OpenAPITools / OpenAPITools/openapi-generator
[Java] Invalid generated code for primitive double array members
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Running the openapi-generator-cli.jar with --type-mappings Integer=int,Boolean=boolean,Float=float,Double=double --language-specific-primitives boolean,int,float,double options, generates incorrect private List<double> vector = null; code.
openapi-generator version
3.3.3-SNAPSHOT (30bfebfa1670840f66f667fc04924391e1994d57) / master
OpenAPI declaration file content or url
Partial content:
"Features": {
"type": "object",
"required": [
"features"
],
"properties": {
"algorithm": {
"description": "The name and version of the algorithm used for feature extraction",
"type": "string",
"example": "Euclidean tripartite loss function"
},
"metric": {
"description": "The recommended type of metric used ",
"type": "string",
"example": "Euclidean tripartite loss function",
"enum": [
"euclidean",
"manhattan",
"cosine"
]
},
"threshold": {
"description": "The value of the metric threshold",
"type": "number",
"format": "double",
"example": 0.8
},
"vector": {
"description": "N-dimensional feature vector of numerical features representing the unique signature of the object",
"type": "array",
"items": {
"type": "number",
"format": "double"
}
}
}
},
Full spec is available here: https://github.com/deepviss/deepviss-server-example/blob/master/src/main/resources/deep-viss-openapi-v3.json
Command line used for generation
java -jar openapi-generator-cli.jar generate -i https://raw.githubusercontent.com/deepviss/deepviss-server-example/master/src/main/resources/deep-viss-openapi-v3.json -l java -o ~/Downloads/generated/ --type-mappings Integer=int,Boolean=boolean,Float=float,Double=double --language-specific-primitives boolean,int,float,double
Steps to reproduce
Generate code with the above specified command.
Open ~/Downloads/generated/src/main/java/org/openapitools/client/model/Features.java and notice the following syntax error:
private List<double> vector = null;
Expected declaration type is:
private double[] vector;
Related issues/PRs
None
Suggest a fix/enhancement
Suggested fix would be to correctly interpret type-mappings and language-specific-primitives options and adjust code generation logic to output double[] instead of List<double>. The same error might reproduce (not tested) for int, float and boolean arrays.
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 by running the listed openapi-generator-cli command and inspect generated src/main/java/org/openapitools/client/model/Features.java. Verify that the vector member is emitted as double[] rather than List, and check whether the same behavior occurs for int, float, and boolean arrays.
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
- Clearly specified
- Newbie friendliness
- 38/100