swagger-api / swagger-api/swagger-codegen
Code generation where '@' prefix used in attribute names
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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