OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][SPRING] Missing `@RequestParam` annotation for complex query parameters which are not an array or an enum
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?
- 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
I have the issue that when I define a GET request with a complex query parameter (see examples below), the parameter in the generated API class is missing the @RequestParam annotation. Due to that, the parameter is not properly resolved by Spring (not entering the Custom Converter, using the "default" instance).
However this seems only to occur, if the complex query parameter is not an enum or an array.
- GET request with a complex query parameter (missing the
@RequestParamannotation). - GET request with a complex query parameter which is an enum (has the
@RequestParamannotation). - GET request with a complex query parameter, but as an array (has the
@RequestParamannotation).
I would expect that all parameters have the @RequestParam annotation.
It also works if it's not a query parameter but a path variables.
- GET request with a complex path parameter (has the RequestParam annotation).
openapi-generator version
7.17.0
OpenAPI declaration file content or url
See full project here: https://github.com/DManstrator/Reproducable-Example-OpenAPI-Missing-RequestParam-Annotation/tree/4713f51f01033cc297f953679c45770db763e380
- OpenAPI definition: https://github.com/DManstrator/Reproducable-Example-OpenAPI-Missing-RequestParam-Annotation/blob/4713f51f01033cc297f953679c45770db763e380/missing_annotation/src/main/resources/api/missing-annotation-example/missing-annotation-example.yml
- POM Plugin definition: https://github.com/DManstrator/Reproducable-Example-OpenAPI-Missing-RequestParam-Annotation/blob/4713f51f01033cc297f953679c45770db763e380/missing_annotation/pom.xml#L38-L74
Generation Details
Install the project with default Maven commands (e.g. mvn clean install) .
Steps to reproduce
- Install the project with Maven.
- Checkout
missing_annotation\src\generated\java\tk\dmanstrator\openapi\missing_annotation\api\MissingAnnotationExampleApi.javaand look for the missing annotation.
Alternatively:
Start the application and open http://localhost:8080/rest/query-custom-version-search?version=3.2.1. You should get an info, that all version attributes are null.
If you open for example
http://localhost:8080/rest/fixed-version-search?version=1.5.7http://localhost:8080/rest/custom-versions-search?versions=1.2.3,4.5.6http://localhost:8080/rest/path-custom-version-search/3.2.1
you will see that the Custom Converters will be entered. This won't happen in the first case.
Related issues/PRs
Perhaps #3248 (this is however over 6 years old and already had a fix).
Suggest a fix
N/A
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 linked OpenAPI definition and generated MissingAnnotationExampleApi.java, then run the reproduction project with Maven using the documented query and path cases. Compare the generated annotations for complex, enum, array, and path parameters; done means the complex query parameter receives @RequestParam and the custom converter is entered as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100