OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] Generated code doesn't compile if two properties are the same except for case
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- Actual: Generated Java code does not compile.
- Expected: Generated Java code compiles
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
For this Qlik REST API, the generated Java code does not compile.
The specification for this API is available live here : https://qlik.dev/specs/rest/audits.json (also, current version attached as file below).
The section that causes the problem is this, where they have properties like "Next" and "next":
"ListLinks": {
"type": "object",
"title": "ListLinks are the HAL links for a list result.",
"properties": {
"Next": {
"$ref": "#/components/schemas/Href"
},
"Prev": {
"$ref": "#/components/schemas/Href"
},
"Self": {
"$ref": "#/components/schemas/Href"
},
"next": {
"$ref": "#/components/schemas/href"
},
"prev": {
"$ref": "#/components/schemas/href"
},
"self": {
"$ref": "#/components/schemas/href"
}
}
}
The generated Java code turns both of these into variables with the same name. Example output:
@JsonPropertyOrder({
ListLinks.JSON_PROPERTY_NEXT,
ListLinks.JSON_PROPERTY_PREV,
ListLinks.JSON_PROPERTY_SELF,
ListLinks.JSON_PROPERTY_NEXT,
ListLinks.JSON_PROPERTY_PREV,
ListLinks.JSON_PROPERTY_SELF
})
@javax.annotation.processing.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-08-14T09:23:07.024303-05:00[America/Chicago]")
public class ListLinks {
public static final String JSON_PROPERTY_NEXT = "Next";
private Href next;
public static final String JSON_PROPERTY_PREV = "Prev";
private Href prev;
public static final String JSON_PROPERTY_SELF = "Self";
private Href self;
//-- ERROR: this set of generated variables have identical names to the ones above
public static final String JSON_PROPERTY_NEXT = "next"; // <-- Error: duplicate symbol
private Href next; // <-- Error: duplicate symbol
public static final String JSON_PROPERTY_PREV = "prev";
private Href prev;
public static final String JSON_PROPERTY_SELF = "self";
private Href self;
public ListLinks() {
}
// ...
openapi-generator version
Tested with 6.0.1 (and 5.4.0 before that).
OpenAPI declaration file content or url
see audits.json
Generation Details
def openApiGeneratorOpts = [
"library" : "native"
];
task openApiGenerateStubs_Audits(type : GenerateTask) {
generatorName = "java"
inputSpec = "$buildDir/open-api-specs/audits.json"
outputDir = "$buildDir/generated"
apiPackage = "example.gen.audits"
modelPackage = "example.gen.audits"
library = openApiGeneratorOpts.library
skipValidateSpec = true
configOptions = [
dateLibrary: "java8"
]
}
Steps to reproduce
Generate the Java code from the supplied spec. It doesn't compile.
Related issues/PRs
Suggest a fix
One seemingly straightforward fix would be to make a the generated constant variable portion align with the case from the spec. For example, instead of the snippet supplied above, generate:
public class ListLinks {
public static final String JSON_PROPERTY_Next = "Next";
private Href Next;
public static final String JSON_PROPERTY_Prev = "Prev";
private Href Prev;
public static final String JSON_PROPERTY_Self = "Self";
private Href Self;
public static final String JSON_PROPERTY_next = "next";
private Href next;
public static final String JSON_PROPERTY_prev = "prev";
private Href prev;
public static final String JSON_PROPERTY_self = "self";
private Href self;
public ListLinks() {
}
// ...
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
Start with the supplied audits.json specification and reproduce generation using the Java generator configuration shown in the issue. Inspect the generated ListLinks model and the Java generator's handling of case-distinct properties; done means the generated code preserves both properties and compiles without duplicate symbols.
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
- 38/100