swagger-api / swagger-api/swagger-codegen

JAVA code-gen not creating model java files

Open
#10,456 2 comments 0 reactions 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

I am trying to expose an internal API for customers to use. For this; I am generating the Swagger api-docs from the API response, and generating the YAML file with it.

Then to the YAML file I am using 'openapi-generator-maven-plugin' to create the model files that will point to internal code for the external users to view the response.

spring-boot: 2.3.2.RELEASE
Java: 1.8
okhttp: 4.8.1
gson: 2.8.6
openapitools: 4.3.1
code-findbugs: 3.0.2

I have in response:

{
  "offset": 0,
  "limit": 200,
  "total": 136,
  "status": {
    "code": 200,
    "message": "Success"
  },
  "count": 136,
  "reponseLastModified": "2020-09-02T20:56:57.951+0000",
  "adjustments": [
    {
      "name1": "value1",
      "name2": value2,
      "name3": value3,
      "name4": "value4"
    },
   {
      "name1": "value1",
      "name2": value2,
      "name3": value3,
      "name4": "value4"
    }
  ]
}

For the above, I generated the Swagger JSON and converted to YAML code(removing some parts):

responses:
          200:
            description: OK
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/AdjustmentResponse'
     AdjustmentResponse:
      type: object
      properties:
        offset:
          type: integer
          description: 'The number of items to offset the start of the list from.'
          format: int32
          example: 5
        limit:
          type: integer
          description: 'The number of items you want the list to be limited to.'
          format: int32
          example: 10
        total:
          type: integer
          description: 'The total number of items that are in the entire collection.'
          format: int32
          example: 50
        count:
          type: integer
          format: int32
        reponseLastModified:
          type: string
        adjustments:
          type: array
          items:
            $ref: '#/components/schemas/Adjustment'
    Adjustment:
      type: object
      properties:
        name1:
          type: string
          description: 'ABCD'
        name2:
          type: integer
          description: 'ABCD'
          example: 39
        name3:
          type: string
          description: 'ABCD'
        name4:
          type: integer
          description: 'ABCD'
          example: 39

When I generate the Models, it will generate the models but will not generate the response API from what I generated the Swagger.

Changing the YAML file to below will generate the response but then the model file 'Adjustment' does not get generated since in AdjustmentResponse DTO it shows up as: List adjustments.

....
adjustments:
          items:
            $ref: '#/components/schemas/Adjustment'
    Adjustment:
      type: array
.....

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 validating the YAML schema around AdjustmentResponse and Adjustment, then inspect the generated Java models and response API output from openapi-generator-maven-plugin 4.3.1. Confirm whether the array property is represented consistently; done means the response API and both AdjustmentResponse and Adjustment model files are generated.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring-boot
Domain
api, backend-api-design, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.