OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] JsonNullable types are not generated for java client models when library is set to 'okhttp-gson' (default) or 'microprofile'
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?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Related to the next issue: https://github.com/OpenAPITools/openapi-generator/issues/17873
openapi-generator does not generate expected JsonNullable properties when library is set with microprofile nor okhttp-gson(default).
Current output: https://github.com/robertop87/opengen/blob/main/build/generated-src/swagger/src/main/java/org/openapitools/client/model/Pet.java
@SerializedName(SERIALIZED_NAME_TAG)
private String tag; // This must be: JsonNullable<String> tag = JsonNullable.undefined();
Expected output: https://github.com/robertop87/opengen/blob/main/src/test/resources/Pet.java
private JsonNullable<String> tag = JsonNullable.<String>undefined();
openapi-generator version
gradle plugin 7.3.0
OpenAPI declaration file content or url
https://github.com/robertop87/opengen/blob/main/swagger.yml
Generation Details
Using gradle plugin configuration (check the next repository) https://github.com/robertop87/opengen
tasks.register('generateClient', GenerateTask) {
generatorName.set("java")
// available libraries list: https://openapi-generator.tech/docs/generators/java/
// Default: okhttp-gson
// The next libraries does not generate the expected JsonNullable: okhttp-gson, microprofile
// The next libraries does generate JsonNullable properly:
// jersey2, jersey3, feign, retrofit2, resttemplate, webclient, resteasy, vertx, google-api-client, rest-assured, native, apache-httpclient
library.set("okhttp-gson") // <-- using default just for testing purposes
inputSpec.set(swaggerFile.toString())
outputDir.set(swaggerOutputDir)
configOptions.set([
dateLibrary: "java8",
useJakartaEe: "true",
openApiNullable: "true" // This is enabled by default
])
}
Steps to reproduce
Clone: https://github.com/robertop87/opengen
Run ./gradlew clean assemble
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/17873
Suggest a fix
Enable the generation of JsonNullable types when library configuration is: microprofile or okhttp-gson.
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 generateClient Gradle task, swagger.yml, and the generated and expected Pet.java files linked in the report. Run ./gradlew clean assemble using the okhttp-gson and microprofile libraries, then compare their output with the libraries that already generate JsonNullable correctly. Done means both affected libraries produce the expected JsonNullable model properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100