OpenAPITools / OpenAPITools/openapi-generator
[BUG] Invalid @HeadMapping annotation generated in Spring controller
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Executing the Spring generator on an Open API file having a HEAD method results in a compilation issue: the generator adds a @HeadMapping annotation which does not exist in spring.
One way to fix that would be to generate RequestMapping whenever the HEAD method is used:
@RequestMapping(value = "/pets",
method = RequestMethod.HEAD)
The issue was introduced by this commit: 8bd2dd4c9dc0d8445f1986d024ce1bd0552b0001
openapi-generator version
This issue affects openapi-generator from 5.0.0, 5.0.1 and 5.1.0.
OpenAPI declaration file content or url
https://gist.github.com/gonzalad/50a657c2ffbafeb85d955672d192e9d2
Generation Details
Just use spring on the previous openapi file.
Steps to reproduce
See https://github.com/gonzalad/openapi-headmapping-issue
- clone the repo
- execute
mvn clean compile
And look at the PetsApi.java class that was generated, we see HeadMapping annotation
which does not exist in Spring:
@HeadMapping(
value = "/pets",
produces = { "application/json" }
)
default ResponseEntity<List<Pet>> listPets(@ApiParam(value = "How many items to return at one time (max 100)") @Valid @RequestParam(value = "limit", required = false) Integer limit) {
Before the 5.0.0, the generated code was
@RequestMapping(value = "/pets",
method = RequestMethod.HEAD)
Related issues/PRs
None known
Suggest a fix
- One way to fix that would be to generate RequestMapping whenever the HEAD method is used:
@RequestMapping(value = "/pets",
method = RequestMethod.HEAD)
- Another way would be to revert this commit: 8bd2dd4c9dc0d8445f1986d024ce1bd0552b0001
And just use @RequestMapping instead of the new PutMapping/GetMapping/etc...
The advantage with this approach imo is that the generator code remains simple.
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 declaration and reproduction repository, then run mvn clean compile to reproduce the generated PetsApi.java failure. Trace the Spring generator entry point that emits the @HeadMapping annotation and make HEAD operations use a compiling mapping; rerun the command and verify the generated controller no longer references HeadMapping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100