Uh oh!
There was an error while loading. Please reload this page.
[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
cachescrubber
commented
Jan 4, 2022
@wing328 Please have a look. |
wing328
commented
Jan 12, 2022
@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? |
welshm
commented
Jan 12, 2022
Will take a look this evening |
cachescrubber
commented
Jan 12, 2022
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| {{#async}} | ||
| import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}}; | ||
| {{/async}} | ||
| import javax.annotation.Generated; |
There was a problem hiding this comment.
Note to self; added import because generated annotation is no longer fully qualified
| {{/-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.
note to self: ApiIgnore added to imports
| // 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.
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}} No newline at end of file |
There was a problem hiding this comment.
Added extra spaces after @Valid - doesn't seem like a big deal though
| */ | ||
| {{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { | ||
| {{>additionalEnumTypeAnnotations}} | ||
| {{>generatedAnnotation}} |
| @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.
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.
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.
I'll look to update that in the coming weeks
There was a problem hiding this comment.
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.
welshm
commented
Jan 13, 2022
Overall this looks good to me - just the one comment about |
wing328
commented
Jan 13, 2022
@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. |
cachescrubber
commented
Jan 13, 2022
# 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
cachescrubber
commented
Jan 17, 2022
@wing328 I merge master and resolved conflicts twice. CI seems a bit spurious, could you please check? |
wing328
commented
Jan 17, 2022
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