swagger-api / swagger-api/swagger-codegen

Code generation where '@' prefix used in attribute names

Open
#8,819 0 comments 4 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 Java code from a swagger definition, if there are any variables prefixed with a '@' character, the code generator strips this character.

However, if you have a swagger where you have two attributes, one called @type and another just called type, this results in two attributes being generated in the resulting code both called type, resulting in a compilation error.

Swagger-codegen version

2.3.1

Swagger declaration file content or url

Try generating a from a swagger definition containing the following:

{
  "swagger": "2.0",
  "definitions": {
    "DuplicateAt": {
      "type": "object",
      "properties": {
        "@type": {
          "type": "string"
        },
        "type": {
          "type": "string"
        }
      }
    }
  }
}

A full Maven project can be uploaded if required.

Command line used for generation

Will provide on request if needed.

Steps to reproduce

Generate the model code.

Related issues/PRs

Very are numerous issues which relate to duplicate variable declarations in Java, but I'm not sure if they relate directly to this issue.

Suggest a fix/enhancement

I would suggest that when striping the any special characters from an attribute name, the code generator checks to see if this would could a duplicate to be created, and, if it is, cause the generation to fail, or, rename the attribute name by adding a prefix and/or suffix.

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

Reproduce generation with the provided Swagger 2.0 definition containing both @type and type properties, using the Java generator; the issue does not name a source file, test, or command. Trace where attribute names lose the @ prefix and establish a handling rule that prevents duplicate Java attributes, then verify the generated model compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, 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.