OpenAPITools / OpenAPITools/openapi-generator
Not able to build generated java implementation for Json spec file
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)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
openapi-generator version
4.3.0
OpenAPI declaration file content or url
below is the code spec of the json file
below file content is just content of model.
PublicKeyDto: {
description: "Public Key",
properties: {
value: {
allowEmptyValue: false,
type: "string",
description: "value"
},
issuer: {
allowEmptyValue: false,
type: "string",
description: "issuer"
},
alg: {
allowEmptyValue: false,
type: "string",
description: "alg"
},
keys: {
items: {
$ref: "#/definitions/MapOfstringAndobject"
},
allowEmptyValue: false,
type: "array",
description: "keys"
}
},
title: "PublicKeyDto",
type: "object"
}
{
title: "MapOfstringAndobject",
additionalProperties: {
type: "object"
},
type: "object"
}
Command line used for generation
openapi-generator generate -i swagger.json -g java -o csp-java-bindings --package-name com.org.csp.openapi_client
Steps to reproduce
after generation try to build the implementation using mvn clean package .
below is the error trace.
Compilation failure
[ERROR] /dbc/sc-dbc2115/ngp/csp-python-bindings/src/main/java/org/openapitools/client/model/PublicKeyDto.java:[130,18] error: incompatible types: ArrayList<Map> cannot be converted to List<Map<String,Object>>
in the implementation of PublicKeyDto.java following assignment is happening which is not correct according to java syntax.
public PublicKeyDto addKeysItem(Map<String, Object> keysItem) {
if (this.keys == null) {
this.keys = new ArrayList<Map>();//in this line error is coming.
}
this.keys.add(keysItem);
return this;
}
this.keys is declared as private List<Map<String, Object>> keys = null;
Related issues/PRs
Suggest a fix
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 with swagger.json using the documented openapi-generator command, then inspect the generated csp-java-bindings/src/main/java/org/openapitools/client/model/PublicKeyDto.java and its addKeysItem method. Compare the declared keys type with the generated initializer and run mvn clean package; done means the generated Java implementation compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- backend-api-design, build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100