-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[Java Spring OAS3] Fix numerous OAS3 related Bugs #11181
[Java Spring OAS3] Fix numerous OAS3 related Bugs #11181
Conversation
…nerator using oas3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing a lot of the issues I introduced! I think the paramDoc mustache is a great simplification overall and makes this much easier to understand
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.parameters.RequestBody; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's value in having both annotations present - but open to removing if no one else feels the same way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was my proposed fix
https://github.com/OpenAPITools/openapi-generator/pull/10766/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would address issue when we would actually need io.swagger.v3.oas.annotations.parameters.RequestBody
. So far, the import is unused, hence the removal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is used - by deleting this import the "@RequestBody" annotation is changing to org.springframework.web.bind.annotation.RequestBody from the import org.springframework.web.bind.annotation.*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this is how it should be - org.springframework.web.bind.annotation.RequestBody
ist the annotation required technically by Spring Mvc or OpenFeign to handle a request. This caused #11165.
io.swagger.v3.oas.annotations.parameters.RequestBody
is never used, as far as I can see.
If we need them both, they should be fully qualified to disambiguate. For example
ResponseEntity<ResourceOrder> createResourceOrder(
@Parameter(name = "resourceOrder", description = "The ResourceOrder to be created", required = true)
@io.swagger.v3.oas.annotations.parameters.RequestBody
@org.springframework.web.bind.annotation.RequestBody
@Valid ResourceOrderCreate resourceOrder);
Question is : Do we actually need to support @io.swagger.v3.oas.annotations.parameters.RequestBody
? What is it good for? Do Tools like SpringFox or SpringDoc support the annotation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is supported by SpringDoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on hvaing both annotations?
modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache
Show resolved
Hide resolved
{{#withXml}} | ||
<!-- XML processing: Jackson --> | ||
<dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Indentation looks off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
{{/hateoas}} | ||
{{#useBeanValidation}} | ||
{{/hateoas}} | ||
{{#useBeanValidation}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe a general question - I assume by having this match the indentation of the pom file this is causing white space to be generated, which is likely why it was fully left aligned.
Are there any community guidelines on this?
@@ -0,0 +1 @@ | |||
{{#allowableValues}}allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/allowableValues}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle enums and containers properly? I don't see a change to "values.mustache" but maybe that's already correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no values.mustache. Which file do you refer to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was making an assumption about the reference to #values - does this work properly with enum values and containers then?
Re #11168. |
That seems reasonable to me |
…e is not compatible with threetenbp > 2.9.10.
…xtensions.x-spring-paginated is not set during import processing.
Short update before Xmas. I duplicated all test configs under |
Your OAS3 implementation basically disables springfox. At the time beeing, springfox moved on and support for openapi3 is
|
modules/openapi-generator/src/main/resources/JavaSpring/pathParams.mustache
Outdated
Show resolved
Hide resolved
Last I was reading about SpringFox, general consensus seemed to be for OAS 3 SpringDoc was greatly preferred. Re-enabling SpringFox support seems fine but I imagine could be done as a separate PR as I could see that likely needing a whole lot more changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like Bitrise failed to download a maven depedency.
CircleCI failed on OpenAPIDocumentationConfig
[ERROR] COMPILATION ERROR :
[ERROR] /home/circleci/OpenAPITools/openapi-generator/samples/server/petstore/spring-mvc-default-value/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java:[14,48] cannot find symbol
symbol: class RelativePathProvider
location: package springfox.documentation.spring.web.paths
[ERROR] /home/circleci/OpenAPITools/openapi-generator/samples/server/petstore/spring-mvc-default-value/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java:[49,53] cannot find symbol
symbol: class RelativePathProvider
location: class org.openapitools.configuration.OpenAPIDocumentationConfig
Looks like that also needs to be updated for full Springfox removal
@Override | ||
public CodegenModel fromModel(String name, Schema model) { | ||
CodegenModel codegenModel = super.fromModel(name, model); | ||
if (oas3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it would be more correct to avoid adding the imports in the first place, but I'm happy to look into that separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is how it is - the swagger2 imports are hard coded in AbstractJavaCodegen
and can only be removed reliably in a post processor. They are not controlled by a mustache template. To change this, all Java based generators would have to be modified.
modules/openapi-generator/src/main/resources/JavaSpring/formParams.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/JavaSpring/paramDoc.mustache
Outdated
Show resolved
Hide resolved
Ok, got it. I have to revert to the latest 2.9.2 release of springfox. Since springfox is on removal, there is no value in upgrading all templates to 3.0.0 (which removes several deprected apis, including RelativePathProvider). A commit fixing this is coming soon. |
@@ -153,13 +156,18 @@ public interface {{classname}} { | |||
produces = { {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }{{/hasProduces}}{{#hasConsumes}}, | |||
consumes = { {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }{{/hasConsumes}}{{/singleContentTypes}} | |||
) | |||
{{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}},{{/-last}}{{#-last}}{{#reactive}}, {{/reactive}}{{/-last}}{{/allParams}}{{#reactive}}{{#oas3}}@Hidden{{/oas3}}{{^oas3}}@springfox.documentation.annotations.ApiIgnore{{/oas3}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, {{#oas3}}@Hidden{{/oas3}}{{^oas3}}@springfox.documentation.annotations.ApiIgnore{{/oas3}} final org.springframework.data.domain.Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}}{{#unhandledException}} throws Exception{{/unhandledException}} { | |||
{{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm looks like @Hidden
may still be relevant from SpringDoc
Additionally, to @Hidden annotation from swagger-annotations, its possible to restrict the generated OpenAPI description using package or path configuration.
As well as the guide on migrating from SpringFox
@ApiIgnore → @Parameter(hidden = true) or @Operation(hidden = true) or @Hidden
Although for method annotation rather than parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe. We should add @Hidden
in a separat PR when it's needed.
May also fix |
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors. Let me know if you need help fixing it. |
Ups, I used $COMPANY email address .... @wing328 I could squash commit the whole branch in a new one and submit another PR. Would that be acceptable? |
@cachescrubber you can simply add your company email address as a secondary email address in your Github account. Let me know if you need help on that. |
@wing328 Ok, I used the secondary email approach. Commits are now linked to my account. |
Tested the new samples locally and all compiles without issues. |
@wing328 when will the release be cut? Is it possible to cut a patch release? |
#9775 introduced in 5.3.1 causes numerous bugs when generating code.
This PR fixes the following Bugs
#11168
#11165
#11164
#11163
#11007
#11203
#11218
This PR implements the following Requests / Improvements
#10409
This PR resolves other, older PRs
#10879
PR checklist
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.
master
(5.3.0),6.0.x