swagger-api / swagger-api/swagger-codegen

[SPRING] Fields starting with _ are generated as duplicates

Open
#10,093 4 comments 2 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

Description

When generating spring code using swagger-codegen-cli, fields starting with an _ appear in the generated response twice.

Swagger-codegen version

swagger-codegen-cli v3.0.18

Swagger declaration file content or url
defaultmodel:
    description: Default response for the api
    properties:
      api_name:
        type: string
        example: "My Wonderful API"
      api_version:
        type: string
        example: v1.0
      api_released:
        type: string
        example: "2020-02-03"
      api_status:
        type: string
        example: "active"
      _links:
        type: array
        items:
          properties:
            rel:
              type: string
              example: organisation-units
            href:
              type: string
              example: /v1.0/organisation-units
            method:
              type: string
              example: GET
Command line used for generation
java -jar swagger-codegen-cli.jar generate -i ..\api.yaml -l spring -o ..\mock
Steps to reproduce
  • Generate the spring code off the api definition
  • cd into the mock directory
  • run mvn clean install
  • run the generated jar file java -jar target\my-jar-file.jar
  • Browse to localhost:8080
  • Note that the _links will be present, but also another variable will be present in the response called links.

e.g.

{
  "_links": [
    {}
  ],
  "api_name": "My Wonderful API",
  "api_released": "2020-02-03",
  "api_status": "active",
  "api_version": "v1.0",
  "links": [
    {}
  ]
}
Related issues/PRs

Can't find any.

Suggest a fix/enhancement

I've reviewed the generated code and can't see this extra parameter in any of the models. It seems to be within the core swagger codegen project.

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 running the documented swagger-codegen-cli generate command with the supplied YAML and the spring generator, then inspect the generated model and response from the jar. Trace how the _links property becomes both _links and links. Done means the generated response contains the declared _links field only, with no duplicate links field.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
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.