-
-
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
Changes from all commits
77ae456
450de73
c24d436
da3b5b1
b8ff798
2964470
709690b
5b02424
040f2fe
847e4d9
3fa4f14
72df450
04d59c8
2eb0916
9e98ebd
ba1e04c
f8eac23
a02b77c
d56bfec
1bdd9cc
caf5c47
7e9d7cb
de95f90
70abe11
b0f452b
98a15e7
f894674
dbb8b1e
c8193ca
c9b38a3
2b0133b
ff7afa4
9f825b0
4f5d316
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
generatorName: spring | ||
outputDir: samples/openapi3/server/petstore/springboot-beanvalidation-no-nullable | ||
library: spring-boot | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
oas3: "true" | ||
java8: "false" | ||
useBeanValidation: true | ||
artifactId: spring-boot-beanvalidation-no-nullable | ||
hideGenerationTimestamp: "true" | ||
openApiNullable: "false" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
generatorName: spring | ||
outputDir: samples/openapi3/server/petstore/springboot-delegate | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
oas3: "true" | ||
artifactId: springboot-delegate | ||
hideGenerationTimestamp: "true" | ||
java8: true | ||
delegatePattern: "true" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
generatorName: spring | ||
outputDir: samples/openapi3/server/petstore/springboot-implicitHeaders | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
oas3: "true" | ||
artifactId: springboot-implicitHeaders | ||
hideGenerationTimestamp: "true" | ||
implicitHeaders: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
generatorName: spring | ||
outputDir: samples/openapi3/server/petstore/springboot | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
artifactId: springboot | ||
snapshotVersion: "true" | ||
oas3: "true" | ||
hideGenerationTimestamp: "true" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
generatorName: spring | ||
outputDir: samples/openapi3/server/petstore/springboot-reactive | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
oas3: "true" | ||
artifactId: springboot-reactive | ||
reactive: "true" | ||
hideGenerationTimestamp: "true" | ||
delegatePattern: "true" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
generatorName: spring | ||
outputDir: samples/openapi3/server/petstore/springboot-useoptional | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
oas3: "true" | ||
useOptional: true | ||
artifactId: spring-boot-useoptional | ||
hideGenerationTimestamp: "true" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
generatorName: spring | ||
outputDir: samples/openapi3/client/petstore/spring-cloud-async | ||
library: spring-cloud | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
oas3: "true" | ||
async: "true" | ||
java8: "true" | ||
artifactId: petstore-spring-cloud | ||
hideGenerationTimestamp: "true" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
generatorName: spring | ||
library: spring-cloud | ||
outputDir: samples/openapi3/client/petstore/spring-cloud-date-time | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/date-time-parameter-types-for-testing.yml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
artifactId: spring-cloud-date-time-oas3 | ||
interfaceOnly: "true" | ||
singleContentTypes: "true" | ||
hideGenerationTimestamp: "true" | ||
oas3: "true" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
generatorName: spring | ||
library: spring-cloud | ||
outputDir: samples/client/petstore/spring-cloud-date-time | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/date-time-parameter-types-for-testing.yml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
artifactId: spring-cloud-date-time | ||
interfaceOnly: "true" | ||
singleContentTypes: "true" | ||
hideGenerationTimestamp: "true" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
generatorName: spring | ||
library: spring-cloud | ||
outputDir: samples/openapi3/client/petstore/spring-cloud-oas3-fakeapi | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
artifactId: spring-cloud-oas3 | ||
interfaceOnly: "true" | ||
singleContentTypes: "true" | ||
hideGenerationTimestamp: "true" | ||
oas3: "true" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
generatorName: spring | ||
library: spring-cloud | ||
outputDir: samples/openapi3/client/petstore/spring-cloud | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
artifactId: spring-cloud-oas3 | ||
interfaceOnly: "true" | ||
singleContentTypes: "true" | ||
hideGenerationTimestamp: "true" | ||
oas3: "true" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
generatorName: spring | ||
outputDir: samples/openapi3/client/petstore/spring-cloud-spring-pageable | ||
library: spring-cloud | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-spring-pageable.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/JavaSpring | ||
additionalProperties: | ||
groupId: org.openapitools.openapi3 | ||
oas3: "true" | ||
artifactId: spring-cloud-spring-pageable | ||
hideGenerationTimestamp: 'true' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{#allowableValues}}allowableValues ={{#oas3}} { {{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}} }{{/oas3}}{{^oas3}} "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/oas3}}{{/allowableValues}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,9 @@ package {{package}}; | |
{{#oas3}} | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.Parameters; | ||
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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I would address issue when we would actually need There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. And this is how it should be -
If we need them both, they should be fully qualified to disambiguate. For example
Question is : Do we actually need to support There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts on hvaing both annotations? |
||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
@@ -120,29 +120,62 @@ public interface {{classname}} { | |
@ApiVirtual | ||
{{/virtualService}} | ||
{{#oas3}} | ||
@Operation(summary = "{{{summary}}}", tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }, responses = { {{#responses}} @ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = @Content(mediaType = "application/json", schema = @Schema(implementation = {{{baseType}}}.class)){{/baseType}}){{^-last}},{{/-last}}{{/responses}} }{{#hasAuthMethods}},security = { | ||
{{#authMethods}}@SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes={ {{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}} }{{/isOAuth}}){{^-last}},{{/-last}}{{/authMethods}} } {{/hasAuthMethods}}) | ||
{{/oas3}}{{^oas3}} | ||
@ApiOperation(value = "{{{summary}}}", nickname = "{{{operationId}}}", notes = "{{{notes}}}"{{#returnBaseType}}, response = {{{.}}}.class{{/returnBaseType}}{{#returnContainer}}, responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { | ||
{{#authMethods}}{{#isOAuth}}@Authorization(value = "{{name}}", scopes = { | ||
{{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, | ||
{{/-last}}{{/scopes}} }){{^-last}},{{/-last}}{{/isOAuth}} | ||
{{^isOAuth}}@Authorization(value = "{{name}}"){{^-last}},{{/-last}} | ||
{{/isOAuth}}{{/authMethods}} }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }) | ||
@ApiResponses(value = { {{#responses}} | ||
|
||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}} }) | ||
@Operation( | ||
summary = "{{{summary}}}", | ||
tags = { {{#vendorExtensions.x-tags}}"{{tag}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} }, | ||
responses = { | ||
{{#responses}} | ||
@ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = @Content(mediaType = "application/json", schema = @Schema(implementation = {{{baseType}}}.class)){{/baseType}}){{^-last}},{{/-last}} | ||
{{/responses}} | ||
}{{#hasAuthMethods}}, | ||
security = { | ||
{{#authMethods}} | ||
@SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes={ {{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}} }{{/isOAuth}}){{^-last}},{{/-last}} | ||
{{/authMethods}} | ||
}{{/hasAuthMethods}} | ||
) | ||
{{/oas3}} | ||
{{^oas3}} | ||
@ApiOperation( | ||
tags = { {{#vendorExtensions.x-tags}}"{{tag}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} }, | ||
value = "{{{summary}}}", | ||
nickname = "{{{operationId}}}", | ||
notes = "{{{notes}}}"{{#returnBaseType}}, | ||
response = {{{.}}}.class{{/returnBaseType}}{{#returnContainer}}, | ||
responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}}, | ||
authorizations = { | ||
{{#authMethods}} | ||
{{#isOAuth}} | ||
@Authorization(value = "{{name}}", scopes = { | ||
{{#scopes}} | ||
@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}},{{/-last}} | ||
{{/scopes}} | ||
}){{^-last}},{{/-last}} | ||
{{/isOAuth}} | ||
{{^isOAuth}} | ||
@Authorization(value = "{{name}}"){{^-last}},{{/-last}} | ||
{{/isOAuth}} | ||
{{/authMethods}} }{{/hasAuthMethods}} | ||
) | ||
@ApiResponses({ | ||
{{#responses}} | ||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}} | ||
{{/responses}} | ||
}) | ||
{{/oas3}} | ||
{{#implicitHeaders}} | ||
{{#oas3}} | ||
@Parameters({ | ||
{{#headerParams}} | ||
{{>paramDoc}}{{^-last}},{{/-last}} | ||
{{/headerParams}} | ||
{{/oas3}} | ||
{{^oas3}} | ||
@ApiImplicitParams({ | ||
{{#headerParams}} | ||
{{>implicitHeader}}{{^-last}},{{/-last}} | ||
{{/headerParams}} | ||
{{/oas3}} | ||
{{#headerParams}} | ||
{{>implicitHeader}} | ||
{{/headerParams}} | ||
}) | ||
{{/implicitHeaders}} | ||
@RequestMapping( | ||
|
@@ -153,13 +186,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 commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm looks like
As well as the guide on migrating from SpringFox
Although for method annotation rather than parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe. We should add |
||
{{#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}} | ||
){{^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}}{{#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}}){{#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}}@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}} { | ||
{{/delegate-method}} | ||
{{^isDelegate}} | ||
{{>methodBody}} | ||
|
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.