OpenAPITools / OpenAPITools/openapi-generator
[BUG][JavaSpring] description values for @Operation annotation are not generated from OpenAPI definition
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
When I run code generation for a Java Spring Api, the description is missing in the @Operation annotation.
openapi-generator version
The bug occurs with the latest openapi-generator version.
OpenAPI declaration file content or url
The bug can be reproduced for example with this file: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/java/petstore-group-parameter.yaml
Generation Details
Command to generate the code: java -jar openapi-generator-cli-6.3.0-20221110.220613-11.jar generate -i modules/openapi-generator/src/test/resources/3_0/java/petstore-group-parameter.yaml -g spring -o test
Steps to reproduce
Run the code generation command from above.
Output:
...
@Operation(
operationId = "findPetsByStatus",
summary = "Finds Pets by status",
tags = { "pet" },
responses = {
@ApiResponse(responseCode = "200", description = "successful operation", content = {
@Content(mediaType = "application/xml", schema = @Schema(implementation = Pet.class)),
@Content(mediaType = "application/json", schema = @Schema(implementation = Pet.class))
}),
@ApiResponse(responseCode = "400", description = "Invalid status value")
},
security = {
@SecurityRequirement(name = "petstore_auth", scopes={ "read:pets" })
}
)
...
Expected output:
...
@Operation(
operationId = "findPetsByStatus",
summary = "Finds Pets by status",
description = "Multiple status values can be provided with comma separated strings",
tags = { "pet" },
responses = {
@ApiResponse(responseCode = "200", description = "successful operation", content = {
@Content(mediaType = "application/xml", schema = @Schema(implementation = Pet.class)),
@Content(mediaType = "application/json", schema = @Schema(implementation = Pet.class))
}),
@ApiResponse(responseCode = "400", description = "Invalid status value")
},
security = {
@SecurityRequirement(name = "petstore_auth", scopes={ "read:pets" })
}
)
...
Related issues/PRs
The bug has already been reported with the closed issue https://github.com/OpenAPITools/openapi-generator/issues/11779, but the fix was not correct as mentioned in the discussion.
Suggest a fix
PR with a fix: https://github.com/OpenAPITools/openapi-generator/pull/13995
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 generation command against modules/openapi-generator/src/test/resources/3_0/java/petstore-group-parameter.yaml and compare the Spring output with the expected @Operation annotation. Review the related closed issue 11779 and pull request 13995; done means the generated annotation includes the OpenAPI operation description.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100