-
-
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] Minor fixes and general improvements #11229
[Java Spring OAS3] Minor fixes and general improvements #11229
Conversation
* api.mustache: Add operationId to atOperation annotation * Overhaul atSchema annotation in model * Add spring-stubs-oas3.yaml test config * Optimize mustache templates * Use Relative Imports for DateTimeFormat, Pageable and ApiIgnore
@wing328 Please have a look. |
@cachescrubber thanks for the PR. One minor suggestion is to add some comments (1 or 2 lines) to the @welshm can you please take a look at this PR as well? |
Will take a look this evening |
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java
Outdated
Show resolved
Hide resolved
{{/jdk8-no-delegate}} | ||
{{#async}} | ||
import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}}; | ||
{{/async}} | ||
import javax.annotation.Generated; |
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 to self; added import because generated annotation is no longer fully qualified
@@ -189,15 +201,15 @@ public interface {{classname}} { | |||
{{#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}}{{/allParams}}{{#reactive}}{{#hasParams}}, | |||
{{/hasParams}}{{#oas3}}@Parameter(hidden = true){{/oas3}}{{#useSpringfox}}@springfox.documentation.annotations.ApiIgnore{{/useSpringfox}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, | |||
{{/hasParams}}{{#useSpringfox}}@springfox.documentation.annotations.ApiIgnore {{/useSpringfox}}final org.springframework.data.domain.Pageable pageable{{/vendorExtensions.x-spring-paginated}} | |||
{{/hasParams}}{{#oas3}}@Parameter(hidden = true){{/oas3}}{{#useSpringfox}}@ApiIgnore{{/useSpringfox}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, |
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 to self: ApiIgnore added to imports
){{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}}{{#unhandledException}} throws Exception{{/unhandledException}} { | ||
{{#delegate-method}} | ||
return {{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, pageable{{/vendorExtensions.x-spring-paginated}}); | ||
} | ||
|
||
// Override this method | ||
{{#jdk8-default-interface}}default {{/jdk8-default-interface}} {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#reactive}}Flux<Part>{{/reactive}}{{^reactive}}MultipartFile{{/reactive}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}{{#useSpringfox}}@springfox.documentation.annotations.ApiIgnore{{/useSpringfox}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, {{#useSpringfox}}@springfox.documentation.annotations.ApiIgnore{{/useSpringfox}} final org.springframework.data.domain.Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}} { | ||
{{#jdk8-default-interface}}default {{/jdk8-default-interface}} {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#reactive}}Flux<Part>{{/reactive}}{{^reactive}}MultipartFile{{/reactive}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#reactive}}{{#hasParams}}, {{/hasParams}}{{#useSpringfox}}@ApiIgnore{{/useSpringfox}} final ServerWebExchange exchange{{/reactive}}{{#vendorExtensions.x-spring-paginated}}, {{#useSpringfox}}@ApiIgnore{{/useSpringfox}} final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{#unhandledException}} throws Exception{{/unhandledException}} { |
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 to self: Pageable added to imports
@Valid{{/isEnum}}{{/isPrimitiveType}}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}} | ||
@Valid{{/isPrimitiveType}}{{/isContainer}} | ||
{{>beanValidationCore}} | ||
{{#required}}@NotNull {{/required}}{{#isContainer}}{{^isPrimitiveType}}{{^isEnum}}@Valid {{/isEnum}}{{/isPrimitiveType}}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}@Valid {{/isPrimitiveType}}{{/isContainer}}{{>beanValidationCore}} |
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.
Added extra spaces after @Valid
- doesn't seem like a big deal though
@@ -6,7 +6,9 @@ import com.fasterxml.jackson.annotation.JsonValue; | |||
/** | |||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{{description}}} | |||
*/ | |||
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { | |||
{{>additionalEnumTypeAnnotations}} | |||
{{>generatedAnnotation}} |
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.
New annotation added here
{{/isDate}} | ||
{{#isDateTime}} | ||
@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME) | ||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | ||
{{/isDateTime}} | ||
{{#openApiNullable}} | ||
private {{>nullableDataType}} {{name}}{{#isNullable}} = JsonNullable.undefined(){{/isNullable}}{{^isNullable}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{/isNullable}}; |
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.
Out of curiosity, are there tests for a nullable field?
I had to fix this locally and haven't upstreamed the changes yet but we're also using a generator one version behind
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.
Yes, but those tests in the 3.0 spec: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml#L1813
Spring samples (most if not all) are using 2.0 spec at the moment. We'll need to update these config to use the 3.0 spec instead.
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'll look to update that in the coming weeks
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.
At least I introduced test configs for oas3 output format... We could update some of them to use 3.0 as input as well. But this could lead to even more test cases ...
oas2 -> oas2 -> ok
oas2 -> oas3 -> ok
oas3 -> oas2 -> do we even need this?
oas3 -> oas3 -> partially ok. This should be the fokus.
Overall this looks good to me - just the one comment about |
@cachescrubber pls let me know if you need help fixing the merge conflicts as I've reordered the tests (spring, apache camel) a bit in pom.xml. |
# Conflicts: # pom.xml
This reverts commit 1915f8b.
# Conflicts: # samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/openapi3/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/openapi3/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/openapi3/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/spring-mvc-no-nullable/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/spring-mvc-spring-pageable/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/spring-mvc/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-spring-pageable-without-j8/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-spring-pageable/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/FileSchemaTestClass.java # samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/FileSchemaTestClass.java # samples/server/petstore/springboot/src/main/java/org/openapitools/model/FileSchemaTestClass.java
# Conflicts: # samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi/src/main/java/org/openapitools/model/File.java # samples/openapi3/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/File.java # samples/openapi3/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/File.java # samples/openapi3/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/File.java # samples/openapi3/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/File.java # samples/openapi3/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/File.java # samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/model/File.java # samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/model/File.java # samples/server/petstore/spring-mvc-no-nullable/src/main/java/org/openapitools/model/File.java # samples/server/petstore/spring-mvc-spring-pageable/src/main/java/org/openapitools/model/File.java # samples/server/petstore/spring-mvc/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-beanvalidation-no-nullable/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-spring-pageable-delegatePattern/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-spring-pageable-without-j8/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-spring-pageable/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/File.java # samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/File.java # samples/server/petstore/springboot/src/main/java/org/openapitools/model/File.java
@wing328 I merge master and resolved conflicts twice. CI seems a bit spurious, could you please check? |
For the bitrise CI failure, please ignore it. |
A follow up to #11181. The OAS3
@Operation
(Api) and@Schema
(Model) annotations have been refined. Also, I did a major cleanup of the mustache templates and the generated source files.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