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

[Java Spring OAS3] Minor fixes and general improvements #11229

Merged
merged 17 commits into from
Jan 17, 2022

Conversation

cachescrubber
Copy link
Contributor

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

  • [ x] Read the contribution guidelines.
  • [ x] 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.
  • [ x] Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    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 (5.3.0), 6.0.x
  • [ x] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

* 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
Copy link
Contributor Author

@wing328 Please have a look.

@wing328
Copy link
Member

wing328 commented Jan 12, 2022

@cachescrubber thanks for the PR. One minor suggestion is to add some comments (1 or 2 lines) to the fromOperation function explain what it does.

@welshm can you please take a look at this PR as well?

@welshm
Copy link
Contributor

welshm commented Jan 12, 2022

@cachescrubber thanks for the PR. One minor suggestion is to add some comments (1 or 2 lines) to the fromOperation function explain what it does.

@welshm can you please take a look at this PR as well?

Will take a look this evening

@cachescrubber
Copy link
Contributor Author

@wing328 thx for the review. I added a short non JavaDoc comment as you suggested.

@welshm sorry - forgot to notify you of the PR.

{{/jdk8-no-delegate}}
{{#async}}
import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}};
{{/async}}
import javax.annotation.Generated;
Copy link
Contributor

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}},
Copy link
Contributor

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}} {
Copy link
Contributor

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}}
Copy link
Contributor

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}}
Copy link
Contributor

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}};
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

@welshm
Copy link
Contributor

welshm commented Jan 13, 2022

Overall this looks good to me - just the one comment about useSpringFox but otherwise looks like good cleanup

@wing328
Copy link
Member

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
Copy link
Contributor Author

@wing328 I reverted 1915f8b - please check the merge result.

# 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
Copy link
Contributor Author

@wing328 I merge master and resolved conflicts twice. CI seems a bit spurious, could you please check?

@wing328
Copy link
Member

wing328 commented Jan 17, 2022

For the bitrise CI failure, please ignore it.

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.

3 participants