OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][Gradle Plugin] Java client generator not initializing fields
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
Using the openapi-generator gradle plugin I setup a task to generate code for the Petstore example YAML. Checking the generated Java classes I can see this in Pet.java:
@JsonProperty("id")
private Long id = ;
@JsonProperty("name")
private String name = ;
@JsonProperty("tag")
private String tag = ;
My Gradle task:
task generatePetStore(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
String basePackage = "com.example.petstore"
verbose = true
library = "resttemplate"
generatorName = "java"
inputSpec = "${project.rootDir}/swagger/petstore.yaml".toString()
outputDir = "${project.buildDir}/generated/api/petstore"
invokerPackage = basePackage
apiPackage = basePackage + ".controller"
modelPackage = basePackage + ".model"
configOptions = [
dateLibrary: "java8-localdatetime"
]
}
openapi-generator version
openapi-generator-gradle-plugin 4.2.2
OpenAPI declaration file content or url
URL: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml
Command line used for generation
Steps to reproduce
- Download Petstore Example YAML
- Run code generation using the Gradle Plugin
- Navigate to the Pet.java generated file
Related issues/PRs
Suggest a fix
The fields probably need to be initialized to null at least as the generated code is invalid Java syntax. Something like
@JsonProperty("id")
private Long id = null;
@JsonProperty("name")
private String name = null;
@JsonProperty("tag")
private String tag = null;
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 the issue with the Petstore YAML and the Gradle GenerateTask configuration, then inspect the generated Pet.java model. Trace the Java generator template or entry point responsible for model field declarations. Done means the generated Java source is valid and fields are initialized consistently with the reported expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100