swagger-api / swagger-api/swagger-codegen

[Go] [Java] [Client] Adding required to fields

Open
#9,111 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Swagger-codegen both for go and java can't add required to fields when reusing object.
related to #722

Swagger-codegen version

2.3.1
3.0.4

openapi 2/3

Swagger declaration file content or url
swagger: '2.0'
info:
  description: Example
  title: Example
  version: '1.0.0'
consumes:
  - application/json
produces:
  - application/json
paths: {}
definitions:
  InputWithRequired:
    required:
      - id
      - number
    allOf:
      - $ref: '#/definitions/Input'
  Input:
    type: object
    properties:
      id:
        type: number
        example: 53
      number:
        type: string
        example: "0000000024"

openapi: 3.0.0
info:
  description: Example
  title: Example
  version: '1.0.0'
paths: {}
components:
  schemas:
    InputWithRequired:
      required:
        - id
        - number
      allOf:
        - $ref: '#/components/schemas/Input'
    Input:
      type: object
      properties:
        id:
          type: number
          example: 53
        number:
          type: string
          example: "0000000024"

Documentaion generated with these specs is correct, it specifies that for InputWithRequired id and number fields are required, but for Input they are optional. However generated models both set fields as optional.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided Swagger 2.0 and OpenAPI 3.0 declarations using the Go and Java generators. Compare the generated models for InputWithRequired and Input; done means id and number are required only in InputWithRequired, while remaining optional in Input.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.