Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Invalid @HeadMapping annotation generated in Spring controller #9351

Open
gonzalad opened this issue Apr 27, 2021 · 4 comments
Open

[BUG] Invalid @HeadMapping annotation generated in Spring controller #9351

gonzalad opened this issue Apr 27, 2021 · 4 comments

Comments

@gonzalad
Copy link
Contributor

gonzalad commented Apr 27, 2021

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: 8bd2dd4

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
  1. One way to fix that would be to generate RequestMapping whenever the HEAD method is used:
        @RequestMapping(value = "/pets",
        method = RequestMethod.HEAD)
  1. Another way would be to revert this commit: 8bd2dd4
    And just use @RequestMapping instead of the new PutMapping/GetMapping/etc...
    The advantage with this approach imo is that the generator code remains simple.
@kroutal
Copy link

kroutal commented Jun 10, 2021

Same issue is present for OPTIONS and TRACE
It will generate a OptionsMapping and TraceMapping annotation. Which do not exist.

@jorgerod
Copy link
Contributor

jorgerod commented Jun 29, 2021

Hi
I have the same problem.

Regarding the possible solutions proposed by @gonzalad, I think the best option would be to revert the commit and improve this behaviour in future improvements.

@dickhaut
Copy link

dickhaut commented Aug 6, 2021

I have the same problem here.

Using HEAD and getting

error: cannot find symbol
    @HeadMapping(
     ^
  symbol:   class HeadMapping
  location: interface Api

@kroutal
Copy link

kroutal commented Oct 8, 2021

Hi, it seems this issue was fixed in 5.2.1 #9900

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants