OpenAPITools / OpenAPITools/openapi-generator
[BUG] [java] [spring] Type-less parameters in generated model method
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
Generated models omit type in a method parameter:
> Task :compileJava FAILED
/Users/flozano/Projects/java/reproduce-openapi-issue/build/generated/src/main/java/io/github/flozano/openapireproduce/model/UserNew.java:102: error: <identifier> expected
public UserNew putRoleItem(String key, roleItem) {
^
/Users/flozano/Projects/java/reproduce-openapi-issue/build/generated/src/main/java/io/github/flozano/openapireproduce/model/UserNew.java:150: error: <identifier> expected
public UserNew putAlertMethodItem(String key, alertMethodItem) {
^
2 errors
full reproducer project in https://github.com/flozano/reproduce-openapi-spring-issue/
openapi-generator version
7.10.0
OpenAPI declaration file content or url
Generation Details
most simple gradle configuration possible:
plugins {
id "org.openapi.generator" version "${openApiGeneratorVersion}"
id 'java'
}
openApiGenerate {
generatorName = "spring"
inputSpec = "${project.projectDir}/src/main/resources/swagger-testing.yaml".toString()
outputDir = "${project.buildDir}/generated".toString()
skipOverwrite = false
}
Steps to reproduce
just run ./gradlew build in the reproducer project https://github.com/flozano/reproduce-openapi-spring-issue/
Incorrect output details
A method like this is generated in the model:
private Object role;
// ...
public UserNew putRoleItem(String key, roleItem) {
if (this.role == null) {
this.role = new HashMap<>();
}
this.role.put(key, roleItem);
return this;
}
role is in a definition like this:
Role:
type: string
enum:
- admin
- technician
- observer
and used like this in the definition that generates the offending class:
role:
allOf:
- description: if role is omitted, `"technician"` is used as default.
- $ref: '#/definitions/Role'
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
Run ./gradlew build in the linked reproducer and inspect src/main/resources/swagger-testing.yaml alongside the generated UserNew.java output. Trace the Spring generator's model-method parameter handling for the allOf Role definition; done means the generated methods include valid Java parameter types and the project compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100