Skip to content

[Java] [Spring] Spring new mapping annotations #7189

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

Merged
merged 3 commits into from
Aug 24, 2020

Conversation

borsch
Copy link
Member

@borsch borsch commented Aug 12, 2020

Replace old @RequestMapping with new @GetMapping, @PostMapping etc. Related issue: #7184

  • [+] Read the contribution guidelines.
  • [+] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • [+] If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • [+] Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • [+] File the PR against the correct branch: master
  • [+] Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@borsch borsch changed the title Spring new mapping annotations [Java] [Spring] Spring new mapping annotations Aug 12, 2020
@borsch borsch force-pushed the spring-new-mapping-annotations branch from dbdc78a to d6bbd51 Compare August 16, 2020 17:34
@borsch
Copy link
Member Author

borsch commented Aug 16, 2020

@wing328 could you please review?

@borsch borsch marked this pull request as draft August 18, 2020 06:32
@borsch borsch marked this pull request as ready for review August 18, 2020 06:32
produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}], {{/hasProduces}}{{#hasConsumes}}
consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}],{{/hasConsumes}}{{/singleContentTypes}}
method = [RequestMethod.{{httpMethod}}])
@{{#lambda.titlecase}}{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}{{/lambda.titlecase}}Mapping(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using {{#lambda.titlecase}}{{#lambda.lowercase}} ... {{/lambda.lowercase}}{{/lambda.titlecase}} is fine. Later I may switch it to something else (e.g. x-kotlin-http-method) to make it easier for new users to understand.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

I just encountered a case where this change is actually blocking for me to upgrade from 4.3.1 to 5.x.x.

I do have an HTTP OPTIONS in my OpenAPI. This change generates an @OptionsMapping, but it does not exist in Spring. The previous version with @RequestMapping and setting the RequestMethod was working for all HTTP methods. I admit, it is more verbose, but at least it covers the various cases.

This change is only viable once there are annotations *Mapping for every RequestMethod values in Spring.

You can find more information in this Spring issue where it is a bit discussed: spring-projects/spring-framework#18565

Can this change be reverted?

@wing328 wing328 merged commit 8bd2dd4 into OpenAPITools:master Aug 24, 2020
@wing328 wing328 added this to the 5.0.0 milestone Aug 24, 2020
@borsch borsch deleted the spring-new-mapping-annotations branch September 4, 2020 08:00
@billbarni
Copy link

billbarni commented May 26, 2021

I'm using the Maven OpenAPi generator, and the generated spring code has "@OptionsMapping" annotations in several methods, but those annotations cannot be found anywhere.
How can I fix this issue?

@borsch
Copy link
Member Author

borsch commented Jun 14, 2021

@billbarni @mwatel42 could you please create an issue for this? I'll fix this issue shortly. As for now there is no workaround other than downgrade of generator ..

Or remove any options method from specification

@mwatel42
Copy link

Issue submitted #9773 (comment)

@borsch I cannot simply change our production API to remove the support of HTTP OPTIONS, while it is a completely valid use case.

@billbarni
Copy link

If I downgrade I get a lot of:
"oas_any_type_not_mapped.class" errors... I am generating this from an existing file that I import frequently in Postman.

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

Successfully merging this pull request may close these issues.

4 participants