diff --git a/.github/workflows/samples-kotlin-server-jdk17.yaml b/.github/workflows/samples-kotlin-server-jdk17.yaml index 22d45ef94c88..999e2f4d817b 100644 --- a/.github/workflows/samples-kotlin-server-jdk17.yaml +++ b/.github/workflows/samples-kotlin-server-jdk17.yaml @@ -36,6 +36,7 @@ jobs: # server - samples/server/petstore/kotlin-server-required-and-nullable-properties - samples/server/petstore/kotlin-springboot-3 + - samples/server/petstore/kotlin-springboot-3-no-response-entity - samples/server/petstore/kotlin-springboot-additionalproperties - samples/server/petstore/kotlin-springboot-delegate-nodefaults - samples/server/petstore/kotlin-springboot-request-cookie diff --git a/.github/workflows/samples-kotlin-server.yaml b/.github/workflows/samples-kotlin-server.yaml index 5b6f3f0a0884..0ab8e5389059 100644 --- a/.github/workflows/samples-kotlin-server.yaml +++ b/.github/workflows/samples-kotlin-server.yaml @@ -29,6 +29,8 @@ jobs: sample: # server - samples/server/petstore/kotlin-springboot + - samples/server/petstore/kotlin-springboot-no-response-entity + - samples/server/petstore/kotlin-springboot-no-response-entity-delegate - samples/server/petstore/kotlin-springboot-multipart-request-model - samples/server/petstore/kotlin-springboot-bigdecimal-default - samples/server/petstore/kotlin-springboot-delegate diff --git a/bin/configs/kotlin-spring-boot-3-no-response-entity.yaml b/bin/configs/kotlin-spring-boot-3-no-response-entity.yaml new file mode 100644 index 000000000000..661548dcd783 --- /dev/null +++ b/bin/configs/kotlin-spring-boot-3-no-response-entity.yaml @@ -0,0 +1,14 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-springboot-3-no-response-entity +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + documentationProvider: none + annotationLibrary: none + useSwaggerUI: "false" + serviceImplementation: "true" + serializableModel: "true" + beanValidations: "true" + useSpringBoot3: "true" + requestMappingMode: api_interface diff --git a/bin/configs/kotlin-spring-boot-no-response-entity-delegate.yaml b/bin/configs/kotlin-spring-boot-no-response-entity-delegate.yaml new file mode 100644 index 000000000000..00c2a32823f8 --- /dev/null +++ b/bin/configs/kotlin-spring-boot-no-response-entity-delegate.yaml @@ -0,0 +1,15 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-springboot-no-response-entity-delegate +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + documentationProvider: none + annotationLibrary: none + useSwaggerUI: "false" + serviceImplementation: "true" + serializableModel: "true" + beanValidations: "true" + useResponseEntity: "false" + delegatePattern: true + requestMappingMode: controller diff --git a/bin/configs/kotlin-spring-boot-no-response-entity.yaml b/bin/configs/kotlin-spring-boot-no-response-entity.yaml new file mode 100644 index 000000000000..d4d1daa263d5 --- /dev/null +++ b/bin/configs/kotlin-spring-boot-no-response-entity.yaml @@ -0,0 +1,14 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-springboot-no-response-entity +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + documentationProvider: none + annotationLibrary: none + useSwaggerUI: "false" + serviceImplementation: "true" + serializableModel: "true" + beanValidations: "true" + useResponseEntity: "false" + requestMappingMode: controller diff --git a/bin/configs/kotlin-spring-declarative-interface-reactive-coroutines.yaml b/bin/configs/kotlin-spring-declarative-interface-reactive-coroutines.yaml index e2ad5943459f..f5375f8f0fb7 100644 --- a/bin/configs/kotlin-spring-declarative-interface-reactive-coroutines.yaml +++ b/bin/configs/kotlin-spring-declarative-interface-reactive-coroutines.yaml @@ -11,6 +11,6 @@ additionalProperties: beanValidations: "true" interfaceOnly: true reactive: true - declarativeInterfaceWrapResponses: false + useResponseEntity: false useFlowForArrayReturnType: false declarativeInterfaceReactiveMode: "coroutines" diff --git a/bin/configs/kotlin-spring-declarative-interface-reactive-reactor-wrapped.yaml b/bin/configs/kotlin-spring-declarative-interface-reactive-reactor-wrapped.yaml index 99ea39a3c8a6..0826f5059e33 100644 --- a/bin/configs/kotlin-spring-declarative-interface-reactive-reactor-wrapped.yaml +++ b/bin/configs/kotlin-spring-declarative-interface-reactive-reactor-wrapped.yaml @@ -11,6 +11,6 @@ additionalProperties: beanValidations: "true" interfaceOnly: true reactive: true - declarativeInterfaceWrapResponses: true + useResponseEntity: true useFlowForArrayReturnType: false declarativeInterfaceReactiveMode: "reactor" diff --git a/bin/configs/kotlin-spring-declarative-interface-wrapped.yaml b/bin/configs/kotlin-spring-declarative-interface-wrapped.yaml index 978584977ae2..ce0d79f6e97b 100644 --- a/bin/configs/kotlin-spring-declarative-interface-wrapped.yaml +++ b/bin/configs/kotlin-spring-declarative-interface-wrapped.yaml @@ -11,5 +11,5 @@ additionalProperties: beanValidations: "true" interfaceOnly: true reactive: false - declarativeInterfaceWrapResponses: true + useResponseEntity: true useFlowForArrayReturnType: false diff --git a/bin/configs/kotlin-spring-declarative-interface.yaml b/bin/configs/kotlin-spring-declarative-interface.yaml index 436e59186636..da5c9c0a8854 100644 --- a/bin/configs/kotlin-spring-declarative-interface.yaml +++ b/bin/configs/kotlin-spring-declarative-interface.yaml @@ -11,5 +11,5 @@ additionalProperties: beanValidations: "true" interfaceOnly: true reactive: false - declarativeInterfaceWrapResponses: true + useResponseEntity: true useFlowForArrayReturnType: false diff --git a/docs/generators/kotlin-spring.md b/docs/generators/kotlin-spring.md index f9334caaccca..9dfba5d3e6c8 100644 --- a/docs/generators/kotlin-spring.md +++ b/docs/generators/kotlin-spring.md @@ -28,7 +28,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl |beanQualifiers|Whether to add fully-qualifier class names as bean qualifiers in @Component and @RestController annotations. May be used to prevent bean names clash if multiple generated libraries (contexts) added to single project.| |false| |configPackage|configuration package for generated code| |org.openapitools.configuration| |declarativeInterfaceReactiveMode|What type of reactive style to use in Spring Http declarative interface|
**coroutines**
Use kotlin-idiomatic 'suspend' functions
**reactor**
Use reactor return wrappers 'Mono' and 'Flux'
|coroutines| -|declarativeInterfaceWrapResponses|Whether (when false) to return actual type (e.g. List<Fruit>) and handle non 2xx responses via exceptions or (when true) return entire ResponseEntity (e.g. ResponseEntity<List<Fruit>>)| |false| |delegatePattern|Whether to generate the server files using the delegate pattern| |false| |documentationProvider|Select the OpenAPI documentation provider.|
**none**
Do not publish an OpenAPI specification.
**source**
Publish the original input OpenAPI specification.
**springfox**
Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x. Deprecated (for removal); use springdoc instead.
**springdoc**
Generate an OpenAPI 3 specification using SpringDoc.
|springdoc| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |original| @@ -56,6 +55,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useBeanValidation|Use BeanValidation API annotations to validate data types| |true| |useFeignClientUrl|Whether to generate Feign client with url parameter.| |true| |useFlowForArrayReturnType|Whether to use Flow for array/collection return types when reactive is enabled. If false, will use List instead.| |true| +|useResponseEntity|Whether (when false) to return actual type (e.g. List<Fruit>) and handle non-happy path responses via exceptions flow or (when true) return entire ResponseEntity (e.g. ResponseEntity<List<Fruit>>). If disabled, method are annotated using a @ResponseStatus annotation, which has the status of the first response declared in the Api definition| |true| |useSpringBoot3|Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |false| |useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true| |useTags|Whether to use tags for creating interface and controller class names| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java index 448561f250ac..62404681c5cb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java @@ -33,6 +33,7 @@ import org.openapitools.codegen.model.ModelsMap; import org.openapitools.codegen.model.OperationMap; import org.openapitools.codegen.model.OperationsMap; +import org.openapitools.codegen.templating.mustache.SpringHttpStatusLambda; import org.openapitools.codegen.utils.ModelUtils; import org.openapitools.codegen.utils.URLPathUtils; import org.slf4j.Logger; @@ -85,7 +86,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen public static final String DELEGATE_PATTERN = "delegatePattern"; public static final String USE_TAGS = "useTags"; public static final String BEAN_QUALIFIERS = "beanQualifiers"; - public static final String DECLARATIVE_INTERFACE_WRAP_RESPONSES = "declarativeInterfaceWrapResponses"; + public static final String USE_RESPONSE_ENTITY = "useResponseEntity"; public static final String DECLARATIVE_INTERFACE_REACTIVE_MODE = "declarativeInterfaceReactiveMode"; public static final String USE_SPRING_BOOT3 = "useSpringBoot3"; @@ -109,6 +110,7 @@ public enum DeclarativeInterfaceReactiveMode { } } + public enum RequestMappingMode { api_interface("Generate the @RequestMapping annotation on the generated Api Interface."), controller("Generate the @RequestMapping annotation on the generated Api Controller Implementation."), @@ -155,7 +157,7 @@ public String getDescription() { @Setter protected boolean useTags = false; @Setter private boolean beanQualifiers = false; @Setter private DeclarativeInterfaceReactiveMode declarativeInterfaceReactiveMode = DeclarativeInterfaceReactiveMode.coroutines; - @Setter private boolean declarativeInterfaceWrapResponses = false; + @Setter private boolean useResponseEntity = true; @Getter @Setter protected boolean useSpringBoot3 = false; @@ -242,9 +244,9 @@ public KotlinSpringServerCodegen() { addSwitch(USE_SPRING_BOOT3, "Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.", useSpringBoot3); addSwitch(USE_FLOW_FOR_ARRAY_RETURN_TYPE, "Whether to use Flow for array/collection return types when reactive is enabled. If false, will use List instead.", useFlowForArrayReturnType); addSwitch(INCLUDE_HTTP_REQUEST_CONTEXT, "Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods.", includeHttpRequestContext); - addSwitch(DECLARATIVE_INTERFACE_WRAP_RESPONSES, - "Whether (when false) to return actual type (e.g. List) and handle non 2xx responses via exceptions or (when true) return entire ResponseEntity (e.g. ResponseEntity>)", - declarativeInterfaceWrapResponses); + addSwitch(USE_RESPONSE_ENTITY, + "Whether (when false) to return actual type (e.g. List) and handle non-happy path responses via exceptions flow or (when true) return entire ResponseEntity (e.g. ResponseEntity>). If disabled, method are annotated using a @ResponseStatus annotation, which has the status of the first response declared in the Api definition", + useResponseEntity); supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application."); supportedLibraries.put(SPRING_CLOUD_LIBRARY, "Spring-Cloud-Feign client with Spring-Boot auto-configured settings."); @@ -468,6 +470,12 @@ public void processOpts() { additionalProperties.put(CodegenConstants.LIBRARY, library); } + if(additionalProperties.containsKey(USE_RESPONSE_ENTITY)) { + this.setUseResponseEntity(Boolean.parseBoolean(additionalProperties.get(USE_RESPONSE_ENTITY).toString())); + } + writePropertyBack(USE_RESPONSE_ENTITY, useResponseEntity); + additionalProperties.put("springHttpStatus", new SpringHttpStatusLambda()); + // Set basePackage from invokerPackage if (!additionalProperties.containsKey(BASE_PACKAGE) && additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) { diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache index 5a371f6309c6..a6ba00354e39 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache @@ -20,7 +20,9 @@ import io.swagger.annotations.AuthorizationScope {{/swagger1AnnotationLibrary}} import org.springframework.http.HttpStatus import org.springframework.http.MediaType +{{#useResponseEntity}} import org.springframework.http.ResponseEntity +{{/useResponseEntity}} import org.springframework.web.bind.annotation.* {{#useBeanValidation}} @@ -28,6 +30,9 @@ import org.springframework.validation.annotation.Validated {{/useBeanValidation}} import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +{{#useRequestMappingOnController}} +import {{#apiPackage}}{{.}}.{{/apiPackage}}{{classname}}Controller.Companion.BASE_PATH +{{/useRequestMappingOnController}} {{#useBeanValidation}} import {{javaxPackage}}.validation.Valid @@ -56,15 +61,18 @@ import kotlin.collections.Map {{/swagger1AnnotationLibrary}} {{#useRequestMappingOnController}} {{=<% %>=}} -@RequestMapping("\${api.base-path:<%contextPath%>}") +@RequestMapping("\${api.<%title%>.base-path:api.base-path:$BASE_PATH}") <%={{ }}=%> {{/useRequestMappingOnController}} {{#operations}} class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) val service: {{classname}}Service{{/serviceInterface}}) { -{{#operation}} - {{#swagger2AnnotationLibrary}} - @Operation( +{{#operation}} +{{^useResponseEntity}} + @ResponseStatus({{#springHttpStatus}}{{#responses.0}}{{{code}}}{{/responses.0}}{{/springHttpStatus}}){{! +}}{{/useResponseEntity}}{{! +}}{{#swagger2AnnotationLibrary}}{{! +}} @Operation( summary = "{{{summary}}}", operationId = "{{{operationId}}}", description = """{{{unescapedNotes}}}""", @@ -83,15 +91,28 @@ class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) v value = [{{#responses}}ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}::class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}}]){{/swagger1AnnotationLibrary}} @RequestMapping( method = [RequestMethod.{{httpMethod}}], - value = ["{{#lambdaEscapeInNormalString}}{{{path}}}{{/lambdaEscapeInNormalString}}"]{{#singleContentTypes}}{{#hasProduces}}, + value = [PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}} /* "{{#lambdaEscapeInNormalString}}{{{path}}}{{/lambdaEscapeInNormalString}}" */]{{#singleContentTypes}}{{#hasProduces}}, produces = [{{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}}]{{/hasProduces}}{{#hasConsumes}}, consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}, produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}]{{/hasProduces}}{{#hasConsumes}}, consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}]{{/hasConsumes}}{{/singleContentTypes}} ) - {{#reactive}}{{^isArray}}suspend {{/isArray}}{{#isArray}}{{^useFlowForArrayReturnType}}suspend {{/useFlowForArrayReturnType}}{{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#swagger1AnnotationLibrary}}@ApiParam(hidden = true) {{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true) {{/swagger2AnnotationLibrary}}{{#reactive}}exchange: org.springframework.web.server.ServerWebExchange{{/reactive}}{{^reactive}}request: {{javaxPackage}}.servlet.http.HttpServletRequest{{/reactive}}{{/includeHttpRequestContext}}): ResponseEntity<{{>returnTypes}}> { + {{#reactive}}{{^isArray}}suspend {{/isArray}}{{#isArray}}{{^useFlowForArrayReturnType}}suspend {{/useFlowForArrayReturnType}}{{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}} + {{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, + {{/hasParams}}{{#swagger1AnnotationLibrary}}@ApiParam(hidden = true) {{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true) {{/swagger2AnnotationLibrary}}{{#reactive}}exchange: org.springframework.web.server.ServerWebExchange{{/reactive}}{{^reactive}}request: {{javaxPackage}}.servlet.http.HttpServletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#hasParams}} + {{/hasParams}}): {{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}} { return {{>returnValue}} } + {{/operation}} + companion object { + //for your own safety never directly reuse these path definitions in tests + {{#useRequestMappingOnController}} + const val BASE_PATH: String = "{{=<% %>=}}<%contextPath%><%={{ }}=%>" + {{/useRequestMappingOnController}} + {{#operation}} + const val PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}}: String = "{{{path}}}" + {{/operation}} + } } {{/operations}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/apiDelegate.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/apiDelegate.mustache index 403f55f33c67..5ae576a08bec 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/apiDelegate.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/apiDelegate.mustache @@ -4,7 +4,9 @@ package {{package}} {{/imports}} import org.springframework.http.HttpStatus import org.springframework.http.MediaType +{{#useResponseEntity}} import org.springframework.http.ResponseEntity +{{/useResponseEntity}} import org.springframework.web.context.request.NativeWebRequest {{#appendRequestToHandler}} import org.springframework.http.server.reactive.ServerHttpRequest @@ -14,9 +16,6 @@ import kotlinx.coroutines.flow.Flow {{/reactive}} import java.util.Optional -{{#async}} -import java.util.concurrent.CompletableFuture -{{/async}} {{#operations}} /** @@ -35,7 +34,7 @@ interface {{classname}}Delegate { */ {{#reactive}}{{^isArray}}suspend {{/isArray}}{{#isArray}}{{^useFlowForArrayReturnType}}suspend {{/useFlowForArrayReturnType}}{{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}{{#isBodyParam}}Flow<{{{baseType}}}>{{/isBodyParam}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{/isArray}}{{/reactive}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, - {{/hasParams}}{{#reactive}}exchange: org.springframework.web.server.ServerWebExchange{{/reactive}}{{^reactive}}request: {{javaxPackage}}.servlet.http.HttpServletRequest{{/reactive}}{{/includeHttpRequestContext}}): {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}}{{^skipDefaultDelegateInterface}} { + {{/hasParams}}{{#reactive}}exchange: org.springframework.web.server.ServerWebExchange{{/reactive}}{{^reactive}}request: {{javaxPackage}}.servlet.http.HttpServletRequest{{/reactive}}{{/includeHttpRequestContext}}): {{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}}{{^skipDefaultDelegateInterface}} { {{>methodBody}}{{! prevent indent}} }{{/skipDefaultDelegateInterface}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache index 386a41479b5b..6c60640cfa2d 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache @@ -25,7 +25,9 @@ import io.swagger.annotations.AuthorizationScope {{/swagger1AnnotationLibrary}} import org.springframework.http.HttpStatus import org.springframework.http.MediaType +{{#useResponseEntity}} import org.springframework.http.ResponseEntity +{{/useResponseEntity}} import org.springframework.web.bind.annotation.* {{#useBeanValidation}} @@ -33,6 +35,9 @@ import org.springframework.validation.annotation.Validated {{/useBeanValidation}} import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +{{#useRequestMappingOnInterface}} +import {{#apiPackage}}{{.}}.{{/apiPackage}}{{classname}}.Companion.BASE_PATH +{{/useRequestMappingOnInterface}} {{#useBeanValidation}} import {{javaxPackage}}.validation.constraints.DecimalMax @@ -63,7 +68,7 @@ import kotlin.collections.Map {{/swagger1AnnotationLibrary}} {{#useRequestMappingOnInterface}} {{=<% %>=}} -@RequestMapping("\${api.base-path:<%contextPath%>}") +@RequestMapping("\${api.<%title%>.base-path:api.base-path:$BASE_PATH}") <%={{ }}=%> {{/useRequestMappingOnInterface}} {{#operations}} @@ -72,10 +77,13 @@ interface {{classname}} { fun getDelegate(): {{classname}}Delegate{{^skipDefaultDelegateInterface}} = object: {{classname}}Delegate {}{{/skipDefaultDelegateInterface}} {{/isDelegate}} -{{#operation}} - {{#swagger2AnnotationLibrary}} - @Operation( +{{#operation}} +{{^useResponseEntity}} + @ResponseStatus({{#springHttpStatus}}{{#responses.0}}{{{code}}}{{/responses.0}}{{/springHttpStatus}}){{! +}}{{/useResponseEntity}}{{! +}}{{#swagger2AnnotationLibrary}}{{! +}} @Operation( tags = [{{#tags}}"{{{name}}}",{{/tags}}], summary = "{{{summary}}}", operationId = "{{{operationId}}}", @@ -91,18 +99,23 @@ interface {{classname}} { notes = "{{{notes}}}"{{#returnBaseType}}, response = {{{.}}}::class{{/returnBaseType}}{{#returnContainer}}, responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}}, - authorizations = [{{#authMethods}}Authorization(value = "{{name}}"{{#isOAuth}}, scopes = [{{#scopes}}AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, {{/-last}}{{/scopes}}]{{/isOAuth}}){{^-last}}, {{/-last}}{{/authMethods}}]{{/hasAuthMethods}}) + authorizations = [{{#authMethods}}Authorization(value = "{{name}}"{{#isOAuth}}, scopes = [{{#scopes}}AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, {{/-last}}{{/scopes}}]{{/isOAuth}}){{^-last}}, {{/-last}}{{/authMethods}}]{{/hasAuthMethods}} + ) @ApiResponses( - value = [{{#responses}}ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}::class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}}, {{/-last}}{{/responses}}]){{/swagger1AnnotationLibrary}} + value = [{{#responses}}ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}::class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}}, {{/-last}}{{/responses}}] + ){{/swagger1AnnotationLibrary}} @RequestMapping( - method = [RequestMethod.{{httpMethod}}], - value = ["{{#lambdaEscapeInNormalString}}{{{path}}}{{/lambdaEscapeInNormalString}}"]{{#singleContentTypes}}{{#hasProduces}}, - produces = [{{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}}]{{/hasProduces}}{{#hasConsumes}}, - consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}, - produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}]{{/hasProduces}}{{#hasConsumes}}, - consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}]{{/hasConsumes}}{{/singleContentTypes}} + method = [RequestMethod.{{httpMethod}}], + value = [PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}} /* "{{#lambdaEscapeInNormalString}}{{{path}}}{{/lambdaEscapeInNormalString}}" */]{{#singleContentTypes}}{{#hasProduces}}, + produces = [{{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}}]{{/hasProduces}}{{#hasConsumes}}, + consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}, + produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}]{{/hasProduces}}{{#hasConsumes}}, + consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}]{{/hasConsumes}}{{/singleContentTypes}} ) - {{#reactive}}{{^isArray}}suspend {{/isArray}}{{#isArray}}{{^useFlowForArrayReturnType}}suspend {{/useFlowForArrayReturnType}}{{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#swagger1AnnotationLibrary}}@ApiParam(hidden = true) {{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true) {{/swagger2AnnotationLibrary}}{{#reactive}}exchange: org.springframework.web.server.ServerWebExchange{{/reactive}}{{^reactive}}request: {{javaxPackage}}.servlet.http.HttpServletRequest{{/reactive}}{{/includeHttpRequestContext}}): ResponseEntity<{{>returnTypes}}>{{^skipDefaultApiInterface}} { + {{#reactive}}{{^isArray}}suspend {{/isArray}}{{#isArray}}{{^useFlowForArrayReturnType}}suspend {{/useFlowForArrayReturnType}}{{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}} + {{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, + {{/hasParams}}{{#swagger1AnnotationLibrary}}@ApiParam(hidden = true) {{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true) {{/swagger2AnnotationLibrary}}{{#reactive}}exchange: org.springframework.web.server.ServerWebExchange{{/reactive}}{{^reactive}}request: {{javaxPackage}}.servlet.http.HttpServletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#hasParams}} + {{/hasParams}}): {{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}}{{^skipDefaultApiInterface}} { {{^isDelegate}} return {{>returnValue}} {{/isDelegate}} @@ -110,6 +123,16 @@ interface {{classname}} { return getDelegate().{{operationId}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#reactive}}exchange{{/reactive}}{{^reactive}}request{{/reactive}}{{/includeHttpRequestContext}}) {{/isDelegate}} }{{/skipDefaultApiInterface}} + {{/operation}} + companion object { + //for your own safety never directly reuse these path definitions in tests + {{#useRequestMappingOnInterface}} + const val BASE_PATH: String = "{{=<% %>=}}<%contextPath%><%={{ }}=%>" + {{/useRequestMappingOnInterface}} + {{#operation}} + const val PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}}: String = "{{{path}}}" + {{/operation}} + } } {{/operations}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/api_test.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/api_test.mustache index 32b1134d7e46..eda2afcd0c18 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/api_test.mustache @@ -7,7 +7,12 @@ import org.junit.jupiter.api.Test import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.test.runBlockingTest {{/reactive}} +{{^useResponseEntity}} +import org.springframework.http.HttpStatus +{{/useResponseEntity}} +{{#useResponseEntity}} import org.springframework.http.ResponseEntity +{{/useResponseEntity}} class {{classname}}Test { @@ -30,7 +35,7 @@ class {{classname}}Test { val {{{paramName}}}: {{>optionalDataType}} = TODO() {{/allParams}} {{#includeHttpRequestContext}}val {{#reactive}}exchange: org.springframework.web.server.ServerWebExchange{{/reactive}}{{^reactive}}request: {{javaxPackage}}.servlet.http.HttpServletRequest{{/reactive}} = TODO(){{/includeHttpRequestContext}} - val response: ResponseEntity<{{>returnTypes}}> = api.{{operationId}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#reactive}}exchange{{/reactive}}{{^reactive}}request{{/reactive}}{{/includeHttpRequestContext}}) + val response: {{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}} = api.{{operationId}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#reactive}}exchange{{/reactive}}{{^reactive}}request{{/reactive}}{{/includeHttpRequestContext}}) // TODO: test validations } diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/bodyParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/bodyParams.mustache index 4ca6b20ca93d..b4f03475cd0b 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/bodyParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/bodyParams.mustache @@ -1 +1 @@ -{{#isBodyParam}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"], defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"]){{/defaultValue}}{{/allowableValues}}{{/isContainer}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}, allowableValues = "{{{.}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}}{{#useBeanValidation}} @Valid{{>beanValidationBodyParams}}{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{{paramName}}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}} \ No newline at end of file +{{#isBodyParam}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"], defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"]){{/defaultValue}}{{/allowableValues}}{{/isContainer}}) {{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}, allowableValues = "{{{.}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}) {{/swagger1AnnotationLibrary}}{{#useBeanValidation}}@Valid{{>beanValidationBodyParams}}{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{{paramName}}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/formParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/formParams.mustache index c6eb0799686a..456af893718f 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/formParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/formParams.mustache @@ -1 +1 @@ -{{#isFormParam}}{{^isFile}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} {{#isModel}}@RequestPart{{/isModel}}{{^isModel}}@RequestParam{{/isModel}}(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}) {{{paramName}}}: {{>optionalDataType}} {{/isFile}}{{#isFile}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "file detail"){{/swagger1AnnotationLibrary}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestPart("{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}) {{{paramName}}}: {{>optionalDataType}}{{/isFile}}{{/isFormParam}} \ No newline at end of file +{{#isFormParam}}{{^isFile}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}) {{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}) {{/swagger1AnnotationLibrary}}{{#useBeanValidation}}@Valid {{/useBeanValidation}}{{#isModel}}@RequestPart{{/isModel}}{{^isModel}}@RequestParam{{/isModel}}(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}) {{{paramName}}}: {{>optionalDataType}}{{/isFile}}{{#isFile}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}") {{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "file detail") {{/swagger1AnnotationLibrary}}{{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestPart("{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}) {{{paramName}}}: {{>optionalDataType}}{{/isFile}}{{/isFormParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/headerParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/headerParams.mustache index a6fa7386e360..0c2678f1bf67 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/headerParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/headerParams.mustache @@ -1 +1 @@ -{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationCore}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}", `in` = ParameterIn.HEADER{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @RequestHeader(value = "{{baseName}}", required = {{#required}}true{{/required}}{{^required}}false{{/required}}{{#defaultValue}}, defaultValue = {{^isString}}"{{{.}}}"{{/isString}}{{#isString}}{{#isEnum}}"{{{.}}}"{{/isEnum}}{{^isEnum}}{{{.}}}{{/isEnum}}{{/isString}}{{/defaultValue}}) {{{paramName}}}: {{>optionalDataType}}{{/isHeaderParam}} \ No newline at end of file +{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationCore}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}", `in` = ParameterIn.HEADER{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}) {{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}) {{/swagger1AnnotationLibrary}}@RequestHeader(value = "{{baseName}}", required = {{#required}}true{{/required}}{{^required}}false{{/required}}{{#defaultValue}}, defaultValue = {{^isString}}"{{{.}}}"{{/isString}}{{#isString}}{{#isEnum}}"{{{.}}}"{{/isEnum}}{{^isEnum}}{{{.}}}{{/isEnum}}{{/isString}}{{/defaultValue}}) {{{paramName}}}: {{>optionalDataType}}{{/isHeaderParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/apiInterface.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/apiInterface.mustache index 6f724779ff6c..9e554bb4c54a 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/apiInterface.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/apiInterface.mustache @@ -29,7 +29,12 @@ import io.swagger.annotations.AuthorizationScope import org.springframework.web.service.annotation.* import org.springframework.web.bind.annotation.* +{{^useResponseEntity}} +import org.springframework.http.HttpStatus +{{/useResponseEntity}} +{{#useResponseEntity}} import org.springframework.http.ResponseEntity +{{/useResponseEntity}} {{#useBeanValidation}} import org.springframework.validation.annotation.Validated @@ -46,7 +51,7 @@ import kotlin.collections.List import kotlin.collections.Map {{#useRequestMappingOnInterface}}@HttpExchange( -"{{=<% %>=}}\${api.base-path:$BASE_PATH}<%={{ }}=%>" +"{{=<% %>=}}\${api.<%title%>.base-path:api.base-path:$BASE_PATH}<%={{ }}=%>" ){{/useRequestMappingOnInterface}} {{#useBeanValidation}} @Validated @@ -54,10 +59,11 @@ import kotlin.collections.Map {{#operations}} interface {{classname}} { -{{#operation}} - {{#httpMethod}} - @HttpExchange( - url = PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}}, +{{#operation}}{{! +}}{{^useResponseEntity}} @ResponseStatus({{#springHttpStatus}}{{#responses.0}}{{{code}}}{{/responses.0}}{{/springHttpStatus}}) +{{/useResponseEntity}}{{! +}}{{#httpMethod}} @HttpExchange( + url = PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}} /* "{{#lambdaEscapeInNormalString}}{{{path}}}{{/lambdaEscapeInNormalString}}" */, method = "{{httpMethod}}" ) {{/httpMethod}}{{! diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/httpInterfaceBodyParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/httpInterfaceBodyParams.mustache index c6383a787c4a..e884046f7d6d 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/httpInterfaceBodyParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/httpInterfaceBodyParams.mustache @@ -1 +1 @@ -{{#isBodyParam}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"], defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"]){{/defaultValue}}{{/allowableValues}}{{/isContainer}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}, allowableValues = "{{{.}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}}{{#useBeanValidation}} @Valid{{>beanValidationBodyParams}}{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{{paramName}}}: {{>optionalDataType}}{{/isBodyParam}} \ No newline at end of file +{{#isBodyParam}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"], defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"]){{/defaultValue}}{{/allowableValues}}{{/isContainer}}) {{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}, allowableValues = "{{{.}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}) {{/swagger1AnnotationLibrary}}{{#useBeanValidation}}@Valid{{>beanValidationBodyParams}}{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{{paramName}}}: {{>optionalDataType}}{{/isBodyParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/httpInterfaceReturnTypes.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/httpInterfaceReturnTypes.mustache index 86f9cea77382..9ea0fdf05f16 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/httpInterfaceReturnTypes.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/httpInterfaceReturnTypes.mustache @@ -1,47 +1,47 @@ {{! handle reactive map and array}} {{#reactive}} {{#isMap}} -{{#reactiveModeReactor}}Mono<{{/reactiveModeReactor}}{{#declarativeInterfaceWrapResponses}}ResponseEntity<{{/declarativeInterfaceWrapResponses}}Map{{#declarativeInterfaceWrapResponses}}>{{/declarativeInterfaceWrapResponses}}{{#reactiveModeReactor}}>{{/reactiveModeReactor}} +{{#reactiveModeReactor}}Mono<{{/reactiveModeReactor}}{{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}Map{{#useResponseEntity}}>{{/useResponseEntity}}{{#reactiveModeReactor}}>{{/reactiveModeReactor}} {{/isMap}} {{#isArray}} {{! array handle reactive - reactor with/without ResponseEntity wrapper}} {{#reactiveModeReactor}} -{{#declarativeInterfaceWrapResponses}}Mono{{#declarativeInterfaceWrapResponses}}>>{{/declarativeInterfaceWrapResponses}} +{{#useResponseEntity}}Mono{{#useResponseEntity}}>>{{/useResponseEntity}} {{/reactiveModeReactor}} {{! array handle reactive - coroutines with/without ResponseEntity wrapper}} {{#reactiveModeCoroutines}} -{{#declarativeInterfaceWrapResponses}}ResponseEntity<{{/declarativeInterfaceWrapResponses}}{{{returnContainer}}}<{{{returnType}}}>{{#declarativeInterfaceWrapResponses}}>{{/declarativeInterfaceWrapResponses}} +{{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{{returnContainer}}}<{{{returnType}}}>{{#useResponseEntity}}>{{/useResponseEntity}} {{/reactiveModeCoroutines}} {{/isArray}} {{! handle reactive non-container - with/without ResponseEntity wrapper}} {{^returnContainer}} {{#reactiveModeReactor}} -Mono<{{#declarativeInterfaceWrapResponses}}ResponseEntity<{{/declarativeInterfaceWrapResponses}}{{{returnType}}}{{#declarativeInterfaceWrapResponses}}>{{/declarativeInterfaceWrapResponses}}> +Mono<{{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{{returnType}}}{{#useResponseEntity}}>{{/useResponseEntity}}> {{/reactiveModeReactor}} {{#reactiveModeCoroutines}} -{{#declarativeInterfaceWrapResponses}} -ResponseEntity<{{/declarativeInterfaceWrapResponses}}{{{returnType}}}{{#declarativeInterfaceWrapResponses}}> -{{/declarativeInterfaceWrapResponses}} +{{#useResponseEntity}} +ResponseEntity<{{/useResponseEntity}}{{{returnType}}}{{#useResponseEntity}}> +{{/useResponseEntity}} {{/reactiveModeCoroutines}} {{/returnContainer}} {{/reactive}} {{^reactive}} {{! handle non-reactive map and array}} {{#isMap}} -{{#declarativeInterfaceWrapResponses}} -ResponseEntity<{{/declarativeInterfaceWrapResponses}}Map{{#declarativeInterfaceWrapResponses}}> -{{/declarativeInterfaceWrapResponses}} +{{#useResponseEntity}} +ResponseEntity<{{/useResponseEntity}}Map{{#useResponseEntity}}> +{{/useResponseEntity}} {{/isMap}} {{#isArray}} {{! array handle non-reactive - with/without ResponseEntity wrapper}} -{{#declarativeInterfaceWrapResponses}} -ResponseEntity<{{/declarativeInterfaceWrapResponses}}{{{returnContainer}}}<{{{returnType}}}>{{#declarativeInterfaceWrapResponses}}> -{{/declarativeInterfaceWrapResponses}} +{{#useResponseEntity}} +ResponseEntity<{{/useResponseEntity}}{{{returnContainer}}}<{{{returnType}}}>{{#useResponseEntity}}> +{{/useResponseEntity}} {{/isArray}} {{! handle reactive non-container - with/without ResponseEntity wrapper}} {{^returnContainer}} -{{#declarativeInterfaceWrapResponses}} -ResponseEntity<{{/declarativeInterfaceWrapResponses}}{{{returnType}}}{{#declarativeInterfaceWrapResponses}}> -{{/declarativeInterfaceWrapResponses}} +{{#useResponseEntity}} +ResponseEntity<{{/useResponseEntity}}{{{returnType}}}{{#useResponseEntity}}> +{{/useResponseEntity}} {{/returnContainer}} {{/reactive}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/methodBody.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/methodBody.mustache index 30be6d64a4b4..0a6660b342a8 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/methodBody.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/methodBody.mustache @@ -1,28 +1,23 @@ {{^reactive}} {{#examples}} {{#-first}} - {{#async}} -return CompletableFuture.supplyAsync(()-> { - {{/async}}getRequest().ifPresent { request -> -{{#async}} {{/async}} for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) { +getRequest().ifPresent { request -> + for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) { {{/-first}} -{{#async}} {{/async}}{{^async}} {{/async}} if (mediaType.isCompatibleWith(MediaType.valueOf("{{{contentType}}}"))) { -{{#async}} {{/async}}{{^async}} {{/async}} ApiUtil.setExampleResponse(request, "{{{contentType}}}", "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{example}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}") -{{#async}} {{/async}}{{^async}} {{/async}} break -{{#async}} {{/async}}{{^async}} {{/async}} } + if (mediaType.isCompatibleWith(MediaType.valueOf("{{{contentType}}}"))) { + ApiUtil.setExampleResponse(request, "{{{contentType}}}", "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{example}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}") + break + } {{#-last}} -{{#async}} {{/async}}{{^async}} {{/async}} } -{{#async}} {{/async}} } -{{#async}} {{/async}} return ResponseEntity({{#returnSuccessCode}}HttpStatus.valueOf({{{statusCode}}}){{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}}) - {{#async}} - }, Runnable::run) - {{/async}} + } + } + return {{#useResponseEntity}}ResponseEntity({{#returnSuccessCode}}HttpStatus.valueOf({{{statusCode}}}){{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}}){{/useResponseEntity}}{{^useResponseEntity}}TODO("Not yet implemented"){{/useResponseEntity}} {{/-last}} {{/examples}} {{^examples}} -return {{#async}}CompletableFuture.completedFuture({{/async}}ResponseEntity({{#returnSuccessCode}}HttpStatus.OK{{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}}) +return {{#useResponseEntity}}ResponseEntity({{#returnSuccessCode}}HttpStatus.OK{{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}}){{/useResponseEntity}}{{^useResponseEntity}}TODO("Not yet implemented"){{/useResponseEntity}} {{/examples}} {{/reactive}} {{#reactive}} -return ResponseEntity({{#returnSuccessCode}}HttpStatus.OK{{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}}) +return {{#useResponseEntity}}ResponseEntity({{#returnSuccessCode}}HttpStatus.OK{{/returnSuccessCode}}{{^returnSuccessCode}}HttpStatus.NOT_IMPLEMENTED{{/returnSuccessCode}}){{/useResponseEntity}}{{^useResponseEntity}}TODO("Not yet implemented"){{/useResponseEntity}} {{/reactive}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/pathParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/pathParams.mustache index 0fd5398a244f..2e28d18c78fa 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/pathParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/pathParams.mustache @@ -1 +1 @@ -{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @PathVariable("{{baseName}}") {{{paramName}}}: {{>optionalDataType}}{{/isPathParam}} \ No newline at end of file +{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}) {{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}) {{/swagger1AnnotationLibrary}}@PathVariable("{{baseName}}") {{{paramName}}}: {{>optionalDataType}}{{/isPathParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/queryParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/queryParams.mustache index 2bf764c99633..27d7e286bb33 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/queryParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/queryParams.mustache @@ -1 +1 @@ -{{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}){{/swagger1AnnotationLibrary}}{{#useBeanValidation}} @Valid{{/useBeanValidation}}{{^isModel}} @RequestParam(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}){{/isModel}}{{#isDate}} @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE){{/isDate}}{{#isDateTime}} @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME){{/isDateTime}} {{{paramName}}}: {{>optionalDataType}}{{/isQueryParam}} \ No newline at end of file +{{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}) {{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}) {{/swagger1AnnotationLibrary}}{{#useBeanValidation}}@Valid{{/useBeanValidation}}{{^isModel}} @RequestParam(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}){{/isModel}}{{#isDate}} @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE){{/isDate}}{{#isDateTime}} @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME){{/isDateTime}} {{{paramName}}}: {{>optionalDataType}}{{/isQueryParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/returnValue.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/returnValue.mustache index 8c7c1aa4f5ce..44336bb5db69 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/returnValue.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/returnValue.mustache @@ -1 +1,4 @@ -{{#serviceInterface}}ResponseEntity(service.{{operationId}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}), {{#responses}}{{#-first}}HttpStatus.valueOf({{code}}){{/-first}}{{/responses}}){{/serviceInterface}}{{^serviceInterface}}ResponseEntity(HttpStatus.NOT_IMPLEMENTED){{/serviceInterface}} \ No newline at end of file +{{!}}{{#useResponseEntity}}{{#serviceInterface}}ResponseEntity(service.{{operationId}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}), {{#responses}}{{#-first}}HttpStatus.valueOf({{code}}){{/-first}}{{/responses}}){{/serviceInterface}}{{/useResponseEntity}}{{! +---}}{{#useResponseEntity}}{{^serviceInterface}}ResponseEntity(HttpStatus.NOT_IMPLEMENTED){{/serviceInterface}}{{/useResponseEntity}}{{! +---}}{{^useResponseEntity}}{{#serviceInterface}}service.{{operationId}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}){{/serviceInterface}}{{/useResponseEntity}}{{! +---}}{{^useResponseEntity}}{{^serviceInterface}}TODO("Not yet implemented"){{/serviceInterface}}{{/useResponseEntity}} \ No newline at end of file diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinReservedWordsTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinReservedWordsTest.java index 7e41bae21523..f8e65fae5bbe 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinReservedWordsTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinReservedWordsTest.java @@ -191,7 +191,8 @@ public void reservedWordsInGeneratedServerCode() throws Exception { File resultSourcePath = new File(output, "src/main/kotlin"); assertFileContains(Paths.get(resultSourcePath.getAbsolutePath() + baseApiPackage + "AnnotationsApiController.kt"), - "fun annotationsPost(@Parameter(description = \"\", required = true) @Valid @RequestBody `annotation`: Annotation", + "fun annotationsPost(" + + " @Parameter(description = \"\", required = true) @Valid @RequestBody `annotation`: Annotation", "return ResponseEntity(service.annotationsPost(`annotation`), HttpStatus.valueOf(200))" ); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java index b697029a4151..43c330044b8f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java @@ -402,13 +402,17 @@ public void testNullableMultipartFile() throws IOException { generator.opts(input).generate(); assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/NullableMultipartfileApiController.kt"), - "file: org.springframework.web.multipart.MultipartFile?)"); + "file: org.springframework.web.multipart.MultipartFile?" + + " )"); assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/NullableMultipartfileArrayApiController.kt"), - "files: Array?)"); + "files: Array?" + + " )"); assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/NonNullableMultipartfileApiController.kt"), - "file: org.springframework.web.multipart.MultipartFile)"); + "file: org.springframework.web.multipart.MultipartFile" + + " )"); assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/NonNullableMultipartfileArrayApiController.kt"), - "files: Array)"); + "files: Array" + + " )"); } @Test @@ -1038,7 +1042,7 @@ public void generateHttpInterfaceReactiveWithReactorResponseEntity() throws Exce codegen.additionalProperties().put(CodegenConstants.LIBRARY, "spring-declarative-http-interface"); codegen.additionalProperties().put(REACTIVE, true); codegen.additionalProperties().put(DECLARATIVE_INTERFACE_REACTIVE_MODE, "reactor"); - codegen.additionalProperties().put(DECLARATIVE_INTERFACE_WRAP_RESPONSES, true); + codegen.additionalProperties().put(USE_RESPONSE_ENTITY, true); codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "none"); codegen.additionalProperties().put(USE_FLOW_FOR_ARRAY_RETURN_TYPE, false); @@ -1061,20 +1065,20 @@ public void generateHttpInterfaceReactiveWithReactorResponseEntity() throws Exce "import reactor.core.publisher.Flux\n" + "import reactor.core.publisher.Mono", " @HttpExchange(\n" - + " url = PATH_GET_INVENTORY,\n" + + " url = PATH_GET_INVENTORY /* \"/store/inventory\" */,\n" + " method = \"GET\"\n" + " )\n" + " fun getInventory(\n" + " ): Mono>>", " @HttpExchange(\n" - + " url = PATH_DELETE_ORDER,\n" + + " url = PATH_DELETE_ORDER /* \"/store/order/{orderId}\" */,\n" + " method = \"DELETE\"\n" + " )\n" + " fun deleteOrder(\n" + " @Parameter(description = \"ID of the order that needs to be deleted\", required = true) @PathVariable(\"orderId\") orderId: kotlin.String\n" + " ): Mono>", " @HttpExchange(\n" - + " url = PATH_PLACE_ORDER,\n" + + " url = PATH_PLACE_ORDER /* \"/store/order\" */,\n" + " method = \"POST\"\n" + " )\n" + " fun placeOrder(\n" @@ -1105,7 +1109,7 @@ public void generateHttpInterfaceReactiveWithCoroutinesResponseEntity() throws E codegen.additionalProperties().put(CodegenConstants.LIBRARY, "spring-declarative-http-interface"); codegen.additionalProperties().put(REACTIVE, true); codegen.additionalProperties().put(DECLARATIVE_INTERFACE_REACTIVE_MODE, "coroutines"); - codegen.additionalProperties().put(DECLARATIVE_INTERFACE_WRAP_RESPONSES, true); + codegen.additionalProperties().put(USE_RESPONSE_ENTITY, true); codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "none"); codegen.additionalProperties().put(USE_FLOW_FOR_ARRAY_RETURN_TYPE, false); @@ -1147,7 +1151,7 @@ public void generateHttpInterfaceReactiveWithReactor() throws Exception { codegen.additionalProperties().put(CodegenConstants.LIBRARY, "spring-declarative-http-interface"); codegen.additionalProperties().put(REACTIVE, true); codegen.additionalProperties().put(DECLARATIVE_INTERFACE_REACTIVE_MODE, "reactor"); - codegen.additionalProperties().put(DECLARATIVE_INTERFACE_WRAP_RESPONSES, false); + codegen.additionalProperties().put(USE_RESPONSE_ENTITY, false); codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "none"); codegen.additionalProperties().put(USE_FLOW_FOR_ARRAY_RETURN_TYPE, false); @@ -1184,7 +1188,6 @@ public void generateHttpInterfaceReactiveWithReactor() throws Exception { ); } - @Test public void generateHttpInterfaceReactiveWithCoroutines() throws Exception { File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); @@ -1196,7 +1199,7 @@ public void generateHttpInterfaceReactiveWithCoroutines() throws Exception { codegen.additionalProperties().put(CodegenConstants.LIBRARY, "spring-declarative-http-interface"); codegen.additionalProperties().put(REACTIVE, true); codegen.additionalProperties().put(DECLARATIVE_INTERFACE_REACTIVE_MODE, "coroutines"); - codegen.additionalProperties().put(DECLARATIVE_INTERFACE_WRAP_RESPONSES, false); + codegen.additionalProperties().put(USE_RESPONSE_ENTITY, false); codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "none"); codegen.additionalProperties().put(USE_FLOW_FOR_ARRAY_RETURN_TYPE, false); @@ -1237,7 +1240,7 @@ public void generateHttpInterfaceResponseEntity() throws Exception { codegen.setOutputDir(output.getAbsolutePath()); codegen.additionalProperties().put(CodegenConstants.LIBRARY, "spring-declarative-http-interface"); codegen.additionalProperties().put(REACTIVE, false); - codegen.additionalProperties().put(DECLARATIVE_INTERFACE_WRAP_RESPONSES, true); + codegen.additionalProperties().put(USE_RESPONSE_ENTITY, true); codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "none"); codegen.additionalProperties().put(USE_FLOW_FOR_ARRAY_RETURN_TYPE, false); @@ -1282,7 +1285,7 @@ public void generateHttpInterface() throws Exception { codegen.setOutputDir(output.getAbsolutePath()); codegen.additionalProperties().put(CodegenConstants.LIBRARY, "spring-declarative-http-interface"); codegen.additionalProperties().put(REACTIVE, false); - codegen.additionalProperties().put(DECLARATIVE_INTERFACE_WRAP_RESPONSES, false); + codegen.additionalProperties().put(USE_RESPONSE_ENTITY, false); codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "none"); codegen.additionalProperties().put(USE_FLOW_FOR_ARRAY_RETURN_TYPE, false); @@ -1383,7 +1386,12 @@ private void verifyGeneratedFilesContain(Map> expectedSnippet for (var expectedSnippetsByPathToFile : expectedSnippetsByPathsToFiles.entrySet()) { assertFileContains(expectedSnippetsByPathToFile.getKey(), expectedSnippetsByPathToFile.getValue().toArray(new String[0])); } + } + private void verifyGeneratedFilesNotContain(Map> unexpectedSnippetsByPathsToFiles) { + for (var unexpectedSnippetsByPathToFile : unexpectedSnippetsByPathsToFiles.entrySet()) { + assertFileNotContains(unexpectedSnippetsByPathToFile.getKey(), unexpectedSnippetsByPathToFile.getValue().toArray(new String[0])); + } } @Test @@ -1405,8 +1413,15 @@ public void reactiveWithHttpRequestContextControllerImplAnnotationSwaggerNoDeleg verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApiController.kt"), List.of( - "deletePet(@Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById(@Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApiController.kt"), List.of( "logoutUser(@Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange)") ) @@ -1432,8 +1447,15 @@ public void reactiveWithHttpRequestContextControllerImplAnnotationSwagger1NoDele verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApiController.kt"), List.of( - "deletePet(@ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById(@ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApiController.kt"), List.of( "logoutUser(@ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange") ) @@ -1459,8 +1481,15 @@ public void reactiveWithHttpRequestContextControllerImplAnnotationNoneNoDelegate verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApiController.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long, exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApiController.kt"), List.of( "logoutUser(exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity") ) @@ -1486,8 +1515,13 @@ public void reactiveWithoutHttpRequestContextControllerImplAnnotationNoneNoDeleg verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApiController.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApiController.kt"), List.of( "logoutUser(): ResponseEntity") ) @@ -1513,8 +1547,15 @@ public void nonReactiveWithHttpRequestContextControllerImplAnnotationSwaggerNoDe verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApiController.kt"), List.of( - "deletePet(@Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById(@Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApiController.kt"), List.of( "logoutUser(@Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity") ) @@ -1540,8 +1581,15 @@ public void nonReactiveWithHttpRequestContextControllerImplAnnotationSwagger1NoD verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApiController.kt"), List.of( - "deletePet(@ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById(@ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApiController.kt"), List.of( "logoutUser(@ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity") ) @@ -1567,8 +1615,15 @@ public void nonReactiveWithHttpRequestContextControllerImplAnnotationNoneNoDeleg verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApiController.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long, request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApiController.kt"), List.of( "logoutUser(request: javax.servlet.http.HttpServletRequest): ResponseEntity") ) @@ -1594,8 +1649,13 @@ public void nonReactiveWithoutHttpRequestContextControllerImplAnnotationNoneNoDe verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApiController.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApiController.kt"), List.of( "logoutUser(): ResponseEntity") ) @@ -1621,8 +1681,15 @@ public void reactiveWithHttpRequestContextInterfaceOnlyAnnotationSwaggerNoDelega verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById(@Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity") ) @@ -1648,8 +1715,15 @@ public void reactiveWithHttpRequestContextInterfaceOnlyAnnotationSwagger1NoDeleg verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById(@ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity") ) @@ -1675,8 +1749,15 @@ public void reactiveWithHttpRequestContextInterfaceOnlyAnnotationNoneNoDelegate( verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long, exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity") ) @@ -1702,8 +1783,13 @@ public void reactiveWithoutHttpRequestContextInterfaceOnlyAnnotationNoneNoDelega verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(): ResponseEntity") ) @@ -1729,8 +1815,15 @@ public void nonReactiveWithHttpRequestContextInterfaceOnlyAnnotationSwaggerNoDel verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById(@Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity") ) @@ -1756,8 +1849,15 @@ public void nonReactiveWithHttpRequestContextInterfaceOnlyAnnotationSwagger1NoDe verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById(@ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity") ) @@ -1783,8 +1883,15 @@ public void nonReactiveWithHttpRequestContextInterfaceOnlyAnnotationNoneNoDelega verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long, request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(request: javax.servlet.http.HttpServletRequest): ResponseEntity") ) @@ -1811,8 +1918,15 @@ public void nonReactiveWithHttpRequestContextControllerImplAnnotationNoneNoDeleg verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApiController.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long, request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApiController.kt"), List.of( "logoutUser(request: javax.servlet.http.HttpServletRequest): ResponseEntity"), root.resolve("src/test/kotlin/org/openapitools/api/PetApiTest.kt"), List.of( @@ -1825,7 +1939,6 @@ public void nonReactiveWithHttpRequestContextControllerImplAnnotationNoneNoDeleg ); } - @Test public void reactiveWithHttpRequestContextControllerImplAnnotationNoneNoDelegateWithApiTests() throws Exception { Path root = generateApiSources(Map.of( @@ -1846,8 +1959,15 @@ public void reactiveWithHttpRequestContextControllerImplAnnotationNoneNoDelegate verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApiController.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long, exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApiController.kt"), List.of( "logoutUser(exchange: org.springframework.web.server.ServerWebExchange)"), root.resolve("src/test/kotlin/org/openapitools/api/PetApiTest.kt"), List.of( @@ -1879,8 +1999,13 @@ public void nonReactiveWithoutHttpRequestContextInterfaceOnlyAnnotationNoneNoDel verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(): ResponseEntity") ) @@ -1906,8 +2031,15 @@ public void reactiveWithHttpRequestContextControllerImplAnnotationSwaggerDelegat verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById(@Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -1938,8 +2070,15 @@ public void reactiveWithHttpRequestContextControllerImplAnnotationSwagger1Delega verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById(@ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -1970,8 +2109,15 @@ public void reactiveWithHttpRequestContextControllerImplAnnotationNoneDelegate() verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long, exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2002,8 +2148,13 @@ public void reactiveWithoutHttpRequestContextControllerImplAnnotationNoneDelegat verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2034,8 +2185,15 @@ public void nonReactiveWithHttpRequestContextControllerImplAnnotationSwaggerDele verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById(@Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2066,8 +2224,15 @@ public void nonReactiveWithHttpRequestContextControllerImplAnnotationSwagger1Del verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById(@ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2098,8 +2263,15 @@ public void nonReactiveWithHttpRequestContextControllerImplAnnotationNoneDelegat verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long, request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "fun deletePet(\n" + + " @PathVariable(\"petId\") petId: kotlin.Long,\n" + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?,\n" + + " request: javax.servlet.http.HttpServletRequest\n" + + " ): ResponseEntity {", + "fun getPetById(\n" + + " @PathVariable(\"petId\") petId: kotlin.Long,\n" + + " request: javax.servlet.http.HttpServletRequest\n" + + " ): ResponseEntity {"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(request: javax.servlet.http.HttpServletRequest): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2130,8 +2302,13 @@ public void nonReactiveWithoutHttpRequestContextControllerImplAnnotationNoneDele verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2162,8 +2339,15 @@ public void reactiveWithHttpRequestContextInterfaceOnlyAnnotationSwaggerDelegate verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById(@Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@Parameter(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2194,8 +2378,15 @@ public void reactiveWithHttpRequestContextInterfaceOnlyAnnotationSwagger1Delegat verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById(@ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2226,8 +2417,15 @@ public void reactiveWithHttpRequestContextInterfaceOnlyAnnotationNoneDelegate() verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long, exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " exchange: org.springframework.web.server.ServerWebExchange" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2258,8 +2456,13 @@ public void reactiveWithoutHttpRequestContextInterfaceOnlyAnnotationNoneDelegate verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2290,8 +2493,15 @@ public void nonReactiveWithHttpRequestContextInterfaceOnlyAnnotationSwaggerDeleg verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById(@Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @Parameter(description = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(description = \"\", `in` = ParameterIn.HEADER) @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @Parameter(description = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@Parameter(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2322,8 +2532,15 @@ public void nonReactiveWithHttpRequestContextInterfaceOnlyAnnotationSwagger1Dele verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet(@ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long,@ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById(@ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @ApiParam(value = \"Pet id to delete\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(value = \"\") @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @ApiParam(value = \"ID of pet to return\", required = true) @PathVariable(\"petId\") petId: kotlin.Long," + + " @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(@ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2354,8 +2571,15 @@ public void nonReactiveWithHttpRequestContextInterfaceOnlyAnnotationNoneDelegate verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?, request: javax.servlet.http.HttpServletRequest): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long, request: javax.servlet.http.HttpServletRequest): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?," + + " request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " request: javax.servlet.http.HttpServletRequest" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(request: javax.servlet.http.HttpServletRequest): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2386,8 +2610,13 @@ public void nonReactiveWithoutHttpRequestContextInterfaceOnlyAnnotationNoneDeleg verifyGeneratedFilesContain( Map.of( root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( - "deletePet( @PathVariable(\"petId\") petId: kotlin.Long, @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?): ResponseEntity", - "getPetById( @PathVariable(\"petId\") petId: kotlin.Long): ResponseEntity"), + "deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): ResponseEntity", + "getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( "logoutUser(): ResponseEntity"), root.resolve("src/main/kotlin/org/openapitools/api/PetApiDelegate.kt"), List.of( @@ -2399,6 +2628,174 @@ public void nonReactiveWithoutHttpRequestContextInterfaceOnlyAnnotationNoneDeleg ); } + @Test + public void reactiveWithoutResponseEntity() throws Exception { + Path root = generateApiSources(Map.of( + KotlinSpringServerCodegen.REACTIVE, true, + KotlinSpringServerCodegen.DOCUMENTATION_PROVIDER, "none", + KotlinSpringServerCodegen.ANNOTATION_LIBRARY, "none", + KotlinSpringServerCodegen.INTERFACE_ONLY, true, + KotlinSpringServerCodegen.USE_RESPONSE_ENTITY, false + ), Map.of( + CodegenConstants.MODELS, "false", + CodegenConstants.MODEL_TESTS, "false", + CodegenConstants.MODEL_DOCS, "false", + CodegenConstants.APIS, "true", + CodegenConstants.SUPPORTING_FILES, "false" + )); + verifyGeneratedFilesContain( + Map.of( + root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( + "@ResponseStatus(HttpStatus.BAD_REQUEST)", + "suspend fun deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): Unit", + "@ResponseStatus(HttpStatus.OK)", + "suspend fun getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): Pet"), + root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( + "@ResponseStatus(HttpStatus.OK)", + "suspend fun logoutUser(): Unit" + ), + root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of( + "@ResponseStatus(HttpStatus.OK)", + "suspend fun getInventory(): Map") + ) + ); + } + + @Test + public void nonReactiveWithoutResponseEntity() throws Exception { + Path root = generateApiSources(Map.of( + KotlinSpringServerCodegen.REACTIVE, false, + KotlinSpringServerCodegen.DOCUMENTATION_PROVIDER, "none", + KotlinSpringServerCodegen.ANNOTATION_LIBRARY, "none", + KotlinSpringServerCodegen.INTERFACE_ONLY, true, + KotlinSpringServerCodegen.USE_RESPONSE_ENTITY, false + ), Map.of( + CodegenConstants.MODELS, "false", + CodegenConstants.MODEL_TESTS, "false", + CodegenConstants.MODEL_DOCS, "false", + CodegenConstants.APIS, "true", + CodegenConstants.SUPPORTING_FILES, "false" + )); + verifyGeneratedFilesContain( + Map.of( + root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( + "@ResponseStatus(HttpStatus.BAD_REQUEST)", + "fun deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): Unit", + "@ResponseStatus(HttpStatus.OK)", + "fun getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): Pet"), + root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( + "@ResponseStatus(HttpStatus.OK)", + "fun logoutUser(): Unit" + ), + root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of( + "@ResponseStatus(HttpStatus.OK)", + "fun getInventory(): Map") + ) + ); + + verifyGeneratedFilesNotContain( + Map.of( + root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of("suspend"), + root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of("suspend"), + root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of("suspend") + ) + ); + } + + @Test + public void reactiveWithResponseEntity() throws Exception { + Path root = generateApiSources(Map.of( + KotlinSpringServerCodegen.REACTIVE, true, + KotlinSpringServerCodegen.DOCUMENTATION_PROVIDER, "none", + KotlinSpringServerCodegen.ANNOTATION_LIBRARY, "none", + KotlinSpringServerCodegen.INTERFACE_ONLY, true, + KotlinSpringServerCodegen.USE_RESPONSE_ENTITY, true + ), Map.of( + CodegenConstants.MODELS, "false", + CodegenConstants.MODEL_TESTS, "false", + CodegenConstants.MODEL_DOCS, "false", + CodegenConstants.APIS, "true", + CodegenConstants.SUPPORTING_FILES, "false" + )); + verifyGeneratedFilesContain( + Map.of( + root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( + "suspend fun deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): ResponseEntity", + "suspend fun getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): ResponseEntity"), + root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( + "suspend fun logoutUser(): ResponseEntity" + ), + root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of( + "suspend fun getInventory(): ResponseEntity>") + ) + ); + + verifyGeneratedFilesNotContain( + Map.of( + root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of("@ResponseStatus(HttpStatus."), + root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of("@ResponseStatus(HttpStatus."), + root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of("@ResponseStatus(HttpStatus.") + ) + ); + } + + @Test + public void nonReactiveWithResponseEntity() throws Exception { + Path root = generateApiSources(Map.of( + KotlinSpringServerCodegen.REACTIVE, false, + KotlinSpringServerCodegen.DOCUMENTATION_PROVIDER, "none", + KotlinSpringServerCodegen.ANNOTATION_LIBRARY, "none", + KotlinSpringServerCodegen.INTERFACE_ONLY, true, + KotlinSpringServerCodegen.USE_RESPONSE_ENTITY, true + ), Map.of( + CodegenConstants.MODELS, "false", + CodegenConstants.MODEL_TESTS, "false", + CodegenConstants.MODEL_DOCS, "false", + CodegenConstants.APIS, "true", + CodegenConstants.SUPPORTING_FILES, "false" + )); + verifyGeneratedFilesContain( + Map.of( + root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of( + "fun deletePet(" + + " @PathVariable(\"petId\") petId: kotlin.Long," + + " @RequestHeader(value = \"api_key\", required = false) apiKey: kotlin.String?" + + " ): ResponseEntity", + "fun getPetById(" + + " @PathVariable(\"petId\") petId: kotlin.Long" + + " ): ResponseEntity"), + root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of( + "fun logoutUser(): ResponseEntity" + ), + root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of( + "fun getInventory(): ResponseEntity>") + ) + ); + + verifyGeneratedFilesNotContain( + Map.of( + root.resolve("src/main/kotlin/org/openapitools/api/PetApi.kt"), List.of("suspend", "@ResponseStatus(HttpStatus."), + root.resolve("src/main/kotlin/org/openapitools/api/UserApi.kt"), List.of("suspend", "@ResponseStatus(HttpStatus."), + root.resolve("src/main/kotlin/org/openapitools/api/StoreApi.kt"), List.of("suspend", "@ResponseStatus(HttpStatus.") + ) + ); + } + @Test public void reactiveWithoutFlow() throws Exception { File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); diff --git a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/PetApi.kt b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/PetApi.kt index 88fdcb3bdd40..36c1821868b9 100644 --- a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/PetApi.kt +++ b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/PetApi.kt @@ -34,83 +34,116 @@ interface PetApi { @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet"], - produces = ["application/xml", "application/json"], - consumes = ["application/json", "application/xml"] + method = [RequestMethod.POST], + value = [PATH_ADD_PET /* "/pet" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json", "application/xml"] ) - fun addPet( @Valid @RequestBody pet: Pet): ResponseEntity { + fun addPet( + @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet( @PathVariable("petId") petId: kotlin.Long, @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @PathVariable("petId") petId: kotlin.Long, + @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByStatus"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], + produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByTags"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], + produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/{petId}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], + produces = ["application/xml", "application/json"] ) - fun getPetById( @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.PUT], - value = ["/pet"], - produces = ["application/xml", "application/json"], - consumes = ["application/json", "application/xml"] + method = [RequestMethod.PUT], + value = [PATH_UPDATE_PET /* "/pet" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json", "application/xml"] ) - fun updatePet( @Valid @RequestBody pet: Pet): ResponseEntity { + fun updatePet( + @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}"], - consumes = ["application/x-www-form-urlencoded"] + method = [RequestMethod.POST], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], + consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm( @PathVariable("petId") petId: kotlin.Long, @Valid @RequestParam(value = "name", required = false) name: kotlin.String? , @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + fun updatePetWithForm( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], - produces = ["application/json"], - consumes = ["multipart/form-data"] + method = [RequestMethod.POST], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], + produces = ["application/json"], + consumes = ["multipart/form-data"] ) - fun uploadFile( @PathVariable("petId") petId: kotlin.Long, @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? , @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + fun uploadFile( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/StoreApi.kt b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/StoreApi.kt index 309f66b435d0..6542dbc72f7a 100644 --- a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/StoreApi.kt +++ b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/StoreApi.kt @@ -33,18 +33,20 @@ interface StoreApi { @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder( @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/inventory"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], + produces = ["application/json"] ) fun getInventory(): ResponseEntity> { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) @@ -52,22 +54,34 @@ interface StoreApi { @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], + produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.POST], - value = ["/store/order"], - produces = ["application/xml", "application/json"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_PLACE_ORDER /* "/store/order" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json"] ) - fun placeOrder( @Valid @RequestBody order: Order): ResponseEntity { + fun placeOrder( + @Valid @RequestBody order: Order + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/UserApi.kt b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/UserApi.kt index 318293a5e7f8..fe632bdab180 100644 --- a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/UserApi.kt +++ b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/api/UserApi.kt @@ -33,67 +33,80 @@ interface UserApi { @RequestMapping( - method = [RequestMethod.POST], - value = ["/user"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USER /* "/user" */], + consumes = ["application/json"] ) - fun createUser( @Valid @RequestBody user: User): ResponseEntity { + fun createUser( + @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithArray"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], + consumes = ["application/json"] ) - fun createUsersWithArrayInput( @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithList"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], + consumes = ["application/json"] ) - fun createUsersWithListInput( @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/user/{username}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser( @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/{username}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], + produces = ["application/xml", "application/json"] ) - fun getUserByName( @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/login"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_LOGIN_USER /* "/user/login" */], + produces = ["application/xml", "application/json"] ) - fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + fun loginUser( + @NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/logout"] + method = [RequestMethod.GET], + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) @@ -101,11 +114,26 @@ interface UserApi { @RequestMapping( - method = [RequestMethod.PUT], - value = ["/user/{username}"], - consumes = ["application/json"] + method = [RequestMethod.PUT], + value = [PATH_UPDATE_USER /* "/user/{username}" */], + consumes = ["application/json"] ) - fun updateUser( @PathVariable("username") username: kotlin.String, @Valid @RequestBody user: User): ResponseEntity { + fun updateUser( + @PathVariable("username") username: kotlin.String, + @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/PetApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/PetApiClient.kt index 986ac550b93a..bdab1c810b35 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/PetApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/PetApiClient.kt @@ -15,7 +15,7 @@ import io.swagger.v3.oas.annotations.security.* import org.springframework.web.service.annotation.* import org.springframework.web.bind.annotation.* -import org.springframework.http.ResponseEntity +import org.springframework.http.HttpStatus import org.springframework.validation.annotation.Validated import jakarta.validation.Valid @@ -29,16 +29,18 @@ import kotlin.collections.Map @Validated interface PetApi { + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_ADD_PET, + url = PATH_ADD_PET /* "/pet" */, method = "POST" ) suspend fun addPet( @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet ): Pet + @ResponseStatus(HttpStatus.BAD_REQUEST) @HttpExchange( - url = PATH_DELETE_PET, + url = PATH_DELETE_PET /* "/pet/{petId}" */, method = "DELETE" ) suspend fun deletePet( @@ -46,8 +48,9 @@ interface PetApi { @Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? ): Unit + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_FIND_PETS_BY_STATUS, + url = PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */, method = "GET" ) suspend fun findPetsByStatus( @@ -55,8 +58,9 @@ interface PetApi { ): List + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_FIND_PETS_BY_TAGS, + url = PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */, method = "GET" ) suspend fun findPetsByTags( @@ -64,39 +68,43 @@ interface PetApi { ): List + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_GET_PET_BY_ID, + url = PATH_GET_PET_BY_ID /* "/pet/{petId}" */, method = "GET" ) suspend fun getPetById( @Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long ): Pet + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_UPDATE_PET, + url = PATH_UPDATE_PET /* "/pet" */, method = "PUT" ) suspend fun updatePet( @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet ): Pet + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) @HttpExchange( - url = PATH_UPDATE_PET_WITH_FORM, + url = PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */, method = "POST" ) suspend fun updatePetWithForm( @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, - @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? , - @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): Unit + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_UPLOAD_FILE, + url = PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */, method = "POST" ) suspend fun uploadFile( @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, - @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? , + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile ): ModelApiResponse diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/StoreApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/StoreApiClient.kt index b0d74b2a4807..4ff6c3f3c758 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/StoreApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/StoreApiClient.kt @@ -14,7 +14,7 @@ import io.swagger.v3.oas.annotations.security.* import org.springframework.web.service.annotation.* import org.springframework.web.bind.annotation.* -import org.springframework.http.ResponseEntity +import org.springframework.http.HttpStatus import org.springframework.validation.annotation.Validated import jakarta.validation.Valid @@ -28,32 +28,36 @@ import kotlin.collections.Map @Validated interface StoreApi { + @ResponseStatus(HttpStatus.BAD_REQUEST) @HttpExchange( - url = PATH_DELETE_ORDER, + url = PATH_DELETE_ORDER /* "/store/order/{orderId}" */, method = "DELETE" ) suspend fun deleteOrder( @Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String ): Unit + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_GET_INVENTORY, + url = PATH_GET_INVENTORY /* "/store/inventory" */, method = "GET" ) suspend fun getInventory( ): Map + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_GET_ORDER_BY_ID, + url = PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */, method = "GET" ) suspend fun getOrderById( @Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long ): Order + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_PLACE_ORDER, + url = PATH_PLACE_ORDER /* "/store/order" */, method = "POST" ) suspend fun placeOrder( diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/UserApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/UserApiClient.kt index dff2d3849af6..722c7060a304 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/UserApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/api/UserApiClient.kt @@ -14,7 +14,7 @@ import io.swagger.v3.oas.annotations.security.* import org.springframework.web.service.annotation.* import org.springframework.web.bind.annotation.* -import org.springframework.http.ResponseEntity +import org.springframework.http.HttpStatus import org.springframework.validation.annotation.Validated import jakarta.validation.Valid @@ -28,48 +28,54 @@ import kotlin.collections.Map @Validated interface UserApi { + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_CREATE_USER, + url = PATH_CREATE_USER /* "/user" */, method = "POST" ) suspend fun createUser( @Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User ): Unit + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_CREATE_USERS_WITH_ARRAY_INPUT, + url = PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */, method = "POST" ) suspend fun createUsersWithArrayInput( @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List ): Unit + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_CREATE_USERS_WITH_LIST_INPUT, + url = PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */, method = "POST" ) suspend fun createUsersWithListInput( @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List ): Unit + @ResponseStatus(HttpStatus.BAD_REQUEST) @HttpExchange( - url = PATH_DELETE_USER, + url = PATH_DELETE_USER /* "/user/{username}" */, method = "DELETE" ) suspend fun deleteUser( @Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String ): Unit + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_GET_USER_BY_NAME, + url = PATH_GET_USER_BY_NAME /* "/user/{username}" */, method = "GET" ) suspend fun getUserByName( @Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String ): User + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_LOGIN_USER, + url = PATH_LOGIN_USER /* "/user/login" */, method = "GET" ) suspend fun loginUser( @@ -77,15 +83,17 @@ interface UserApi { @NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String ): kotlin.String + @ResponseStatus(HttpStatus.OK) @HttpExchange( - url = PATH_LOGOUT_USER, + url = PATH_LOGOUT_USER /* "/user/logout" */, method = "GET" ) suspend fun logoutUser( ): Unit + @ResponseStatus(HttpStatus.BAD_REQUEST) @HttpExchange( - url = PATH_UPDATE_USER, + url = PATH_UPDATE_USER /* "/user/{username}" */, method = "PUT" ) suspend fun updateUser( diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt index dc86929e4990..c65fb3ba8785 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt @@ -32,7 +32,7 @@ import kotlin.collections.Map interface PetApi { @HttpExchange( - url = PATH_ADD_PET, + url = PATH_ADD_PET /* "/pet" */, method = "POST" ) fun addPet( @@ -41,7 +41,7 @@ interface PetApi { @HttpExchange( - url = PATH_DELETE_PET, + url = PATH_DELETE_PET /* "/pet/{petId}" */, method = "DELETE" ) fun deletePet( @@ -51,7 +51,7 @@ interface PetApi { @HttpExchange( - url = PATH_FIND_PETS_BY_STATUS, + url = PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */, method = "GET" ) fun findPetsByStatus( @@ -60,7 +60,7 @@ interface PetApi { @HttpExchange( - url = PATH_FIND_PETS_BY_TAGS, + url = PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */, method = "GET" ) fun findPetsByTags( @@ -69,7 +69,7 @@ interface PetApi { @HttpExchange( - url = PATH_GET_PET_BY_ID, + url = PATH_GET_PET_BY_ID /* "/pet/{petId}" */, method = "GET" ) fun getPetById( @@ -78,7 +78,7 @@ interface PetApi { @HttpExchange( - url = PATH_UPDATE_PET, + url = PATH_UPDATE_PET /* "/pet" */, method = "PUT" ) fun updatePet( @@ -87,23 +87,23 @@ interface PetApi { @HttpExchange( - url = PATH_UPDATE_PET_WITH_FORM, + url = PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */, method = "POST" ) fun updatePetWithForm( @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, - @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? , - @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): Mono> @HttpExchange( - url = PATH_UPLOAD_FILE, + url = PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */, method = "POST" ) fun uploadFile( @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, - @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? , + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile ): Mono> diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt index 85f3bf03df56..6e79de6f9975 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt @@ -31,7 +31,7 @@ import kotlin.collections.Map interface StoreApi { @HttpExchange( - url = PATH_DELETE_ORDER, + url = PATH_DELETE_ORDER /* "/store/order/{orderId}" */, method = "DELETE" ) fun deleteOrder( @@ -40,7 +40,7 @@ interface StoreApi { @HttpExchange( - url = PATH_GET_INVENTORY, + url = PATH_GET_INVENTORY /* "/store/inventory" */, method = "GET" ) fun getInventory( @@ -48,7 +48,7 @@ interface StoreApi { @HttpExchange( - url = PATH_GET_ORDER_BY_ID, + url = PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */, method = "GET" ) fun getOrderById( @@ -57,7 +57,7 @@ interface StoreApi { @HttpExchange( - url = PATH_PLACE_ORDER, + url = PATH_PLACE_ORDER /* "/store/order" */, method = "POST" ) fun placeOrder( diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt index a7fc04c93b6d..9caf73a05169 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt @@ -31,7 +31,7 @@ import kotlin.collections.Map interface UserApi { @HttpExchange( - url = PATH_CREATE_USER, + url = PATH_CREATE_USER /* "/user" */, method = "POST" ) fun createUser( @@ -40,7 +40,7 @@ interface UserApi { @HttpExchange( - url = PATH_CREATE_USERS_WITH_ARRAY_INPUT, + url = PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */, method = "POST" ) fun createUsersWithArrayInput( @@ -49,7 +49,7 @@ interface UserApi { @HttpExchange( - url = PATH_CREATE_USERS_WITH_LIST_INPUT, + url = PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */, method = "POST" ) fun createUsersWithListInput( @@ -58,7 +58,7 @@ interface UserApi { @HttpExchange( - url = PATH_DELETE_USER, + url = PATH_DELETE_USER /* "/user/{username}" */, method = "DELETE" ) fun deleteUser( @@ -67,7 +67,7 @@ interface UserApi { @HttpExchange( - url = PATH_GET_USER_BY_NAME, + url = PATH_GET_USER_BY_NAME /* "/user/{username}" */, method = "GET" ) fun getUserByName( @@ -76,7 +76,7 @@ interface UserApi { @HttpExchange( - url = PATH_LOGIN_USER, + url = PATH_LOGIN_USER /* "/user/login" */, method = "GET" ) fun loginUser( @@ -86,7 +86,7 @@ interface UserApi { @HttpExchange( - url = PATH_LOGOUT_USER, + url = PATH_LOGOUT_USER /* "/user/logout" */, method = "GET" ) fun logoutUser( @@ -94,7 +94,7 @@ interface UserApi { @HttpExchange( - url = PATH_UPDATE_USER, + url = PATH_UPDATE_USER /* "/user/{username}" */, method = "PUT" ) fun updateUser( diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt index 19d77d469605..d463afa6aa24 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/PetApiClient.kt @@ -30,7 +30,7 @@ import kotlin.collections.Map interface PetApi { @HttpExchange( - url = PATH_ADD_PET, + url = PATH_ADD_PET /* "/pet" */, method = "POST" ) fun addPet( @@ -39,7 +39,7 @@ interface PetApi { @HttpExchange( - url = PATH_DELETE_PET, + url = PATH_DELETE_PET /* "/pet/{petId}" */, method = "DELETE" ) fun deletePet( @@ -49,7 +49,7 @@ interface PetApi { @HttpExchange( - url = PATH_FIND_PETS_BY_STATUS, + url = PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */, method = "GET" ) fun findPetsByStatus( @@ -58,7 +58,7 @@ interface PetApi { @HttpExchange( - url = PATH_FIND_PETS_BY_TAGS, + url = PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */, method = "GET" ) fun findPetsByTags( @@ -67,7 +67,7 @@ interface PetApi { @HttpExchange( - url = PATH_GET_PET_BY_ID, + url = PATH_GET_PET_BY_ID /* "/pet/{petId}" */, method = "GET" ) fun getPetById( @@ -76,7 +76,7 @@ interface PetApi { @HttpExchange( - url = PATH_UPDATE_PET, + url = PATH_UPDATE_PET /* "/pet" */, method = "PUT" ) fun updatePet( @@ -85,23 +85,23 @@ interface PetApi { @HttpExchange( - url = PATH_UPDATE_PET_WITH_FORM, + url = PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */, method = "POST" ) fun updatePetWithForm( @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, - @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? , - @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity @HttpExchange( - url = PATH_UPLOAD_FILE, + url = PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */, method = "POST" ) fun uploadFile( @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, - @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? , + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile ): ResponseEntity diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt index 95d07e02abf7..318a73809f5c 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/StoreApiClient.kt @@ -29,7 +29,7 @@ import kotlin.collections.Map interface StoreApi { @HttpExchange( - url = PATH_DELETE_ORDER, + url = PATH_DELETE_ORDER /* "/store/order/{orderId}" */, method = "DELETE" ) fun deleteOrder( @@ -38,7 +38,7 @@ interface StoreApi { @HttpExchange( - url = PATH_GET_INVENTORY, + url = PATH_GET_INVENTORY /* "/store/inventory" */, method = "GET" ) fun getInventory( @@ -46,7 +46,7 @@ interface StoreApi { @HttpExchange( - url = PATH_GET_ORDER_BY_ID, + url = PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */, method = "GET" ) fun getOrderById( @@ -55,7 +55,7 @@ interface StoreApi { @HttpExchange( - url = PATH_PLACE_ORDER, + url = PATH_PLACE_ORDER /* "/store/order" */, method = "POST" ) fun placeOrder( diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt index 1f9fcebe6d43..70f54f1bc572 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/api/UserApiClient.kt @@ -29,7 +29,7 @@ import kotlin.collections.Map interface UserApi { @HttpExchange( - url = PATH_CREATE_USER, + url = PATH_CREATE_USER /* "/user" */, method = "POST" ) fun createUser( @@ -38,7 +38,7 @@ interface UserApi { @HttpExchange( - url = PATH_CREATE_USERS_WITH_ARRAY_INPUT, + url = PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */, method = "POST" ) fun createUsersWithArrayInput( @@ -47,7 +47,7 @@ interface UserApi { @HttpExchange( - url = PATH_CREATE_USERS_WITH_LIST_INPUT, + url = PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */, method = "POST" ) fun createUsersWithListInput( @@ -56,7 +56,7 @@ interface UserApi { @HttpExchange( - url = PATH_DELETE_USER, + url = PATH_DELETE_USER /* "/user/{username}" */, method = "DELETE" ) fun deleteUser( @@ -65,7 +65,7 @@ interface UserApi { @HttpExchange( - url = PATH_GET_USER_BY_NAME, + url = PATH_GET_USER_BY_NAME /* "/user/{username}" */, method = "GET" ) fun getUserByName( @@ -74,7 +74,7 @@ interface UserApi { @HttpExchange( - url = PATH_LOGIN_USER, + url = PATH_LOGIN_USER /* "/user/login" */, method = "GET" ) fun loginUser( @@ -84,7 +84,7 @@ interface UserApi { @HttpExchange( - url = PATH_LOGOUT_USER, + url = PATH_LOGOUT_USER /* "/user/logout" */, method = "GET" ) fun logoutUser( @@ -92,7 +92,7 @@ interface UserApi { @HttpExchange( - url = PATH_UPDATE_USER, + url = PATH_UPDATE_USER /* "/user/{username}" */, method = "PUT" ) fun updateUser( diff --git a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/PetApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/PetApiClient.kt index 19d77d469605..d463afa6aa24 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/PetApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/PetApiClient.kt @@ -30,7 +30,7 @@ import kotlin.collections.Map interface PetApi { @HttpExchange( - url = PATH_ADD_PET, + url = PATH_ADD_PET /* "/pet" */, method = "POST" ) fun addPet( @@ -39,7 +39,7 @@ interface PetApi { @HttpExchange( - url = PATH_DELETE_PET, + url = PATH_DELETE_PET /* "/pet/{petId}" */, method = "DELETE" ) fun deletePet( @@ -49,7 +49,7 @@ interface PetApi { @HttpExchange( - url = PATH_FIND_PETS_BY_STATUS, + url = PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */, method = "GET" ) fun findPetsByStatus( @@ -58,7 +58,7 @@ interface PetApi { @HttpExchange( - url = PATH_FIND_PETS_BY_TAGS, + url = PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */, method = "GET" ) fun findPetsByTags( @@ -67,7 +67,7 @@ interface PetApi { @HttpExchange( - url = PATH_GET_PET_BY_ID, + url = PATH_GET_PET_BY_ID /* "/pet/{petId}" */, method = "GET" ) fun getPetById( @@ -76,7 +76,7 @@ interface PetApi { @HttpExchange( - url = PATH_UPDATE_PET, + url = PATH_UPDATE_PET /* "/pet" */, method = "PUT" ) fun updatePet( @@ -85,23 +85,23 @@ interface PetApi { @HttpExchange( - url = PATH_UPDATE_PET_WITH_FORM, + url = PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */, method = "POST" ) fun updatePetWithForm( @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, - @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? , - @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity @HttpExchange( - url = PATH_UPLOAD_FILE, + url = PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */, method = "POST" ) fun uploadFile( @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, - @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? , + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile ): ResponseEntity diff --git a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/StoreApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/StoreApiClient.kt index 95d07e02abf7..318a73809f5c 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/StoreApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/StoreApiClient.kt @@ -29,7 +29,7 @@ import kotlin.collections.Map interface StoreApi { @HttpExchange( - url = PATH_DELETE_ORDER, + url = PATH_DELETE_ORDER /* "/store/order/{orderId}" */, method = "DELETE" ) fun deleteOrder( @@ -38,7 +38,7 @@ interface StoreApi { @HttpExchange( - url = PATH_GET_INVENTORY, + url = PATH_GET_INVENTORY /* "/store/inventory" */, method = "GET" ) fun getInventory( @@ -46,7 +46,7 @@ interface StoreApi { @HttpExchange( - url = PATH_GET_ORDER_BY_ID, + url = PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */, method = "GET" ) fun getOrderById( @@ -55,7 +55,7 @@ interface StoreApi { @HttpExchange( - url = PATH_PLACE_ORDER, + url = PATH_PLACE_ORDER /* "/store/order" */, method = "POST" ) fun placeOrder( diff --git a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/UserApiClient.kt b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/UserApiClient.kt index 1f9fcebe6d43..70f54f1bc572 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/UserApiClient.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/api/UserApiClient.kt @@ -29,7 +29,7 @@ import kotlin.collections.Map interface UserApi { @HttpExchange( - url = PATH_CREATE_USER, + url = PATH_CREATE_USER /* "/user" */, method = "POST" ) fun createUser( @@ -38,7 +38,7 @@ interface UserApi { @HttpExchange( - url = PATH_CREATE_USERS_WITH_ARRAY_INPUT, + url = PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */, method = "POST" ) fun createUsersWithArrayInput( @@ -47,7 +47,7 @@ interface UserApi { @HttpExchange( - url = PATH_CREATE_USERS_WITH_LIST_INPUT, + url = PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */, method = "POST" ) fun createUsersWithListInput( @@ -56,7 +56,7 @@ interface UserApi { @HttpExchange( - url = PATH_DELETE_USER, + url = PATH_DELETE_USER /* "/user/{username}" */, method = "DELETE" ) fun deleteUser( @@ -65,7 +65,7 @@ interface UserApi { @HttpExchange( - url = PATH_GET_USER_BY_NAME, + url = PATH_GET_USER_BY_NAME /* "/user/{username}" */, method = "GET" ) fun getUserByName( @@ -74,7 +74,7 @@ interface UserApi { @HttpExchange( - url = PATH_LOGIN_USER, + url = PATH_LOGIN_USER /* "/user/login" */, method = "GET" ) fun loginUser( @@ -84,7 +84,7 @@ interface UserApi { @HttpExchange( - url = PATH_LOGOUT_USER, + url = PATH_LOGOUT_USER /* "/user/logout" */, method = "GET" ) fun logoutUser( @@ -92,7 +92,7 @@ interface UserApi { @HttpExchange( - url = PATH_UPDATE_USER, + url = PATH_UPDATE_USER /* "/user/{username}" */, method = "PUT" ) fun updateUser( diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/FakeApiController.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/FakeApiController.kt index e89b886bd6a3..8c82e0cc9056 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/FakeApiController.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/FakeApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.FakeApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -30,7 +31,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class FakeApiController() { @Operation( @@ -42,10 +43,12 @@ class FakeApiController() { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/fake/annotations"], + value = [PATH_ANNOTATIONS /* "/fake/annotations" */], consumes = ["application/json"] ) - fun annotations(@Parameter(description = "", required = true) @Valid @RequestBody `annotation`: Annotation): ResponseEntity { + fun annotations( + @Parameter(description = "", required = true) @Valid @RequestBody `annotation`: Annotation + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -59,10 +62,22 @@ class FakeApiController() { ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/fake/annotations"], + value = [PATH_UPDATE_PET_WITH_FORM_NUMBER /* "/fake/annotations" */], consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithFormNumber(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "integer type") @Valid @RequestParam(value = "status", required = false) status: kotlin.Int? ,@Parameter(description = "number type") @Valid @RequestParam(value = "status2", required = false) status2: java.math.BigDecimal? ): ResponseEntity { + fun updatePetWithFormNumber( + @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "integer type") @Valid @RequestParam(value = "status", required = false) status: kotlin.Int?, + @Parameter(description = "number type") @Valid @RequestParam(value = "status2", required = false) status2: java.math.BigDecimal? + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ANNOTATIONS: String = "/fake/annotations" + const val PATH_UPDATE_PET_WITH_FORM_NUMBER: String = "/fake/annotations" + } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/PetApiController.kt index 4da69ab07131..39eb46fad334 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.PetApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -31,7 +32,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class PetApiController() { @Operation( @@ -45,11 +46,13 @@ class PetApiController() { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet"], + value = [PATH_ADD_PET /* "/pet" */], produces = ["application/xml", "application/json"], consumes = ["application/json", "application/xml"] ) - fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + fun addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -63,9 +66,12 @@ class PetApiController() { ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -80,10 +86,12 @@ class PetApiController() { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByStatus"], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -98,10 +106,12 @@ class PetApiController() { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByTags"], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -117,10 +127,12 @@ class PetApiController() { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/{petId}"], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], produces = ["application/xml", "application/json"] ) - fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -137,11 +149,13 @@ class PetApiController() { ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/pet"], + value = [PATH_UPDATE_PET /* "/pet" */], produces = ["application/xml", "application/json"], consumes = ["application/json", "application/xml"] ) - fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + fun updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -155,10 +169,14 @@ class PetApiController() { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}"], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + fun updatePetWithForm( + @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -172,11 +190,28 @@ class PetApiController() { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], produces = ["application/json"], consumes = ["multipart/form-data"] ) - fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + fun uploadFile( + @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/StoreApiController.kt index c7a3cab4ff92..02170fa68d63 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.StoreApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -30,7 +31,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class StoreApiController() { @Operation( @@ -43,9 +44,11 @@ class StoreApiController() { ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -59,7 +62,7 @@ class StoreApiController() { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/inventory"], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], produces = ["application/json"] ) fun getInventory(): ResponseEntity> { @@ -77,10 +80,12 @@ class StoreApiController() { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -94,11 +99,22 @@ class StoreApiController() { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/store/order"], + value = [PATH_PLACE_ORDER /* "/store/order" */], produces = ["application/xml", "application/json"], consumes = ["application/json"] ) - fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order): ResponseEntity { + fun placeOrder( + @Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/UserApiController.kt index 6577de75e45f..dc009fc57bcf 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.UserApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -30,7 +31,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class UserApiController() { @Operation( @@ -43,10 +44,12 @@ class UserApiController() { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user"], + value = [PATH_CREATE_USER /* "/user" */], consumes = ["application/json"] ) - fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + fun createUser( + @Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -60,10 +63,12 @@ class UserApiController() { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithArray"], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], consumes = ["application/json"] ) - fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -77,10 +82,12 @@ class UserApiController() { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithList"], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], consumes = ["application/json"] ) - fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -95,9 +102,11 @@ class UserApiController() { ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/user/{username}"] + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -112,10 +121,12 @@ class UserApiController() { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/{username}"], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], produces = ["application/xml", "application/json"] ) - fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -129,10 +140,13 @@ class UserApiController() { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/login"], + value = [PATH_LOGIN_USER /* "/user/login" */], produces = ["application/xml", "application/json"] ) - fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + fun loginUser( + @NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -146,7 +160,7 @@ class UserApiController() { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/logout"] + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) @@ -163,10 +177,26 @@ class UserApiController() { ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/user/{username}"], + value = [PATH_UPDATE_USER /* "/user/{username}" */], consumes = ["application/json"] ) - fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + fun updateUser( + @Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String, + @Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/.openapi-generator-ignore b/samples/server/petstore/kotlin-springboot-3-no-response-entity/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-3-no-response-entity/.openapi-generator/FILES new file mode 100644 index 000000000000..c7afb2eda91e --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/.openapi-generator/FILES @@ -0,0 +1,27 @@ +README.md +build.gradle.kts +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +pom.xml +settings.gradle +src/main/kotlin/org/openapitools/Application.kt +src/main/kotlin/org/openapitools/api/ApiUtil.kt +src/main/kotlin/org/openapitools/api/Exceptions.kt +src/main/kotlin/org/openapitools/api/PetApiController.kt +src/main/kotlin/org/openapitools/api/PetApiService.kt +src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/StoreApiController.kt +src/main/kotlin/org/openapitools/api/StoreApiService.kt +src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/UserApiController.kt +src/main/kotlin/org/openapitools/api/UserApiService.kt +src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt +src/main/kotlin/org/openapitools/model/Category.kt +src/main/kotlin/org/openapitools/model/ModelApiResponse.kt +src/main/kotlin/org/openapitools/model/Order.kt +src/main/kotlin/org/openapitools/model/Pet.kt +src/main/kotlin/org/openapitools/model/Tag.kt +src/main/kotlin/org/openapitools/model/User.kt +src/main/resources/application.yaml diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/.openapi-generator/VERSION b/samples/server/petstore/kotlin-springboot-3-no-response-entity/.openapi-generator/VERSION new file mode 100644 index 000000000000..2fb556b60635 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.18.0-SNAPSHOT diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/README.md b/samples/server/petstore/kotlin-springboot-3-no-response-entity/README.md new file mode 100644 index 000000000000..b6865a081135 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/README.md @@ -0,0 +1,21 @@ +# openAPIPetstore + +This Kotlin based [Spring Boot](https://spring.io/projects/spring-boot) application has been generated using the [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator). + +## Getting Started + +This document assumes you have either maven or gradle available, either via the wrapper or otherwise. This does not come with a gradle / maven wrapper checked in. + +By default a [`pom.xml`](pom.xml) file will be generated. If you specified `gradleBuildFile=true` when generating this project, a `build.gradle.kts` will also be generated. Note this uses [Gradle Kotlin DSL](https://github.com/gradle/kotlin-dsl). + +To build the project using maven, run: +```bash +mvn package && java -jar target/openapi-spring-1.0.0.jar +``` + +To build the project using gradle, run: +```bash +gradle build && java -jar build/libs/openapi-spring-1.0.0.jar +``` + +If all builds successfully, the server should run on [http://localhost:8080/](http://localhost:8080/) diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/build.gradle.kts b/samples/server/petstore/kotlin-springboot-3-no-response-entity/build.gradle.kts new file mode 100644 index 000000000000..473c0162e0f4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/build.gradle.kts @@ -0,0 +1,42 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +group = "org.openapitools" +version = "1.0.0" +java.sourceCompatibility = JavaVersion.VERSION_17 + +repositories { + mavenCentral() + maven { url = uri("https://repo.spring.io/milestone") } +} + +tasks.withType { + kotlinOptions.jvmTarget = "17" +} + +plugins { + val kotlinVersion = "1.9.25" + id("org.jetbrains.kotlin.jvm") version kotlinVersion + id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion + id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion + id("org.springframework.boot") version "3.0.2" + id("io.spring.dependency-management") version "1.0.14.RELEASE" +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.springframework.boot:spring-boot-starter-web") + + implementation("com.google.code.findbugs:jsr305:3.0.2") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + implementation("jakarta.validation:jakarta.validation-api") + implementation("jakarta.annotation:jakarta.annotation-api:2.1.0") + + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") + testImplementation("org.springframework.boot:spring-boot-starter-test") { + exclude(module = "junit") + } +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradle/wrapper/gradle-wrapper.jar b/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..e6441136f3d4 Binary files /dev/null and b/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..80187ac30432 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradlew b/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradlew new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while +APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path +[ -h "$app_path" ] +do +ls=$( ls -ld "$app_path" ) +link=${ls#*' -> '} +case $link in #( +/*) app_path=$link ;; #( +*) app_path=$APP_HOME$link ;; +esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { +echo "$*" +} >&2 + +die () { +echo +echo "$*" +echo +exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( +CYGWIN* ) cygwin=true ;; #( +Darwin* ) darwin=true ;; #( +MSYS* | MINGW* ) msys=true ;; #( +NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then +if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +# IBM's JDK on AIX uses strange locations for the executables +JAVACMD=$JAVA_HOME/jre/sh/java +else +JAVACMD=$JAVA_HOME/bin/java +fi +if [ ! -x "$JAVACMD" ] ; then +die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +else +JAVACMD=java +if ! command -v java >/dev/null 2>&1 +then +die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then +case $MAX_FD in #( +max*) +# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +MAX_FD=$( ulimit -H -n ) || +warn "Could not query maximum file descriptor limit" +esac +case $MAX_FD in #( +'' | soft) :;; #( +*) +# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +ulimit -n "$MAX_FD" || +warn "Could not set maximum file descriptor limit to $MAX_FD" +esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then +APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) +CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + +JAVACMD=$( cygpath --unix "$JAVACMD" ) + +# Now convert the arguments - kludge to limit ourselves to /bin/sh +for arg do +if +case $arg in #( +-*) false ;; # don't mess with options #( +/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath +[ -e "$t" ] ;; #( +*) false ;; +esac +then +arg=$( cygpath --path --ignore --mixed "$arg" ) +fi +# Roll the args list around exactly as many times as the number of +# args, so each arg winds up back in the position where it started, but +# possibly modified. +# +# NB: a `for` loop captures its iteration list before it begins, so +# changing the positional parameters here affects neither the number of +# iterations, nor the values presented in `arg`. +shift # remove old arg +set -- "$@" "$arg" # push replacement arg +done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ +"-Dorg.gradle.appname=$APP_BASE_NAME" \ +-classpath "$CLASSPATH" \ +org.gradle.wrapper.GradleWrapperMain \ +"$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then +die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( +printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | +xargs -n1 | +sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | +tr '\n' ' ' +)" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradlew.bat b/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradlew.bat new file mode 100644 index 000000000000..25da30dbdeee --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/pom.xml b/samples/server/petstore/kotlin-springboot-3-no-response-entity/pom.xml new file mode 100644 index 000000000000..3c52a401bf8a --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/pom.xml @@ -0,0 +1,144 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 3.0.2 + 2.1.0 + 1.7.10 + + 1.7.10 + UTF-8 + + + org.springframework.boot + spring-boot-starter-parent + 3.1.3 + + + + repository.spring.milestone + Spring Milestone Repository + https://repo.spring.io/milestone + + + + + spring-milestones + https://repo.spring.io/milestone + + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + spring + + 17 + + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + + + org.springframework.boot + spring-boot-starter-web + + + + + + + com.google.code.findbugs + jsr305 + ${findbugs-jsr305.version} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + jakarta.validation + jakarta.validation-api + + + jakarta.annotation + jakarta.annotation-api + ${jakarta-annotation.version} + provided + + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin-test-junit5.version} + test + + + diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/settings.gradle b/samples/server/petstore/kotlin-springboot-3-no-response-entity/settings.gradle new file mode 100644 index 000000000000..14844905cd40 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + maven { url = uri("https://repo.spring.io/snapshot") } + maven { url = uri("https://repo.spring.io/milestone") } + gradlePluginPortal() + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "org.springframework.boot") { + useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}") + } + } + } +} +rootProject.name = "openapi-spring" diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/Application.kt new file mode 100644 index 000000000000..2fe6de62479e --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/Application.kt @@ -0,0 +1,13 @@ +package org.openapitools + +import org.springframework.boot.runApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.context.annotation.ComponentScan + +@SpringBootApplication +@ComponentScan(basePackages = ["org.openapitools", "org.openapitools.api", "org.openapitools.model"]) +class Application + +fun main(args: Array) { + runApplication(*args) +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 000000000000..03344e13b474 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,19 @@ +package org.openapitools.api + +import org.springframework.web.context.request.NativeWebRequest + +import jakarta.servlet.http.HttpServletResponse +import java.io.IOException + +object ApiUtil { + fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { + try { + val res = req.getNativeResponse(HttpServletResponse::class.java) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) + } catch (e: IOException) { + throw RuntimeException(e) + } + } +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/Exceptions.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/Exceptions.kt new file mode 100644 index 000000000000..1bd78f54576a --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/Exceptions.kt @@ -0,0 +1,30 @@ +package org.openapitools.api + +import org.springframework.context.annotation.Configuration +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.bind.annotation.ExceptionHandler +import jakarta.servlet.http.HttpServletResponse +import jakarta.validation.ConstraintViolationException + +// TODO Extend ApiException for custom exception handling, e.g. the below NotFound exception +sealed class ApiException(msg: String, val code: Int) : Exception(msg) + +class NotFoundException(msg: String, code: Int = HttpStatus.NOT_FOUND.value()) : ApiException(msg, code) + +@Configuration("org.openapitools.api.DefaultExceptionHandler") +@ControllerAdvice +class DefaultExceptionHandler { + + @ExceptionHandler(value = [ApiException::class]) + fun onApiException(ex: ApiException, response: HttpServletResponse): Unit = + response.sendError(ex.code, ex.message) + + @ExceptionHandler(value = [NotImplementedError::class]) + fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.NOT_IMPLEMENTED.value()) + + @ExceptionHandler(value = [ConstraintViolationException::class]) + fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message }) +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiController.kt new file mode 100644 index 000000000000..0cffbb9f76e6 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -0,0 +1,145 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.Valid +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +class PetApiController(@Autowired(required = true) val service: PetApiService) { + + + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_ADD_PET /* "/pet" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json", "application/xml"] + ) + fun addPet( + @Valid @RequestBody pet: Pet + ): ResponseEntity { + return ResponseEntity(service.addPet(pet), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.DELETE], + value = [PATH_DELETE_PET /* "/pet/{petId}" */] + ) + fun deletePet( + @PathVariable("petId") petId: kotlin.Long, + @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { + return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) + } + + + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], + produces = ["application/xml", "application/json"] + ) + fun findPetsByStatus( + @NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { + return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], + produces = ["application/xml", "application/json"] + ) + fun findPetsByTags( + @NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { + return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], + produces = ["application/xml", "application/json"] + ) + fun getPetById( + @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { + return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.PUT], + value = [PATH_UPDATE_PET /* "/pet" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json", "application/xml"] + ) + fun updatePet( + @Valid @RequestBody pet: Pet + ): ResponseEntity { + return ResponseEntity(service.updatePet(pet), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], + consumes = ["application/x-www-form-urlencoded"] + ) + fun updatePetWithForm( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { + return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) + } + + + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], + produces = ["application/json"], + consumes = ["multipart/form-data"] + ) + fun uploadFile( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { + return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiService.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiService.kt new file mode 100644 index 000000000000..031da963d22d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiService.kt @@ -0,0 +1,103 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet + +interface PetApiService { + + /** + * POST /pet : Add a new pet to the store + * + * + * @param pet Pet object that needs to be added to the store (required) + * @return successful operation (status code 200) + * or Invalid input (status code 405) + * @see PetApi#addPet + */ + fun addPet(pet: Pet): Pet + + /** + * DELETE /pet/{petId} : Deletes a pet + * + * + * @param petId Pet id to delete (required) + * @param apiKey (optional) + * @return Invalid pet value (status code 400) + * @see PetApi#deletePet + */ + fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit + + /** + * GET /pet/findByStatus : Finds Pets by status + * Multiple status values can be provided with comma separated strings + * + * @param status Status values that need to be considered for filter (required) + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + * @see PetApi#findPetsByStatus + */ + fun findPetsByStatus(status: kotlin.collections.List): List + + /** + * GET /pet/findByTags : Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * + * @param tags Tags to filter by (required) + * @return successful operation (status code 200) + * or Invalid tag value (status code 400) + * @deprecated + * @see PetApi#findPetsByTags + */ + fun findPetsByTags(tags: kotlin.collections.List): List + + /** + * GET /pet/{petId} : Find pet by ID + * Returns a single pet + * + * @param petId ID of pet to return (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * @see PetApi#getPetById + */ + fun getPetById(petId: kotlin.Long): Pet + + /** + * PUT /pet : Update an existing pet + * + * + * @param pet Pet object that needs to be added to the store (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * or Validation exception (status code 405) + * API documentation for the updatePet operation + * @see Update an existing pet Documentation + * @see PetApi#updatePet + */ + fun updatePet(pet: Pet): Pet + + /** + * POST /pet/{petId} : Updates a pet in the store with form data + * + * + * @param petId ID of pet that needs to be updated (required) + * @param name Updated name of the pet (optional) + * @param status Updated status of the pet (optional) + * @return Invalid input (status code 405) + * @see PetApi#updatePetWithForm + */ + fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit + + /** + * POST /pet/{petId}/uploadImage : uploads an image + * + * + * @param petId ID of pet to update (required) + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return successful operation (status code 200) + * @see PetApi#uploadFile + */ + fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.web.multipart.MultipartFile): ModelApiResponse +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt new file mode 100644 index 000000000000..6600f5535137 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt @@ -0,0 +1,40 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.springframework.stereotype.Service +@Service +class PetApiServiceImpl : PetApiService { + + override fun addPet(pet: Pet): Pet { + TODO("Implement me") + } + + override fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun findPetsByStatus(status: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun findPetsByTags(tags: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun getPetById(petId: kotlin.Long): Pet { + TODO("Implement me") + } + + override fun updatePet(pet: Pet): Pet { + TODO("Implement me") + } + + override fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.web.multipart.MultipartFile): ModelApiResponse { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiController.kt new file mode 100644 index 000000000000..457638d16963 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -0,0 +1,83 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.Valid +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +class StoreApiController(@Autowired(required = true) val service: StoreApiService) { + + + @RequestMapping( + method = [RequestMethod.DELETE], + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] + ) + fun deleteOrder( + @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { + return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) + } + + + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], + produces = ["application/json"] + ) + fun getInventory(): ResponseEntity> { + return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], + produces = ["application/xml", "application/json"] + ) + fun getOrderById( + @Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { + return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_PLACE_ORDER /* "/store/order" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json"] + ) + fun placeOrder( + @Valid @RequestBody order: Order + ): ResponseEntity { + return ResponseEntity(service.placeOrder(order), HttpStatus.valueOf(200)) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiService.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiService.kt new file mode 100644 index 000000000000..474b51456b27 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiService.kt @@ -0,0 +1,49 @@ +package org.openapitools.api + +import org.openapitools.model.Order + +interface StoreApiService { + + /** + * DELETE /store/order/{orderId} : Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * + * @param orderId ID of the order that needs to be deleted (required) + * @return Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#deleteOrder + */ + fun deleteOrder(orderId: kotlin.String): Unit + + /** + * GET /store/inventory : Returns pet inventories by status + * Returns a map of status codes to quantities + * + * @return successful operation (status code 200) + * @see StoreApi#getInventory + */ + fun getInventory(): Map + + /** + * GET /store/order/{orderId} : Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions + * + * @param orderId ID of pet that needs to be fetched (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#getOrderById + */ + fun getOrderById(orderId: kotlin.Long): Order + + /** + * POST /store/order : Place an order for a pet + * + * + * @param order order placed for purchasing the pet (required) + * @return successful operation (status code 200) + * or Invalid Order (status code 400) + * @see StoreApi#placeOrder + */ + fun placeOrder(order: Order): Order +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt new file mode 100644 index 000000000000..70e1e76b06b3 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt @@ -0,0 +1,23 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.springframework.stereotype.Service +@Service +class StoreApiServiceImpl : StoreApiService { + + override fun deleteOrder(orderId: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getInventory(): Map { + TODO("Implement me") + } + + override fun getOrderById(orderId: kotlin.Long): Order { + TODO("Implement me") + } + + override fun placeOrder(order: Order): Order { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiController.kt new file mode 100644 index 000000000000..fa8508cf219f --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -0,0 +1,135 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.Valid +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +class UserApiController(@Autowired(required = true) val service: UserApiService) { + + + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_CREATE_USER /* "/user" */], + consumes = ["application/json"] + ) + fun createUser( + @Valid @RequestBody user: User + ): ResponseEntity { + return ResponseEntity(service.createUser(user), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], + consumes = ["application/json"] + ) + fun createUsersWithArrayInput( + @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { + return ResponseEntity(service.createUsersWithArrayInput(user), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], + consumes = ["application/json"] + ) + fun createUsersWithListInput( + @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { + return ResponseEntity(service.createUsersWithListInput(user), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.DELETE], + value = [PATH_DELETE_USER /* "/user/{username}" */] + ) + fun deleteUser( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { + return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) + } + + + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], + produces = ["application/xml", "application/json"] + ) + fun getUserByName( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { + return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_LOGIN_USER /* "/user/login" */], + produces = ["application/xml", "application/json"] + ) + fun loginUser( + @NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { + return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_LOGOUT_USER /* "/user/logout" */] + ) + fun logoutUser(): ResponseEntity { + return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) + } + + + @RequestMapping( + method = [RequestMethod.PUT], + value = [PATH_UPDATE_USER /* "/user/{username}" */], + consumes = ["application/json"] + ) + fun updateUser( + @PathVariable("username") username: kotlin.String, + @Valid @RequestBody user: User + ): ResponseEntity { + return ResponseEntity(service.updateUser(username, user), HttpStatus.valueOf(400)) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiService.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiService.kt new file mode 100644 index 000000000000..8c28d098389a --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiService.kt @@ -0,0 +1,92 @@ +package org.openapitools.api + +import org.openapitools.model.User + +interface UserApiService { + + /** + * POST /user : Create user + * This can only be done by the logged in user. + * + * @param user Created user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUser + */ + fun createUser(user: User): Unit + + /** + * POST /user/createWithArray : Creates list of users with given input array + * + * + * @param user List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithArrayInput + */ + fun createUsersWithArrayInput(user: kotlin.collections.List): Unit + + /** + * POST /user/createWithList : Creates list of users with given input array + * + * + * @param user List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithListInput + */ + fun createUsersWithListInput(user: kotlin.collections.List): Unit + + /** + * DELETE /user/{username} : Delete user + * This can only be done by the logged in user. + * + * @param username The name that needs to be deleted (required) + * @return Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#deleteUser + */ + fun deleteUser(username: kotlin.String): Unit + + /** + * GET /user/{username} : Get user by user name + * + * + * @param username The name that needs to be fetched. Use user1 for testing. (required) + * @return successful operation (status code 200) + * or Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#getUserByName + */ + fun getUserByName(username: kotlin.String): User + + /** + * GET /user/login : Logs user into the system + * + * + * @param username The user name for login (required) + * @param password The password for login in clear text (required) + * @return successful operation (status code 200) + * or Invalid username/password supplied (status code 400) + * @see UserApi#loginUser + */ + fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String + + /** + * GET /user/logout : Logs out current logged in user session + * + * + * @return successful operation (status code 200) + * @see UserApi#logoutUser + */ + fun logoutUser(): Unit + + /** + * PUT /user/{username} : Updated user + * This can only be done by the logged in user. + * + * @param username name that need to be deleted (required) + * @param user Updated user object (required) + * @return Invalid user supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#updateUser + */ + fun updateUser(username: kotlin.String, user: User): Unit +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt new file mode 100644 index 000000000000..0c24688975c9 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt @@ -0,0 +1,39 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.springframework.stereotype.Service +@Service +class UserApiServiceImpl : UserApiService { + + override fun createUser(user: User): Unit { + TODO("Implement me") + } + + override fun createUsersWithArrayInput(user: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun createUsersWithListInput(user: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun deleteUser(username: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getUserByName(username: kotlin.String): User { + TODO("Implement me") + } + + override fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String { + TODO("Implement me") + } + + override fun logoutUser(): Unit { + TODO("Implement me") + } + + override fun updateUser(username: kotlin.String, user: User): Unit { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Category.kt new file mode 100644 index 000000000000..50cfbcf80623 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Category.kt @@ -0,0 +1,34 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * A category for a pet + * @param id + * @param name + */ +data class Category( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") + @get:JsonProperty("name") val name: kotlin.String? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt new file mode 100644 index 000000000000..4d12f23ba411 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt @@ -0,0 +1,36 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * Describes the result of uploading an image resource + * @param code + * @param type + * @param message + */ +data class ModelApiResponse( + + @get:JsonProperty("code") val code: kotlin.Int? = null, + + @get:JsonProperty("type") val type: kotlin.String? = null, + + @get:JsonProperty("message") val message: kotlin.String? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt new file mode 100644 index 000000000000..bee507c64e65 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt @@ -0,0 +1,67 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +import java.io.Serializable +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * An order for a pets from the pet store + * @param id + * @param petId + * @param quantity + * @param shipDate + * @param status Order Status + * @param complete + */ +data class Order( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("petId") val petId: kotlin.Long? = null, + + @get:JsonProperty("quantity") val quantity: kotlin.Int? = null, + + @get:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, + + @get:JsonProperty("status") val status: Order.Status? = null, + + @get:JsonProperty("complete") val complete: kotlin.Boolean? = false +) : Serializable { + + /** + * Order Status + * Values: placed,approved,delivered + */ + enum class Status(@get:JsonValue val value: kotlin.String) { + + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + } + } + } + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt new file mode 100644 index 000000000000..e78365b47814 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt @@ -0,0 +1,72 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +import org.openapitools.model.Category +import org.openapitools.model.Tag +import java.io.Serializable +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * A pet for sale in the pet store + * @param name + * @param photoUrls + * @param id + * @param category + * @param tags + * @param status pet status in the store + */ +data class Pet( + + @get:JsonProperty("name", required = true) val name: kotlin.String, + + @get:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @field:Valid + @get:JsonProperty("category") val category: Category? = null, + + @field:Valid + @get:JsonProperty("tags") val tags: kotlin.collections.List? = null, + + @Deprecated(message = "") + @get:JsonProperty("status") val status: Pet.Status? = null +) : Serializable { + + /** + * pet status in the store + * Values: available,pending,sold + */ + enum class Status(@get:JsonValue val value: kotlin.String) { + + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + } + } + } + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Tag.kt new file mode 100644 index 000000000000..bee0b3c419dd --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Tag.kt @@ -0,0 +1,33 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * A tag for a pet + * @param id + * @param name + */ +data class Tag( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("name") val name: kotlin.String? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/User.kt new file mode 100644 index 000000000000..df4b7c3b5883 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/User.kt @@ -0,0 +1,51 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * A User who is purchasing from the pet store + * @param id + * @param username + * @param firstName + * @param lastName + * @param email + * @param password + * @param phone + * @param userStatus User Status + */ +data class User( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("username") val username: kotlin.String? = null, + + @get:JsonProperty("firstName") val firstName: kotlin.String? = null, + + @get:JsonProperty("lastName") val lastName: kotlin.String? = null, + + @get:JsonProperty("email") val email: kotlin.String? = null, + + @get:JsonProperty("password") val password: kotlin.String? = null, + + @get:JsonProperty("phone") val phone: kotlin.String? = null, + + @get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/resources/application.yaml b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/resources/application.yaml new file mode 100644 index 000000000000..8e2ebcde976d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/resources/application.yaml @@ -0,0 +1,10 @@ +spring: + application: + name: openAPIPetstore + + jackson: + serialization: + WRITE_DATES_AS_TIMESTAMPS: false + +server: + port: 8080 diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/test/kotlin/org/openapitools/api/PetApiTest.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/test/kotlin/org/openapitools/api/PetApiTest.kt new file mode 100644 index 000000000000..48966ac74eca --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/test/kotlin/org/openapitools/api/PetApiTest.kt @@ -0,0 +1,137 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class PetApiTest { + + private val service: PetApiService = PetApiServiceImpl() + private val api: PetApiController = PetApiController(service) + + /** + * To test PetApiController.addPet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun addPetTest() { + val pet: Pet = TODO() + + val response: ResponseEntity = api.addPet(pet) + + // TODO: test validations + } + + /** + * To test PetApiController.deletePet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deletePetTest() { + val petId: kotlin.Long = TODO() + val apiKey: kotlin.String? = TODO() + + val response: ResponseEntity = api.deletePet(petId, apiKey) + + // TODO: test validations + } + + /** + * To test PetApiController.findPetsByStatus + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun findPetsByStatusTest() { + val status: kotlin.collections.List = TODO() + + val response: ResponseEntity> = api.findPetsByStatus(status) + + // TODO: test validations + } + + /** + * To test PetApiController.findPetsByTags + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun findPetsByTagsTest() { + val tags: kotlin.collections.List = TODO() + + val response: ResponseEntity> = api.findPetsByTags(tags) + + // TODO: test validations + } + + /** + * To test PetApiController.getPetById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getPetByIdTest() { + val petId: kotlin.Long = TODO() + + val response: ResponseEntity = api.getPetById(petId) + + // TODO: test validations + } + + /** + * To test PetApiController.updatePet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updatePetTest() { + val pet: Pet = TODO() + + val response: ResponseEntity = api.updatePet(pet) + + // TODO: test validations + } + + /** + * To test PetApiController.updatePetWithForm + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updatePetWithFormTest() { + val petId: kotlin.Long = TODO() + val name: kotlin.String? = TODO() + val status: kotlin.String? = TODO() + + val response: ResponseEntity = api.updatePetWithForm(petId, name, status) + + // TODO: test validations + } + + /** + * To test PetApiController.uploadFile + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun uploadFileTest() { + val petId: kotlin.Long = TODO() + val additionalMetadata: kotlin.String? = TODO() + val file: org.springframework.web.multipart.MultipartFile = TODO() + + val response: ResponseEntity = api.uploadFile(petId, additionalMetadata, file) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/test/kotlin/org/openapitools/api/StoreApiTest.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/test/kotlin/org/openapitools/api/StoreApiTest.kt new file mode 100644 index 000000000000..f8a87c71bca2 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/test/kotlin/org/openapitools/api/StoreApiTest.kt @@ -0,0 +1,70 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class StoreApiTest { + + private val service: StoreApiService = StoreApiServiceImpl() + private val api: StoreApiController = StoreApiController(service) + + /** + * To test StoreApiController.deleteOrder + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deleteOrderTest() { + val orderId: kotlin.String = TODO() + + val response: ResponseEntity = api.deleteOrder(orderId) + + // TODO: test validations + } + + /** + * To test StoreApiController.getInventory + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getInventoryTest() { + + val response: ResponseEntity> = api.getInventory() + + // TODO: test validations + } + + /** + * To test StoreApiController.getOrderById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getOrderByIdTest() { + val orderId: kotlin.Long = TODO() + + val response: ResponseEntity = api.getOrderById(orderId) + + // TODO: test validations + } + + /** + * To test StoreApiController.placeOrder + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun placeOrderTest() { + val order: Order = TODO() + + val response: ResponseEntity = api.placeOrder(order) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/test/kotlin/org/openapitools/api/UserApiTest.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/test/kotlin/org/openapitools/api/UserApiTest.kt new file mode 100644 index 000000000000..805c8bd0a8a1 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/test/kotlin/org/openapitools/api/UserApiTest.kt @@ -0,0 +1,132 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class UserApiTest { + + private val service: UserApiService = UserApiServiceImpl() + private val api: UserApiController = UserApiController(service) + + /** + * To test UserApiController.createUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUserTest() { + val user: User = TODO() + + val response: ResponseEntity = api.createUser(user) + + // TODO: test validations + } + + /** + * To test UserApiController.createUsersWithArrayInput + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUsersWithArrayInputTest() { + val user: kotlin.collections.List = TODO() + + val response: ResponseEntity = api.createUsersWithArrayInput(user) + + // TODO: test validations + } + + /** + * To test UserApiController.createUsersWithListInput + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUsersWithListInputTest() { + val user: kotlin.collections.List = TODO() + + val response: ResponseEntity = api.createUsersWithListInput(user) + + // TODO: test validations + } + + /** + * To test UserApiController.deleteUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deleteUserTest() { + val username: kotlin.String = TODO() + + val response: ResponseEntity = api.deleteUser(username) + + // TODO: test validations + } + + /** + * To test UserApiController.getUserByName + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getUserByNameTest() { + val username: kotlin.String = TODO() + + val response: ResponseEntity = api.getUserByName(username) + + // TODO: test validations + } + + /** + * To test UserApiController.loginUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun loginUserTest() { + val username: kotlin.String = TODO() + val password: kotlin.String = TODO() + + val response: ResponseEntity = api.loginUser(username, password) + + // TODO: test validations + } + + /** + * To test UserApiController.logoutUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun logoutUserTest() { + + val response: ResponseEntity = api.logoutUser() + + // TODO: test validations + } + + /** + * To test UserApiController.updateUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updateUserTest() { + val username: kotlin.String = TODO() + val user: User = TODO() + + val response: ResponseEntity = api.updateUser(username, user) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/PetApiController.kt index da8c6b076bb5..0cffbb9f76e6 100644 --- a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -31,82 +31,115 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { @RequestMapping( method = [RequestMethod.POST], - value = ["/pet"], + value = [PATH_ADD_PET /* "/pet" */], produces = ["application/xml", "application/json"], consumes = ["application/json", "application/xml"] ) - fun addPet( @Valid @RequestBody pet: Pet): ResponseEntity { + fun addPet( + @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(service.addPet(pet), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet( @PathVariable("petId") petId: kotlin.Long, @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @PathVariable("petId") petId: kotlin.Long, + @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByStatus"], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByTags"], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/{petId}"], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], produces = ["application/xml", "application/json"] ) - fun getPetById( @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.PUT], - value = ["/pet"], + value = [PATH_UPDATE_PET /* "/pet" */], produces = ["application/xml", "application/json"], consumes = ["application/json", "application/xml"] ) - fun updatePet( @Valid @RequestBody pet: Pet): ResponseEntity { + fun updatePet( + @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(service.updatePet(pet), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}"], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm( @PathVariable("petId") petId: kotlin.Long, @Valid @RequestParam(value = "name", required = false) name: kotlin.String? , @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + fun updatePetWithForm( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], produces = ["application/json"], consumes = ["multipart/form-data"] ) - fun uploadFile( @PathVariable("petId") petId: kotlin.Long, @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? , @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + fun uploadFile( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/StoreApiController.kt index dfec4ecc73fc..457638d16963 100644 --- a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -30,16 +30,18 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic @RequestMapping( method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder( @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/store/inventory"], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], produces = ["application/json"] ) fun getInventory(): ResponseEntity> { @@ -49,21 +51,33 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic @RequestMapping( method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/store/order"], + value = [PATH_PLACE_ORDER /* "/store/order" */], produces = ["application/xml", "application/json"], consumes = ["application/json"] ) - fun placeOrder( @Valid @RequestBody order: Order): ResponseEntity { + fun placeOrder( + @Valid @RequestBody order: Order + ): ResponseEntity { return ResponseEntity(service.placeOrder(order), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/UserApiController.kt index ce2c67c60423..fa8508cf219f 100644 --- a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -30,66 +30,79 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) @RequestMapping( method = [RequestMethod.POST], - value = ["/user"], + value = [PATH_CREATE_USER /* "/user" */], consumes = ["application/json"] ) - fun createUser( @Valid @RequestBody user: User): ResponseEntity { + fun createUser( + @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(service.createUser(user), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithArray"], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], consumes = ["application/json"] ) - fun createUsersWithArrayInput( @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(user), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithList"], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], consumes = ["application/json"] ) - fun createUsersWithListInput( @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(user), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.DELETE], - value = ["/user/{username}"] + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser( @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/user/{username}"], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], produces = ["application/xml", "application/json"] ) - fun getUserByName( @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/user/login"], + value = [PATH_LOGIN_USER /* "/user/login" */], produces = ["application/xml", "application/json"] ) - fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + fun loginUser( + @NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/user/logout"] + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) @@ -98,10 +111,25 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) @RequestMapping( method = [RequestMethod.PUT], - value = ["/user/{username}"], + value = [PATH_UPDATE_USER /* "/user/{username}" */], consumes = ["application/json"] ) - fun updateUser( @PathVariable("username") username: kotlin.String, @Valid @RequestBody user: User): ResponseEntity { + fun updateUser( + @PathVariable("username") username: kotlin.String, + @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(service.updateUser(username, user), HttpStatus.valueOf(400)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/PetApiController.kt index da8c6b076bb5..0cffbb9f76e6 100644 --- a/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -31,82 +31,115 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { @RequestMapping( method = [RequestMethod.POST], - value = ["/pet"], + value = [PATH_ADD_PET /* "/pet" */], produces = ["application/xml", "application/json"], consumes = ["application/json", "application/xml"] ) - fun addPet( @Valid @RequestBody pet: Pet): ResponseEntity { + fun addPet( + @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(service.addPet(pet), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet( @PathVariable("petId") petId: kotlin.Long, @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @PathVariable("petId") petId: kotlin.Long, + @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByStatus"], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByTags"], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/{petId}"], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], produces = ["application/xml", "application/json"] ) - fun getPetById( @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.PUT], - value = ["/pet"], + value = [PATH_UPDATE_PET /* "/pet" */], produces = ["application/xml", "application/json"], consumes = ["application/json", "application/xml"] ) - fun updatePet( @Valid @RequestBody pet: Pet): ResponseEntity { + fun updatePet( + @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(service.updatePet(pet), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}"], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm( @PathVariable("petId") petId: kotlin.Long, @Valid @RequestParam(value = "name", required = false) name: kotlin.String? , @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + fun updatePetWithForm( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], produces = ["application/json"], consumes = ["multipart/form-data"] ) - fun uploadFile( @PathVariable("petId") petId: kotlin.Long, @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? , @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + fun uploadFile( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/StoreApiController.kt index dfec4ecc73fc..457638d16963 100644 --- a/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -30,16 +30,18 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic @RequestMapping( method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder( @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/store/inventory"], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], produces = ["application/json"] ) fun getInventory(): ResponseEntity> { @@ -49,21 +51,33 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic @RequestMapping( method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/store/order"], + value = [PATH_PLACE_ORDER /* "/store/order" */], produces = ["application/xml", "application/json"], consumes = ["application/json"] ) - fun placeOrder( @Valid @RequestBody order: Order): ResponseEntity { + fun placeOrder( + @Valid @RequestBody order: Order + ): ResponseEntity { return ResponseEntity(service.placeOrder(order), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/UserApiController.kt index ce2c67c60423..fa8508cf219f 100644 --- a/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -30,66 +30,79 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) @RequestMapping( method = [RequestMethod.POST], - value = ["/user"], + value = [PATH_CREATE_USER /* "/user" */], consumes = ["application/json"] ) - fun createUser( @Valid @RequestBody user: User): ResponseEntity { + fun createUser( + @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(service.createUser(user), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithArray"], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], consumes = ["application/json"] ) - fun createUsersWithArrayInput( @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(user), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithList"], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], consumes = ["application/json"] ) - fun createUsersWithListInput( @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(user), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.DELETE], - value = ["/user/{username}"] + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser( @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/user/{username}"], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], produces = ["application/xml", "application/json"] ) - fun getUserByName( @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/user/login"], + value = [PATH_LOGIN_USER /* "/user/login" */], produces = ["application/xml", "application/json"] ) - fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + fun loginUser( + @NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/user/logout"] + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) @@ -98,10 +111,25 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) @RequestMapping( method = [RequestMethod.PUT], - value = ["/user/{username}"], + value = [PATH_UPDATE_USER /* "/user/{username}" */], consumes = ["application/json"] ) - fun updateUser( @PathVariable("username") username: kotlin.String, @Valid @RequestBody user: User): ResponseEntity { + fun updateUser( + @PathVariable("username") username: kotlin.String, + @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(service.updateUser(username, user), HttpStatus.valueOf(400)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-bigdecimal-default/src/main/kotlin/org/openapitools/api/TestApiController.kt b/samples/server/petstore/kotlin-springboot-bigdecimal-default/src/main/kotlin/org/openapitools/api/TestApiController.kt index 79d88b8d26b2..22bd57fee318 100644 --- a/samples/server/petstore/kotlin-springboot-bigdecimal-default/src/main/kotlin/org/openapitools/api/TestApiController.kt +++ b/samples/server/petstore/kotlin-springboot-bigdecimal-default/src/main/kotlin/org/openapitools/api/TestApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.TestApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -30,7 +31,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:}") +@RequestMapping("\${api.demo.base-path:api.base-path:$BASE_PATH}") class TestApiController() { @Operation( @@ -42,10 +43,18 @@ class TestApiController() { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/test"], + value = [PATH_TEST_POST /* "/test" */], consumes = ["application/json"] ) - fun testPost(@Parameter(description = "", required = true) @Valid @RequestBody apa: Apa): ResponseEntity { + fun testPost( + @Parameter(description = "", required = true) @Valid @RequestBody apa: Apa + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "" + const val PATH_TEST_POST: String = "/test" + } } diff --git a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/PetApi.kt b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/PetApi.kt index 792572559201..f73b78ead9f5 100644 --- a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/PetApi.kt +++ b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/PetApi.kt @@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.PetApi.Companion.BASE_PATH import jakarta.validation.constraints.DecimalMax import jakarta.validation.constraints.DecimalMin @@ -36,7 +37,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") interface PetApi { fun getDelegate(): PetApiDelegate @@ -53,12 +54,14 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet"], - produces = ["application/xml", "application/json"], - consumes = ["application/json", "application/xml"] - ) - fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + method = [RequestMethod.POST], + value = [PATH_ADD_PET /* "/pet" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json", "application/xml"] + ) + fun addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return getDelegate().addPet(pet) } @@ -73,10 +76,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return getDelegate().deletePet(petId, apiKey) } @@ -92,11 +98,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByStatus"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], + produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return getDelegate().findPetsByStatus(status) } @@ -112,11 +120,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByTags"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], + produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return getDelegate().findPetsByTags(tags) } @@ -133,11 +143,13 @@ interface PetApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/{petId}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], + produces = ["application/xml", "application/json"] ) - fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return getDelegate().getPetById(petId) } @@ -155,12 +167,14 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.PUT], - value = ["/pet"], - produces = ["application/xml", "application/json"], - consumes = ["application/json", "application/xml"] - ) - fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + method = [RequestMethod.PUT], + value = [PATH_UPDATE_PET /* "/pet" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json", "application/xml"] + ) + fun updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return getDelegate().updatePet(pet) } @@ -175,11 +189,15 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}"], - consumes = ["application/x-www-form-urlencoded"] - ) - fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + method = [RequestMethod.POST], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], + consumes = ["application/x-www-form-urlencoded"] + ) + fun updatePetWithForm( + @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return getDelegate().updatePetWithForm(petId, name, status) } @@ -194,12 +212,29 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], - produces = ["application/json"], - consumes = ["multipart/form-data"] - ) - fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + method = [RequestMethod.POST], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], + produces = ["application/json"], + consumes = ["multipart/form-data"] + ) + fun uploadFile( + @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return getDelegate().uploadFile(petId, additionalMetadata, file) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/StoreApi.kt b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/StoreApi.kt index 11108f5c6535..0f641951b643 100644 --- a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/StoreApi.kt +++ b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/StoreApi.kt @@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.StoreApi.Companion.BASE_PATH import jakarta.validation.constraints.DecimalMax import jakarta.validation.constraints.DecimalMin @@ -35,7 +36,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") interface StoreApi { fun getDelegate(): StoreApiDelegate @@ -51,10 +52,12 @@ interface StoreApi { ] ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return getDelegate().deleteOrder(orderId) } @@ -69,9 +72,9 @@ interface StoreApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/inventory"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], + produces = ["application/json"] ) fun getInventory(): ResponseEntity> { return getDelegate().getInventory() @@ -89,11 +92,13 @@ interface StoreApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], + produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return getDelegate().getOrderById(orderId) } @@ -108,12 +113,23 @@ interface StoreApi { ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/store/order"], - produces = ["application/xml", "application/json"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_PLACE_ORDER /* "/store/order" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json"] ) - fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order): ResponseEntity { + fun placeOrder( + @Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order + ): ResponseEntity { return getDelegate().placeOrder(order) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/UserApi.kt b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/UserApi.kt index 76b48c1ec0ae..33e2afdd2903 100644 --- a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/UserApi.kt +++ b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/api/UserApi.kt @@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.UserApi.Companion.BASE_PATH import jakarta.validation.constraints.DecimalMax import jakarta.validation.constraints.DecimalMin @@ -35,7 +36,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") interface UserApi { fun getDelegate(): UserApiDelegate @@ -51,11 +52,13 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USER /* "/user" */], + consumes = ["application/json"] ) - fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + fun createUser( + @Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return getDelegate().createUser(user) } @@ -70,11 +73,13 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithArray"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], + consumes = ["application/json"] ) - fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return getDelegate().createUsersWithArrayInput(user) } @@ -89,11 +94,13 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithList"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], + consumes = ["application/json"] ) - fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return getDelegate().createUsersWithListInput(user) } @@ -109,10 +116,12 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/user/{username}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return getDelegate().deleteUser(username) } @@ -128,11 +137,13 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/{username}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], + produces = ["application/xml", "application/json"] ) - fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return getDelegate().getUserByName(username) } @@ -147,11 +158,14 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/login"], - produces = ["application/xml", "application/json"] - ) - fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + method = [RequestMethod.GET], + value = [PATH_LOGIN_USER /* "/user/login" */], + produces = ["application/xml", "application/json"] + ) + fun loginUser( + @NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return getDelegate().loginUser(username, password) } @@ -166,8 +180,8 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/logout"] + method = [RequestMethod.GET], + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return getDelegate().logoutUser() @@ -185,11 +199,27 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.PUT], - value = ["/user/{username}"], - consumes = ["application/json"] - ) - fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + method = [RequestMethod.PUT], + value = [PATH_UPDATE_USER /* "/user/{username}" */], + consumes = ["application/json"] + ) + fun updateUser( + @Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String, + @Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return getDelegate().updateUser(username, user) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt index 3816bc65b78b..5c4a858ad524 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt @@ -52,12 +52,14 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet"], - produces = ["application/xml", "application/json"], - consumes = ["application/json", "application/xml"] - ) - fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + method = [RequestMethod.POST], + value = [PATH_ADD_PET /* "/pet" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json", "application/xml"] + ) + fun addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return getDelegate().addPet(pet) } @@ -72,10 +74,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return getDelegate().deletePet(petId, apiKey) } @@ -91,11 +96,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByStatus"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], + produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return getDelegate().findPetsByStatus(status) } @@ -111,11 +118,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByTags"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], + produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return getDelegate().findPetsByTags(tags) } @@ -132,11 +141,13 @@ interface PetApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/{petId}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], + produces = ["application/xml", "application/json"] ) - fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return getDelegate().getPetById(petId) } @@ -154,12 +165,14 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.PUT], - value = ["/pet"], - produces = ["application/xml", "application/json"], - consumes = ["application/json", "application/xml"] - ) - fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + method = [RequestMethod.PUT], + value = [PATH_UPDATE_PET /* "/pet" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json", "application/xml"] + ) + fun updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return getDelegate().updatePet(pet) } @@ -174,11 +187,15 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}"], - consumes = ["application/x-www-form-urlencoded"] - ) - fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + method = [RequestMethod.POST], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], + consumes = ["application/x-www-form-urlencoded"] + ) + fun updatePetWithForm( + @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return getDelegate().updatePetWithForm(petId, name, status) } @@ -193,12 +210,28 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], - produces = ["application/json"], - consumes = ["multipart/form-data"] - ) - fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + method = [RequestMethod.POST], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], + produces = ["application/json"], + consumes = ["multipart/form-data"] + ) + fun uploadFile( + @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return getDelegate().uploadFile(petId, additionalMetadata, file) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt index 6cd8dc53a457..6affe35e7bf6 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt @@ -50,10 +50,12 @@ interface StoreApi { ] ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return getDelegate().deleteOrder(orderId) } @@ -68,9 +70,9 @@ interface StoreApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/inventory"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], + produces = ["application/json"] ) fun getInventory(): ResponseEntity> { return getDelegate().getInventory() @@ -88,11 +90,13 @@ interface StoreApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], + produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return getDelegate().getOrderById(orderId) } @@ -107,12 +111,22 @@ interface StoreApi { ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/store/order"], - produces = ["application/xml", "application/json"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_PLACE_ORDER /* "/store/order" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json"] ) - fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order): ResponseEntity { + fun placeOrder( + @Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order + ): ResponseEntity { return getDelegate().placeOrder(order) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt index 81391593ab86..55d7c2558785 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt @@ -50,11 +50,13 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USER /* "/user" */], + consumes = ["application/json"] ) - fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + fun createUser( + @Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return getDelegate().createUser(user) } @@ -69,11 +71,13 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithArray"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], + consumes = ["application/json"] ) - fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return getDelegate().createUsersWithArrayInput(user) } @@ -88,11 +92,13 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithList"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], + consumes = ["application/json"] ) - fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return getDelegate().createUsersWithListInput(user) } @@ -108,10 +114,12 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/user/{username}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return getDelegate().deleteUser(username) } @@ -127,11 +135,13 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/{username}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], + produces = ["application/xml", "application/json"] ) - fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return getDelegate().getUserByName(username) } @@ -146,11 +156,14 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/login"], - produces = ["application/xml", "application/json"] - ) - fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + method = [RequestMethod.GET], + value = [PATH_LOGIN_USER /* "/user/login" */], + produces = ["application/xml", "application/json"] + ) + fun loginUser( + @NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return getDelegate().loginUser(username, password) } @@ -165,8 +178,8 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/logout"] + method = [RequestMethod.GET], + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return getDelegate().logoutUser() @@ -184,11 +197,26 @@ interface UserApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.PUT], - value = ["/user/{username}"], - consumes = ["application/json"] - ) - fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + method = [RequestMethod.PUT], + value = [PATH_UPDATE_USER /* "/user/{username}" */], + consumes = ["application/json"] + ) + fun updateUser( + @Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String, + @Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return getDelegate().updateUser(username, user) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt index a5484ab149dd..04baf319ae2d 100644 --- a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt +++ b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt @@ -49,15 +49,20 @@ interface PetApi { value = "Add a new pet to the store", nickname = "addPet", notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + value = [ApiResponse(code = 405, message = "Invalid input")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_ADD_PET /* "/pet" */], + consumes = ["application/json"] ) - suspend fun addPet(@ApiParam(value = "", required = true) @Valid @RequestBody pet: Pet, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun addPet( + @ApiParam(value = "", required = true) @Valid @RequestBody pet: Pet, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().addPet(pet, exchange) } @@ -66,14 +71,20 @@ interface PetApi { value = "Deletes a pet", nickname = "deletePet", notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid pet value")]) + value = [ApiResponse(code = 400, message = "Invalid pet value")] + ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - suspend fun deletePet(@ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "") @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun deletePet( + @ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "") @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().deletePet(petId, apiKey, exchange) } @@ -84,15 +95,20 @@ interface PetApi { notes = "Multiple status values can be provided with comma separated strings", response = Pet::class, responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"), ApiResponse(code = 400, message = "Invalid status value")]) + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"), ApiResponse(code = 400, message = "Invalid status value")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByStatus"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], + produces = ["application/json"] ) - fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity> { + fun findPetsByStatus( + @NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity> { return getDelegate().findPetsByStatus(status, exchange) } @@ -103,15 +119,20 @@ interface PetApi { notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet::class, responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"), ApiResponse(code = 400, message = "Invalid tag value")]) + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"), ApiResponse(code = 400, message = "Invalid tag value")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByTags"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], + produces = ["application/json"] ) - fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity> { + fun findPetsByTags( + @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity> { return getDelegate().findPetsByTags(tags, exchange) } @@ -121,15 +142,20 @@ interface PetApi { nickname = "getPetById", notes = "Returns a single pet", response = Pet::class, - authorizations = [Authorization(value = "api_key")]) + authorizations = [Authorization(value = "api_key")] + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class), ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Pet not found")]) + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class), ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Pet not found")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/{petId}"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], + produces = ["application/json"] ) - suspend fun getPetById(@ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun getPetById( + @ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().getPetById(petId, exchange) } @@ -138,15 +164,20 @@ interface PetApi { value = "Update an existing pet", nickname = "updatePet", notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Pet not found"), ApiResponse(code = 405, message = "Validation exception")]) + value = [ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Pet not found"), ApiResponse(code = 405, message = "Validation exception")] + ) @RequestMapping( - method = [RequestMethod.PUT], - value = ["/pet"], - consumes = ["application/json"] + method = [RequestMethod.PUT], + value = [PATH_UPDATE_PET /* "/pet" */], + consumes = ["application/json"] ) - suspend fun updatePet(@ApiParam(value = "", required = true) @Valid @RequestBody pet: Pet, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun updatePet( + @ApiParam(value = "", required = true) @Valid @RequestBody pet: Pet, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().updatePet(pet, exchange) } @@ -155,15 +186,22 @@ interface PetApi { value = "Updates a pet in the store with form data", nickname = "updatePetWithForm", notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + value = [ApiResponse(code = 405, message = "Invalid input")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}"], - consumes = ["application/x-www-form-urlencoded"] + method = [RequestMethod.POST], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], + consumes = ["application/x-www-form-urlencoded"] ) - suspend fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@ApiParam(value = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? , @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun updatePetWithForm( + @ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @ApiParam(value = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String?, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().updatePetWithForm(petId, name, status, exchange) } @@ -173,16 +211,35 @@ interface PetApi { nickname = "uploadFile", notes = "", response = ModelApiResponse::class, - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) + value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], - produces = ["application/json"], - consumes = ["multipart/form-data"] + method = [RequestMethod.POST], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], + produces = ["application/json"], + consumes = ["multipart/form-data"] ) - suspend fun uploadFile(@ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@ApiParam(value = "file detail") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun uploadFile( + @ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @ApiParam(value = "file detail") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().uploadFile(petId, additionalMetadata, file, exchange) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt index 8b42f54741f0..8557e4fc88ca 100644 --- a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt +++ b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt @@ -47,14 +47,19 @@ interface StoreApi { @ApiOperation( value = "Delete purchase order by ID", nickname = "deleteOrder", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Order not found")]) + value = [ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Order not found")] + ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - suspend fun deleteOrder(@ApiParam(value = "", required = true) @PathVariable("orderId") orderId: kotlin.String, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun deleteOrder( + @ApiParam(value = "", required = true) @PathVariable("orderId") orderId: kotlin.String, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().deleteOrder(orderId, exchange) } @@ -65,13 +70,15 @@ interface StoreApi { notes = "", response = kotlin.Int::class, responseContainer = "Map", - authorizations = [Authorization(value = "api_key")]) + authorizations = [Authorization(value = "api_key")] + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")]) + value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/inventory"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], + produces = ["application/json"] ) suspend fun getInventory(@ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity> { return getDelegate().getInventory(exchange) @@ -82,15 +89,20 @@ interface StoreApi { value = "Find purchase order by ID", nickname = "getOrderById", notes = "", - response = Order::class) + response = Order::class + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class), ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Order not found")]) + value = [ApiResponse(code = 200, message = "successful operation", response = Order::class), ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Order not found")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], + produces = ["application/json"] ) - suspend fun getOrderById(@Min(value=1) @Max(value=5) @ApiParam(value = "", required = true) @PathVariable("orderId") orderId: kotlin.Int, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun getOrderById( + @Min(value=1) @Max(value=5) @ApiParam(value = "", required = true) @PathVariable("orderId") orderId: kotlin.Int, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().getOrderById(orderId, exchange) } @@ -99,16 +111,29 @@ interface StoreApi { value = "Place an order for a pet", nickname = "placeOrder", notes = "", - response = Order::class) + response = Order::class + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class), ApiResponse(code = 400, message = "Invalid Order")]) + value = [ApiResponse(code = 200, message = "successful operation", response = Order::class), ApiResponse(code = 400, message = "Invalid Order")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/store/order"], - produces = ["application/json"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_PLACE_ORDER /* "/store/order" */], + produces = ["application/json"], + consumes = ["application/json"] ) - suspend fun placeOrder(@ApiParam(value = "", required = true) @Valid @RequestBody order: Order, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun placeOrder( + @ApiParam(value = "", required = true) @Valid @RequestBody order: Order, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().placeOrder(order, exchange) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt index 8cddc539266b..30c0c32f527d 100644 --- a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt +++ b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt @@ -47,15 +47,20 @@ interface UserApi { @ApiOperation( value = "Create user", nickname = "createUser", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + value = [ApiResponse(code = 200, message = "successful operation")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USER /* "/user" */], + consumes = ["application/json"] ) - suspend fun createUser(@ApiParam(value = "", required = true) @Valid @RequestBody user: User, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun createUser( + @ApiParam(value = "", required = true) @Valid @RequestBody user: User, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().createUser(user, exchange) } @@ -63,15 +68,20 @@ interface UserApi { @ApiOperation( value = "Creates list of users with given input array", nickname = "createUsersWithArrayInput", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + value = [ApiResponse(code = 200, message = "successful operation")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithArray"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], + consumes = ["application/json"] ) - suspend fun createUsersWithArrayInput(@ApiParam(value = "", required = true) @Valid @RequestBody user: Flow, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun createUsersWithArrayInput( + @ApiParam(value = "", required = true) @Valid @RequestBody user: Flow, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().createUsersWithArrayInput(user, exchange) } @@ -79,15 +89,20 @@ interface UserApi { @ApiOperation( value = "Creates list of users with given input array", nickname = "createUsersWithListInput", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + value = [ApiResponse(code = 200, message = "successful operation")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithList"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], + consumes = ["application/json"] ) - suspend fun createUsersWithListInput(@ApiParam(value = "", required = true) @Valid @RequestBody user: Flow, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun createUsersWithListInput( + @ApiParam(value = "", required = true) @Valid @RequestBody user: Flow, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().createUsersWithListInput(user, exchange) } @@ -95,14 +110,19 @@ interface UserApi { @ApiOperation( value = "Delete user", nickname = "deleteUser", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid username supplied"), ApiResponse(code = 404, message = "User not found")]) + value = [ApiResponse(code = 400, message = "Invalid username supplied"), ApiResponse(code = 404, message = "User not found")] + ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/user/{username}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - suspend fun deleteUser(@ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun deleteUser( + @ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().deleteUser(username, exchange) } @@ -111,15 +131,20 @@ interface UserApi { value = "Get user by user name", nickname = "getUserByName", notes = "", - response = User::class) + response = User::class + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = User::class), ApiResponse(code = 400, message = "Invalid username supplied"), ApiResponse(code = 404, message = "User not found")]) + value = [ApiResponse(code = 200, message = "successful operation", response = User::class), ApiResponse(code = 400, message = "Invalid username supplied"), ApiResponse(code = 404, message = "User not found")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/{username}"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], + produces = ["application/json"] ) - suspend fun getUserByName(@ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun getUserByName( + @ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().getUserByName(username, exchange) } @@ -128,15 +153,21 @@ interface UserApi { value = "Logs user into the system", nickname = "loginUser", notes = "", - response = kotlin.String::class) + response = kotlin.String::class + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class), ApiResponse(code = 400, message = "Invalid username/password supplied")]) + value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class), ApiResponse(code = 400, message = "Invalid username/password supplied")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/login"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_LOGIN_USER /* "/user/login" */], + produces = ["application/json"] ) - suspend fun loginUser(@NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun loginUser( + @NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().loginUser(username, password, exchange) } @@ -144,12 +175,14 @@ interface UserApi { @ApiOperation( value = "Logs out current logged in user session", nickname = "logoutUser", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + value = [ApiResponse(code = 200, message = "successful operation")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/logout"] + method = [RequestMethod.GET], + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) suspend fun logoutUser(@ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { return getDelegate().logoutUser(exchange) @@ -159,15 +192,33 @@ interface UserApi { @ApiOperation( value = "Updated user", nickname = "updateUser", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid user supplied"), ApiResponse(code = 404, message = "User not found")]) + value = [ApiResponse(code = 400, message = "Invalid user supplied"), ApiResponse(code = 404, message = "User not found")] + ) @RequestMapping( - method = [RequestMethod.PUT], - value = ["/user/{username}"], - consumes = ["application/json"] + method = [RequestMethod.PUT], + value = [PATH_UPDATE_USER /* "/user/{username}" */], + consumes = ["application/json"] ) - suspend fun updateUser(@ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String,@ApiParam(value = "", required = true) @Valid @RequestBody user: User, @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange): ResponseEntity { + suspend fun updateUser( + @ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String, + @ApiParam(value = "", required = true) @Valid @RequestBody user: User, + @ApiParam(hidden = true) exchange: org.springframework.web.server.ServerWebExchange + ): ResponseEntity { return getDelegate().updateUser(username, user, exchange) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/DefaultApi.kt b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/DefaultApi.kt index af1f1ebefb90..3aa911897301 100644 --- a/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/DefaultApi.kt +++ b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/DefaultApi.kt @@ -34,9 +34,14 @@ interface DefaultApi { @RequestMapping( - method = [RequestMethod.GET], - value = ["/healthcheck"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_HEALTHCHECK /* "/healthcheck" */], + produces = ["application/json"] ) fun healthcheck(): ResponseEntity + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_HEALTHCHECK: String = "/healthcheck" + } } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/PetApiController.kt index d227b75281a7..f13355fca1df 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.PetApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -31,7 +32,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class PetApiController(@Autowired(required = true) val service: PetApiService) { @Operation( @@ -44,10 +45,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet"], + value = [PATH_ADD_PET /* "/pet" */], consumes = ["application/json", "application/xml"] ) - fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + fun addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet + ): ResponseEntity { return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) } @@ -61,9 +64,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) } @@ -78,10 +84,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByStatus"], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) } @@ -96,10 +104,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByTags"], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) } @@ -115,10 +125,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/{petId}"], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], produces = ["application/xml", "application/json"] ) - fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } @@ -134,10 +146,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/pet"], + value = [PATH_UPDATE_PET /* "/pet" */], consumes = ["application/json", "application/xml"] ) - fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + fun updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet + ): ResponseEntity { return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) } @@ -151,10 +165,14 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}"], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + fun updatePetWithForm( + @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) } @@ -168,11 +186,28 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], produces = ["application/json"], consumes = ["multipart/form-data"] ) - fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + fun uploadFile( + @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/StoreApiController.kt index a74a81d00667..d2afc77e43ae 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.StoreApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -30,7 +31,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class StoreApiController(@Autowired(required = true) val service: StoreApiService) { @Operation( @@ -43,9 +44,11 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } @@ -59,7 +62,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/inventory"], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], produces = ["application/json"] ) fun getInventory(): ResponseEntity> { @@ -77,10 +80,12 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) } @@ -94,10 +99,21 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.POST], - value = ["/store/order"], + value = [PATH_PLACE_ORDER /* "/store/order" */], produces = ["application/xml", "application/json"] ) - fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order): ResponseEntity { + fun placeOrder( + @Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order + ): ResponseEntity { return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/UserApiController.kt index 08160bfaf0fc..9ed8632dd6a3 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.UserApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -30,7 +31,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class UserApiController(@Autowired(required = true) val service: UserApiService) { @Operation( @@ -42,9 +43,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user"] + value = [PATH_CREATE_USER /* "/user" */] ) - fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + fun createUser( + @Parameter(description = "Created user object", required = true) @Valid @RequestBody body: User + ): ResponseEntity { return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) } @@ -57,9 +60,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithArray"] + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */] ) - fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) } @@ -72,9 +77,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithList"] + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */] ) - fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) } @@ -88,9 +95,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/user/{username}"] + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } @@ -105,10 +114,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/{username}"], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], produces = ["application/xml", "application/json"] ) - fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } @@ -122,10 +133,13 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/login"], + value = [PATH_LOGIN_USER /* "/user/login" */], produces = ["application/xml", "application/json"] ) - fun loginUser(@NotNull @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + fun loginUser( + @NotNull @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } @@ -138,7 +152,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/logout"] + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) @@ -154,9 +168,25 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/user/{username}"] + value = [PATH_UPDATE_USER /* "/user/{username}" */] ) - fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + fun updateUser( + @Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String, + @Parameter(description = "Updated user object", required = true) @Valid @RequestBody body: User + ): ResponseEntity { return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-multipart-request-model/src/main/kotlin/org/openapitools/api/MultipartMixedApiController.kt b/samples/server/petstore/kotlin-springboot-multipart-request-model/src/main/kotlin/org/openapitools/api/MultipartMixedApiController.kt index 2934906f7d74..3f72f772f189 100644 --- a/samples/server/petstore/kotlin-springboot-multipart-request-model/src/main/kotlin/org/openapitools/api/MultipartMixedApiController.kt +++ b/samples/server/petstore/kotlin-springboot-multipart-request-model/src/main/kotlin/org/openapitools/api/MultipartMixedApiController.kt @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.MultipartMixedApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -31,7 +32,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:}") +@RequestMapping("\${api.multipartFileTest.base-path:api.base-path:$BASE_PATH}") class MultipartMixedApiController() { @Operation( @@ -43,10 +44,20 @@ class MultipartMixedApiController() { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/multipart-mixed"], + value = [PATH_MULTIPART_MIXED /* "/multipart-mixed" */], consumes = ["multipart/form-data"] ) - fun multipartMixed(@Parameter(description = "", required = true, schema = Schema(allowableValues = ["ALLOWED", "IN_PROGRESS", "REJECTED"])) @Valid @RequestParam(value = "status", required = true) status: MultipartMixedStatus ,@Parameter(description = "a file") @Valid @RequestPart("file", required = true) file: org.springframework.web.multipart.MultipartFile,@Parameter(description = "") @Valid @RequestPart(value = "marker", required = false) marker: MultipartMixedRequestMarker? ): ResponseEntity { + fun multipartMixed( + @Parameter(description = "", required = true, schema = Schema(allowableValues = ["ALLOWED", "IN_PROGRESS", "REJECTED"])) @Valid @RequestParam(value = "status", required = true) status: MultipartMixedStatus, + @Parameter(description = "a file") @Valid @RequestPart("file", required = true) file: org.springframework.web.multipart.MultipartFile, + @Parameter(description = "") @Valid @RequestPart(value = "marker", required = false) marker: MultipartMixedRequestMarker? + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "" + const val PATH_MULTIPART_MIXED: String = "/multipart-mixed" + } } diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/.openapi-generator-ignore b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/.openapi-generator/FILES new file mode 100644 index 000000000000..e69adb786fa0 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/.openapi-generator/FILES @@ -0,0 +1,33 @@ +README.md +build.gradle.kts +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +pom.xml +settings.gradle +src/main/kotlin/org/openapitools/Application.kt +src/main/kotlin/org/openapitools/api/ApiUtil.kt +src/main/kotlin/org/openapitools/api/Exceptions.kt +src/main/kotlin/org/openapitools/api/PetApi.kt +src/main/kotlin/org/openapitools/api/PetApiController.kt +src/main/kotlin/org/openapitools/api/PetApiDelegate.kt +src/main/kotlin/org/openapitools/api/PetApiService.kt +src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/StoreApi.kt +src/main/kotlin/org/openapitools/api/StoreApiController.kt +src/main/kotlin/org/openapitools/api/StoreApiDelegate.kt +src/main/kotlin/org/openapitools/api/StoreApiService.kt +src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/UserApi.kt +src/main/kotlin/org/openapitools/api/UserApiController.kt +src/main/kotlin/org/openapitools/api/UserApiDelegate.kt +src/main/kotlin/org/openapitools/api/UserApiService.kt +src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt +src/main/kotlin/org/openapitools/model/Category.kt +src/main/kotlin/org/openapitools/model/ModelApiResponse.kt +src/main/kotlin/org/openapitools/model/Order.kt +src/main/kotlin/org/openapitools/model/Pet.kt +src/main/kotlin/org/openapitools/model/Tag.kt +src/main/kotlin/org/openapitools/model/User.kt +src/main/resources/application.yaml diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/.openapi-generator/VERSION b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/.openapi-generator/VERSION new file mode 100644 index 000000000000..2fb556b60635 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.18.0-SNAPSHOT diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/README.md b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/README.md new file mode 100644 index 000000000000..b6865a081135 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/README.md @@ -0,0 +1,21 @@ +# openAPIPetstore + +This Kotlin based [Spring Boot](https://spring.io/projects/spring-boot) application has been generated using the [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator). + +## Getting Started + +This document assumes you have either maven or gradle available, either via the wrapper or otherwise. This does not come with a gradle / maven wrapper checked in. + +By default a [`pom.xml`](pom.xml) file will be generated. If you specified `gradleBuildFile=true` when generating this project, a `build.gradle.kts` will also be generated. Note this uses [Gradle Kotlin DSL](https://github.com/gradle/kotlin-dsl). + +To build the project using maven, run: +```bash +mvn package && java -jar target/openapi-spring-1.0.0.jar +``` + +To build the project using gradle, run: +```bash +gradle build && java -jar build/libs/openapi-spring-1.0.0.jar +``` + +If all builds successfully, the server should run on [http://localhost:8080/](http://localhost:8080/) diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/build.gradle.kts b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/build.gradle.kts new file mode 100644 index 000000000000..3507e44d515a --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/build.gradle.kts @@ -0,0 +1,48 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.7") + } +} + +group = "org.openapitools" +version = "1.0.0" + +repositories { + mavenCentral() +} + +tasks.withType { + kotlinOptions.jvmTarget = "11" +} + +plugins { + val kotlinVersion = "1.9.25" + id("org.jetbrains.kotlin.jvm") version kotlinVersion + id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion + id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion + id("org.springframework.boot") version "2.6.7" + id("io.spring.dependency-management") version "1.0.11.RELEASE" +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.springframework.boot:spring-boot-starter-web") + + implementation("com.google.code.findbugs:jsr305:3.0.2") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + implementation("javax.validation:validation-api") + implementation("javax.annotation:javax.annotation-api:1.3.2") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") + testImplementation("org.springframework.boot:spring-boot-starter-test") { + exclude(module = "junit") + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradle/wrapper/gradle-wrapper.jar b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..e6441136f3d4 Binary files /dev/null and b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..80187ac30432 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradlew b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradlew new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while +APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path +[ -h "$app_path" ] +do +ls=$( ls -ld "$app_path" ) +link=${ls#*' -> '} +case $link in #( +/*) app_path=$link ;; #( +*) app_path=$APP_HOME$link ;; +esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { +echo "$*" +} >&2 + +die () { +echo +echo "$*" +echo +exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( +CYGWIN* ) cygwin=true ;; #( +Darwin* ) darwin=true ;; #( +MSYS* | MINGW* ) msys=true ;; #( +NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then +if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +# IBM's JDK on AIX uses strange locations for the executables +JAVACMD=$JAVA_HOME/jre/sh/java +else +JAVACMD=$JAVA_HOME/bin/java +fi +if [ ! -x "$JAVACMD" ] ; then +die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +else +JAVACMD=java +if ! command -v java >/dev/null 2>&1 +then +die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then +case $MAX_FD in #( +max*) +# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +MAX_FD=$( ulimit -H -n ) || +warn "Could not query maximum file descriptor limit" +esac +case $MAX_FD in #( +'' | soft) :;; #( +*) +# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +ulimit -n "$MAX_FD" || +warn "Could not set maximum file descriptor limit to $MAX_FD" +esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then +APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) +CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + +JAVACMD=$( cygpath --unix "$JAVACMD" ) + +# Now convert the arguments - kludge to limit ourselves to /bin/sh +for arg do +if +case $arg in #( +-*) false ;; # don't mess with options #( +/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath +[ -e "$t" ] ;; #( +*) false ;; +esac +then +arg=$( cygpath --path --ignore --mixed "$arg" ) +fi +# Roll the args list around exactly as many times as the number of +# args, so each arg winds up back in the position where it started, but +# possibly modified. +# +# NB: a `for` loop captures its iteration list before it begins, so +# changing the positional parameters here affects neither the number of +# iterations, nor the values presented in `arg`. +shift # remove old arg +set -- "$@" "$arg" # push replacement arg +done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ +"-Dorg.gradle.appname=$APP_BASE_NAME" \ +-classpath "$CLASSPATH" \ +org.gradle.wrapper.GradleWrapperMain \ +"$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then +die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( +printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | +xargs -n1 | +sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | +tr '\n' ' ' +)" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradlew.bat b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradlew.bat new file mode 100644 index 000000000000..25da30dbdeee --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/pom.xml b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/pom.xml new file mode 100644 index 000000000000..cab717f26a33 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/pom.xml @@ -0,0 +1,131 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 3.0.2 + 1.3.2 + 1.6.21 + + 1.6.21 + UTF-8 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.15 + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + spring + + 11 + + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + + + org.springframework.boot + spring-boot-starter-web + + + + + + + com.google.code.findbugs + jsr305 + ${findbugs-jsr305.version} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + javax.validation + validation-api + + + javax.annotation + javax.annotation-api + ${javax-annotation.version} + provided + + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin-test-junit5.version} + test + + + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/settings.gradle b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/settings.gradle new file mode 100644 index 000000000000..14844905cd40 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + maven { url = uri("https://repo.spring.io/snapshot") } + maven { url = uri("https://repo.spring.io/milestone") } + gradlePluginPortal() + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "org.springframework.boot") { + useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}") + } + } + } +} +rootProject.name = "openapi-spring" diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/Application.kt new file mode 100644 index 000000000000..2fe6de62479e --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/Application.kt @@ -0,0 +1,13 @@ +package org.openapitools + +import org.springframework.boot.runApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.context.annotation.ComponentScan + +@SpringBootApplication +@ComponentScan(basePackages = ["org.openapitools", "org.openapitools.api", "org.openapitools.model"]) +class Application + +fun main(args: Array) { + runApplication(*args) +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 000000000000..88e892d0f49a --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,19 @@ +package org.openapitools.api + +import org.springframework.web.context.request.NativeWebRequest + +import javax.servlet.http.HttpServletResponse +import java.io.IOException + +object ApiUtil { + fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { + try { + val res = req.getNativeResponse(HttpServletResponse::class.java) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) + } catch (e: IOException) { + throw RuntimeException(e) + } + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/Exceptions.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/Exceptions.kt new file mode 100644 index 000000000000..901db1237ee7 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/Exceptions.kt @@ -0,0 +1,30 @@ +package org.openapitools.api + +import org.springframework.context.annotation.Configuration +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.bind.annotation.ExceptionHandler +import javax.servlet.http.HttpServletResponse +import javax.validation.ConstraintViolationException + +// TODO Extend ApiException for custom exception handling, e.g. the below NotFound exception +sealed class ApiException(msg: String, val code: Int) : Exception(msg) + +class NotFoundException(msg: String, code: Int = HttpStatus.NOT_FOUND.value()) : ApiException(msg, code) + +@Configuration("org.openapitools.api.DefaultExceptionHandler") +@ControllerAdvice +class DefaultExceptionHandler { + + @ExceptionHandler(value = [ApiException::class]) + fun onApiException(ex: ApiException, response: HttpServletResponse): Unit = + response.sendError(ex.code, ex.message) + + @ExceptionHandler(value = [NotImplementedError::class]) + fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.NOT_IMPLEMENTED.value()) + + @ExceptionHandler(value = [ConstraintViolationException::class]) + fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message }) +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt new file mode 100644 index 000000000000..bed8de60b2a8 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt @@ -0,0 +1,149 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.18.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface PetApi { + + fun getDelegate(): PetApiDelegate = object: PetApiDelegate {} + + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_ADD_PET /* "/pet" */], + consumes = ["application/json", "application/xml"] + ) + fun addPet( + @Valid @RequestBody body: Pet + ): Unit { + return getDelegate().addPet(body) + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @RequestMapping( + method = [RequestMethod.DELETE], + value = [PATH_DELETE_PET /* "/pet/{petId}" */] + ) + fun deletePet( + @PathVariable("petId") petId: kotlin.Long, + @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): Unit { + return getDelegate().deletePet(petId, apiKey) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], + produces = ["application/xml", "application/json"] + ) + fun findPetsByStatus( + @NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): List { + return getDelegate().findPetsByStatus(status) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], + produces = ["application/xml", "application/json"] + ) + fun findPetsByTags( + @NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): List { + return getDelegate().findPetsByTags(tags) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], + produces = ["application/xml", "application/json"] + ) + fun getPetById( + @PathVariable("petId") petId: kotlin.Long + ): Pet { + return getDelegate().getPetById(petId) + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @RequestMapping( + method = [RequestMethod.PUT], + value = [PATH_UPDATE_PET /* "/pet" */], + consumes = ["application/json", "application/xml"] + ) + fun updatePet( + @Valid @RequestBody body: Pet + ): Unit { + return getDelegate().updatePet(body) + } + + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], + consumes = ["application/x-www-form-urlencoded"] + ) + fun updatePetWithForm( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): Unit { + return getDelegate().updatePetWithForm(petId, name, status) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], + produces = ["application/json"], + consumes = ["multipart/form-data"] + ) + fun uploadFile( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ModelApiResponse { + return getDelegate().uploadFile(petId, additionalMetadata, file) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiController.kt new file mode 100644 index 000000000000..bda17886a9fb --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -0,0 +1,20 @@ +package org.openapitools.api + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import java.util.Optional + +@javax.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.18.0-SNAPSHOT") +@Controller +@RequestMapping("\${openapi.openAPIPetstore.base-path:/v2}") +class PetApiController( + delegate: PetApiDelegate? +) : PetApi { + private lateinit var delegate: PetApiDelegate + + init { + this.delegate = Optional.ofNullable(delegate).orElse(object : PetApiDelegate {}) + } + + override fun getDelegate(): PetApiDelegate = delegate +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiDelegate.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiDelegate.kt new file mode 100644 index 000000000000..a96a547cf8b0 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiDelegate.kt @@ -0,0 +1,140 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.web.context.request.NativeWebRequest + +import java.util.Optional + +/** + * A delegate to be called by the {@link PetApiController}}. + * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class. + */ +@javax.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.18.0-SNAPSHOT") +interface PetApiDelegate { + + fun getRequest(): Optional = Optional.empty() + + /** + * @see PetApi#addPet + */ + fun addPet(body: Pet): Unit { + return TODO("Not yet implemented") + + } + + + /** + * @see PetApi#deletePet + */ + fun deletePet(petId: kotlin.Long, + apiKey: kotlin.String?): Unit { + return TODO("Not yet implemented") + + } + + + /** + * @see PetApi#findPetsByStatus + */ + fun findPetsByStatus(status: kotlin.collections.List): List { + getRequest().ifPresent { request -> + for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + ApiUtil.setExampleResponse(request, "application/json", "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"}, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"} ]") + break + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + ApiUtil.setExampleResponse(request, "application/xml", " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou") + break + } + } + } + return TODO("Not yet implemented") + + } + + + /** + * @see PetApi#findPetsByTags + */ + fun findPetsByTags(tags: kotlin.collections.List): List { + getRequest().ifPresent { request -> + for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + ApiUtil.setExampleResponse(request, "application/json", "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"}, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"} ]") + break + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + ApiUtil.setExampleResponse(request, "application/xml", " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou") + break + } + } + } + return TODO("Not yet implemented") + + } + + + /** + * @see PetApi#getPetById + */ + fun getPetById(petId: kotlin.Long): Pet { + getRequest().ifPresent { request -> + for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + ApiUtil.setExampleResponse(request, "application/json", "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\"}") + break + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + ApiUtil.setExampleResponse(request, "application/xml", " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou") + break + } + } + } + return TODO("Not yet implemented") + + } + + + /** + * @see PetApi#updatePet + */ + fun updatePet(body: Pet): Unit { + return TODO("Not yet implemented") + + } + + + /** + * @see PetApi#updatePetWithForm + */ + fun updatePetWithForm(petId: kotlin.Long, + name: kotlin.String?, + status: kotlin.String?): Unit { + return TODO("Not yet implemented") + + } + + + /** + * @see PetApi#uploadFile + */ + fun uploadFile(petId: kotlin.Long, + additionalMetadata: kotlin.String?, + file: org.springframework.web.multipart.MultipartFile): ModelApiResponse { + getRequest().ifPresent { request -> + for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + ApiUtil.setExampleResponse(request, "application/json", "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\"}") + break + } + } + } + return TODO("Not yet implemented") + + } + +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiService.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiService.kt new file mode 100644 index 000000000000..db655b8a7978 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiService.kt @@ -0,0 +1,94 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet + +interface PetApiService { + + /** + * POST /pet : Add a new pet to the store + * + * @param body Pet object that needs to be added to the store (required) + * @return Invalid input (status code 405) + * @see PetApi#addPet + */ + fun addPet(body: Pet): Unit + + /** + * DELETE /pet/{petId} : Deletes a pet + * + * @param petId Pet id to delete (required) + * @param apiKey (optional) + * @return Invalid pet value (status code 400) + * @see PetApi#deletePet + */ + fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit + + /** + * GET /pet/findByStatus : Finds Pets by status + * Multiple status values can be provided with comma separated strings + * + * @param status Status values that need to be considered for filter (required) + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + * @see PetApi#findPetsByStatus + */ + fun findPetsByStatus(status: kotlin.collections.List): List + + /** + * GET /pet/findByTags : Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * + * @param tags Tags to filter by (required) + * @return successful operation (status code 200) + * or Invalid tag value (status code 400) + * @deprecated + * @see PetApi#findPetsByTags + */ + fun findPetsByTags(tags: kotlin.collections.List): List + + /** + * GET /pet/{petId} : Find pet by ID + * Returns a single pet + * + * @param petId ID of pet to return (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * @see PetApi#getPetById + */ + fun getPetById(petId: kotlin.Long): Pet + + /** + * PUT /pet : Update an existing pet + * + * @param body Pet object that needs to be added to the store (required) + * @return Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * or Validation exception (status code 405) + * @see PetApi#updatePet + */ + fun updatePet(body: Pet): Unit + + /** + * POST /pet/{petId} : Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated (required) + * @param name Updated name of the pet (optional) + * @param status Updated status of the pet (optional) + * @return Invalid input (status code 405) + * @see PetApi#updatePetWithForm + */ + fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit + + /** + * POST /pet/{petId}/uploadImage : uploads an image + * + * @param petId ID of pet to update (required) + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return successful operation (status code 200) + * @see PetApi#uploadFile + */ + fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.web.multipart.MultipartFile): ModelApiResponse +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt new file mode 100644 index 000000000000..a48482be32bd --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt @@ -0,0 +1,40 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.springframework.stereotype.Service +@Service +class PetApiServiceImpl : PetApiService { + + override fun addPet(body: Pet): Unit { + TODO("Implement me") + } + + override fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun findPetsByStatus(status: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun findPetsByTags(tags: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun getPetById(petId: kotlin.Long): Pet { + TODO("Implement me") + } + + override fun updatePet(body: Pet): Unit { + TODO("Implement me") + } + + override fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.web.multipart.MultipartFile): ModelApiResponse { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt new file mode 100644 index 000000000000..832fecd5a166 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt @@ -0,0 +1,88 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.18.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.api + +import org.openapitools.model.Order +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface StoreApi { + + fun getDelegate(): StoreApiDelegate = object: StoreApiDelegate {} + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @RequestMapping( + method = [RequestMethod.DELETE], + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] + ) + fun deleteOrder( + @PathVariable("orderId") orderId: kotlin.String + ): Unit { + return getDelegate().deleteOrder(orderId) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], + produces = ["application/json"] + ) + fun getInventory(): Map { + return getDelegate().getInventory() + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], + produces = ["application/xml", "application/json"] + ) + fun getOrderById( + @Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long + ): Order { + return getDelegate().getOrderById(orderId) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_PLACE_ORDER /* "/store/order" */], + produces = ["application/xml", "application/json"] + ) + fun placeOrder( + @Valid @RequestBody body: Order + ): Order { + return getDelegate().placeOrder(body) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiController.kt new file mode 100644 index 000000000000..d716a4f9b76b --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -0,0 +1,20 @@ +package org.openapitools.api + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import java.util.Optional + +@javax.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.18.0-SNAPSHOT") +@Controller +@RequestMapping("\${openapi.openAPIPetstore.base-path:/v2}") +class StoreApiController( + delegate: StoreApiDelegate? +) : StoreApi { + private lateinit var delegate: StoreApiDelegate + + init { + this.delegate = Optional.ofNullable(delegate).orElse(object : StoreApiDelegate {}) + } + + override fun getDelegate(): StoreApiDelegate = delegate +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiDelegate.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiDelegate.kt new file mode 100644 index 000000000000..9c4233db165d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiDelegate.kt @@ -0,0 +1,78 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.web.context.request.NativeWebRequest + +import java.util.Optional + +/** + * A delegate to be called by the {@link StoreApiController}}. + * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class. + */ +@javax.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.18.0-SNAPSHOT") +interface StoreApiDelegate { + + fun getRequest(): Optional = Optional.empty() + + /** + * @see StoreApi#deleteOrder + */ + fun deleteOrder(orderId: kotlin.String): Unit { + return TODO("Not yet implemented") + + } + + + /** + * @see StoreApi#getInventory + */ + fun getInventory(): Map { + return TODO("Not yet implemented") + + } + + + /** + * @see StoreApi#getOrderById + */ + fun getOrderById(orderId: kotlin.Long): Order { + getRequest().ifPresent { request -> + for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + ApiUtil.setExampleResponse(request, "application/json", "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\"}") + break + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + ApiUtil.setExampleResponse(request, "application/xml", " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true") + break + } + } + } + return TODO("Not yet implemented") + + } + + + /** + * @see StoreApi#placeOrder + */ + fun placeOrder(body: Order): Order { + getRequest().ifPresent { request -> + for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + ApiUtil.setExampleResponse(request, "application/json", "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\"}") + break + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + ApiUtil.setExampleResponse(request, "application/xml", " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true") + break + } + } + } + return TODO("Not yet implemented") + + } + +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiService.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiService.kt new file mode 100644 index 000000000000..60e754529448 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiService.kt @@ -0,0 +1,48 @@ +package org.openapitools.api + +import org.openapitools.model.Order + +interface StoreApiService { + + /** + * DELETE /store/order/{orderId} : Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * + * @param orderId ID of the order that needs to be deleted (required) + * @return Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#deleteOrder + */ + fun deleteOrder(orderId: kotlin.String): Unit + + /** + * GET /store/inventory : Returns pet inventories by status + * Returns a map of status codes to quantities + * + * @return successful operation (status code 200) + * @see StoreApi#getInventory + */ + fun getInventory(): Map + + /** + * GET /store/order/{orderId} : Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions + * + * @param orderId ID of pet that needs to be fetched (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#getOrderById + */ + fun getOrderById(orderId: kotlin.Long): Order + + /** + * POST /store/order : Place an order for a pet + * + * @param body order placed for purchasing the pet (required) + * @return successful operation (status code 200) + * or Invalid Order (status code 400) + * @see StoreApi#placeOrder + */ + fun placeOrder(body: Order): Order +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt new file mode 100644 index 000000000000..7e733e28dc50 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt @@ -0,0 +1,23 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.springframework.stereotype.Service +@Service +class StoreApiServiceImpl : StoreApiService { + + override fun deleteOrder(orderId: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getInventory(): Map { + TODO("Implement me") + } + + override fun getOrderById(orderId: kotlin.Long): Order { + TODO("Implement me") + } + + override fun placeOrder(body: Order): Order { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt new file mode 100644 index 000000000000..1ed657d7663c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt @@ -0,0 +1,137 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.18.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.api + +import org.openapitools.model.User +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface UserApi { + + fun getDelegate(): UserApiDelegate = object: UserApiDelegate {} + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_CREATE_USER /* "/user" */] + ) + fun createUser( + @Valid @RequestBody body: User + ): Unit { + return getDelegate().createUser(body) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */] + ) + fun createUsersWithArrayInput( + @Valid @RequestBody body: kotlin.collections.List + ): Unit { + return getDelegate().createUsersWithArrayInput(body) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */] + ) + fun createUsersWithListInput( + @Valid @RequestBody body: kotlin.collections.List + ): Unit { + return getDelegate().createUsersWithListInput(body) + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @RequestMapping( + method = [RequestMethod.DELETE], + value = [PATH_DELETE_USER /* "/user/{username}" */] + ) + fun deleteUser( + @PathVariable("username") username: kotlin.String + ): Unit { + return getDelegate().deleteUser(username) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], + produces = ["application/xml", "application/json"] + ) + fun getUserByName( + @PathVariable("username") username: kotlin.String + ): User { + return getDelegate().getUserByName(username) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_LOGIN_USER /* "/user/login" */], + produces = ["application/xml", "application/json"] + ) + fun loginUser( + @NotNull @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): kotlin.String { + return getDelegate().loginUser(username, password) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_LOGOUT_USER /* "/user/logout" */] + ) + fun logoutUser(): Unit { + return getDelegate().logoutUser() + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @RequestMapping( + method = [RequestMethod.PUT], + value = [PATH_UPDATE_USER /* "/user/{username}" */] + ) + fun updateUser( + @PathVariable("username") username: kotlin.String, + @Valid @RequestBody body: User + ): Unit { + return getDelegate().updateUser(username, body) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiController.kt new file mode 100644 index 000000000000..d298504ed57a --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -0,0 +1,20 @@ +package org.openapitools.api + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import java.util.Optional + +@javax.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.18.0-SNAPSHOT") +@Controller +@RequestMapping("\${openapi.openAPIPetstore.base-path:/v2}") +class UserApiController( + delegate: UserApiDelegate? +) : UserApi { + private lateinit var delegate: UserApiDelegate + + init { + this.delegate = Optional.ofNullable(delegate).orElse(object : UserApiDelegate {}) + } + + override fun getDelegate(): UserApiDelegate = delegate +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiDelegate.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiDelegate.kt new file mode 100644 index 000000000000..d3479ff78aad --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiDelegate.kt @@ -0,0 +1,104 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.web.context.request.NativeWebRequest + +import java.util.Optional + +/** + * A delegate to be called by the {@link UserApiController}}. + * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class. + */ +@javax.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.18.0-SNAPSHOT") +interface UserApiDelegate { + + fun getRequest(): Optional = Optional.empty() + + /** + * @see UserApi#createUser + */ + fun createUser(body: User): Unit { + return TODO("Not yet implemented") + + } + + + /** + * @see UserApi#createUsersWithArrayInput + */ + fun createUsersWithArrayInput(body: kotlin.collections.List): Unit { + return TODO("Not yet implemented") + + } + + + /** + * @see UserApi#createUsersWithListInput + */ + fun createUsersWithListInput(body: kotlin.collections.List): Unit { + return TODO("Not yet implemented") + + } + + + /** + * @see UserApi#deleteUser + */ + fun deleteUser(username: kotlin.String): Unit { + return TODO("Not yet implemented") + + } + + + /** + * @see UserApi#getUserByName + */ + fun getUserByName(username: kotlin.String): User { + getRequest().ifPresent { request -> + for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + ApiUtil.setExampleResponse(request, "application/json", "{ \"firstName\" : \"firstName\", \"lastName\" : \"lastName\", \"password\" : \"password\", \"userStatus\" : 6, \"phone\" : \"phone\", \"id\" : 0, \"email\" : \"email\", \"username\" : \"username\"}") + break + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + ApiUtil.setExampleResponse(request, "application/xml", " 123456789 aeiou aeiou aeiou aeiou aeiou aeiou 123") + break + } + } + } + return TODO("Not yet implemented") + + } + + + /** + * @see UserApi#loginUser + */ + fun loginUser(username: kotlin.String, + password: kotlin.String): kotlin.String { + return TODO("Not yet implemented") + + } + + + /** + * @see UserApi#logoutUser + */ + fun logoutUser(): Unit { + return TODO("Not yet implemented") + + } + + + /** + * @see UserApi#updateUser + */ + fun updateUser(username: kotlin.String, + body: User): Unit { + return TODO("Not yet implemented") + + } + +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiService.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiService.kt new file mode 100644 index 000000000000..a1bcf6be237c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiService.kt @@ -0,0 +1,87 @@ +package org.openapitools.api + +import org.openapitools.model.User + +interface UserApiService { + + /** + * POST /user : Create user + * This can only be done by the logged in user. + * + * @param body Created user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUser + */ + fun createUser(body: User): Unit + + /** + * POST /user/createWithArray : Creates list of users with given input array + * + * @param body List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithArrayInput + */ + fun createUsersWithArrayInput(body: kotlin.collections.List): Unit + + /** + * POST /user/createWithList : Creates list of users with given input array + * + * @param body List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithListInput + */ + fun createUsersWithListInput(body: kotlin.collections.List): Unit + + /** + * DELETE /user/{username} : Delete user + * This can only be done by the logged in user. + * + * @param username The name that needs to be deleted (required) + * @return Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#deleteUser + */ + fun deleteUser(username: kotlin.String): Unit + + /** + * GET /user/{username} : Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. (required) + * @return successful operation (status code 200) + * or Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#getUserByName + */ + fun getUserByName(username: kotlin.String): User + + /** + * GET /user/login : Logs user into the system + * + * @param username The user name for login (required) + * @param password The password for login in clear text (required) + * @return successful operation (status code 200) + * or Invalid username/password supplied (status code 400) + * @see UserApi#loginUser + */ + fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String + + /** + * GET /user/logout : Logs out current logged in user session + * + * @return successful operation (status code 200) + * @see UserApi#logoutUser + */ + fun logoutUser(): Unit + + /** + * PUT /user/{username} : Updated user + * This can only be done by the logged in user. + * + * @param username name that need to be deleted (required) + * @param body Updated user object (required) + * @return Invalid user supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#updateUser + */ + fun updateUser(username: kotlin.String, body: User): Unit +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt new file mode 100644 index 000000000000..ebd822220153 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt @@ -0,0 +1,39 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.springframework.stereotype.Service +@Service +class UserApiServiceImpl : UserApiService { + + override fun createUser(body: User): Unit { + TODO("Implement me") + } + + override fun createUsersWithArrayInput(body: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun createUsersWithListInput(body: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun deleteUser(username: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getUserByName(username: kotlin.String): User { + TODO("Implement me") + } + + override fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String { + TODO("Implement me") + } + + override fun logoutUser(): Unit { + TODO("Implement me") + } + + override fun updateUser(username: kotlin.String, body: User): Unit { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Category.kt new file mode 100644 index 000000000000..0638b1718f3d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Category.kt @@ -0,0 +1,33 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * A category for a pet + * @param id + * @param name + */ +data class Category( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("name") val name: kotlin.String? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt new file mode 100644 index 000000000000..f520047d850d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt @@ -0,0 +1,36 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * Describes the result of uploading an image resource + * @param code + * @param type + * @param message + */ +data class ModelApiResponse( + + @get:JsonProperty("code") val code: kotlin.Int? = null, + + @get:JsonProperty("type") val type: kotlin.String? = null, + + @get:JsonProperty("message") val message: kotlin.String? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Order.kt new file mode 100644 index 000000000000..4ebe51e765ed --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Order.kt @@ -0,0 +1,67 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * An order for a pets from the pet store + * @param id + * @param petId + * @param quantity + * @param shipDate + * @param status Order Status + * @param complete + */ +data class Order( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("petId") val petId: kotlin.Long? = null, + + @get:JsonProperty("quantity") val quantity: kotlin.Int? = null, + + @get:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, + + @get:JsonProperty("status") val status: Order.Status? = null, + + @get:JsonProperty("complete") val complete: kotlin.Boolean? = false +) : Serializable { + + /** + * Order Status + * Values: placed,approved,delivered + */ + enum class Status(@get:JsonValue val value: kotlin.String) { + + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + } + } + } + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Pet.kt new file mode 100644 index 000000000000..cf9ccf2f4f7d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Pet.kt @@ -0,0 +1,71 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +import org.openapitools.model.Category +import org.openapitools.model.Tag +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * A pet for sale in the pet store + * @param name + * @param photoUrls + * @param id + * @param category + * @param tags + * @param status pet status in the store + */ +data class Pet( + + @get:JsonProperty("name", required = true) val name: kotlin.String, + + @get:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @field:Valid + @get:JsonProperty("category") val category: Category? = null, + + @field:Valid + @get:JsonProperty("tags") val tags: kotlin.collections.List? = null, + + @get:JsonProperty("status") val status: Pet.Status? = null +) : Serializable { + + /** + * pet status in the store + * Values: available,pending,sold + */ + enum class Status(@get:JsonValue val value: kotlin.String) { + + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + } + } + } + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Tag.kt new file mode 100644 index 000000000000..36f841600047 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Tag.kt @@ -0,0 +1,33 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * A tag for a pet + * @param id + * @param name + */ +data class Tag( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("name") val name: kotlin.String? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/User.kt new file mode 100644 index 000000000000..b04c9e312592 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/User.kt @@ -0,0 +1,51 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * A User who is purchasing from the pet store + * @param id + * @param username + * @param firstName + * @param lastName + * @param email + * @param password + * @param phone + * @param userStatus User Status + */ +data class User( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("username") val username: kotlin.String? = null, + + @get:JsonProperty("firstName") val firstName: kotlin.String? = null, + + @get:JsonProperty("lastName") val lastName: kotlin.String? = null, + + @get:JsonProperty("email") val email: kotlin.String? = null, + + @get:JsonProperty("password") val password: kotlin.String? = null, + + @get:JsonProperty("phone") val phone: kotlin.String? = null, + + @get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/resources/application.yaml b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/resources/application.yaml new file mode 100644 index 000000000000..8e2ebcde976d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/resources/application.yaml @@ -0,0 +1,10 @@ +spring: + application: + name: openAPIPetstore + + jackson: + serialization: + WRITE_DATES_AS_TIMESTAMPS: false + +server: + port: 8080 diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/.openapi-generator-ignore b/samples/server/petstore/kotlin-springboot-no-response-entity/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-no-response-entity/.openapi-generator/FILES new file mode 100644 index 000000000000..c7afb2eda91e --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/.openapi-generator/FILES @@ -0,0 +1,27 @@ +README.md +build.gradle.kts +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +pom.xml +settings.gradle +src/main/kotlin/org/openapitools/Application.kt +src/main/kotlin/org/openapitools/api/ApiUtil.kt +src/main/kotlin/org/openapitools/api/Exceptions.kt +src/main/kotlin/org/openapitools/api/PetApiController.kt +src/main/kotlin/org/openapitools/api/PetApiService.kt +src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/StoreApiController.kt +src/main/kotlin/org/openapitools/api/StoreApiService.kt +src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/UserApiController.kt +src/main/kotlin/org/openapitools/api/UserApiService.kt +src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt +src/main/kotlin/org/openapitools/model/Category.kt +src/main/kotlin/org/openapitools/model/ModelApiResponse.kt +src/main/kotlin/org/openapitools/model/Order.kt +src/main/kotlin/org/openapitools/model/Pet.kt +src/main/kotlin/org/openapitools/model/Tag.kt +src/main/kotlin/org/openapitools/model/User.kt +src/main/resources/application.yaml diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/.openapi-generator/VERSION b/samples/server/petstore/kotlin-springboot-no-response-entity/.openapi-generator/VERSION new file mode 100644 index 000000000000..2fb556b60635 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.18.0-SNAPSHOT diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/README.md b/samples/server/petstore/kotlin-springboot-no-response-entity/README.md new file mode 100644 index 000000000000..b6865a081135 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/README.md @@ -0,0 +1,21 @@ +# openAPIPetstore + +This Kotlin based [Spring Boot](https://spring.io/projects/spring-boot) application has been generated using the [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator). + +## Getting Started + +This document assumes you have either maven or gradle available, either via the wrapper or otherwise. This does not come with a gradle / maven wrapper checked in. + +By default a [`pom.xml`](pom.xml) file will be generated. If you specified `gradleBuildFile=true` when generating this project, a `build.gradle.kts` will also be generated. Note this uses [Gradle Kotlin DSL](https://github.com/gradle/kotlin-dsl). + +To build the project using maven, run: +```bash +mvn package && java -jar target/openapi-spring-1.0.0.jar +``` + +To build the project using gradle, run: +```bash +gradle build && java -jar build/libs/openapi-spring-1.0.0.jar +``` + +If all builds successfully, the server should run on [http://localhost:8080/](http://localhost:8080/) diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/build.gradle.kts b/samples/server/petstore/kotlin-springboot-no-response-entity/build.gradle.kts new file mode 100644 index 000000000000..3507e44d515a --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/build.gradle.kts @@ -0,0 +1,48 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.7") + } +} + +group = "org.openapitools" +version = "1.0.0" + +repositories { + mavenCentral() +} + +tasks.withType { + kotlinOptions.jvmTarget = "11" +} + +plugins { + val kotlinVersion = "1.9.25" + id("org.jetbrains.kotlin.jvm") version kotlinVersion + id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion + id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion + id("org.springframework.boot") version "2.6.7" + id("io.spring.dependency-management") version "1.0.11.RELEASE" +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.springframework.boot:spring-boot-starter-web") + + implementation("com.google.code.findbugs:jsr305:3.0.2") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + implementation("javax.validation:validation-api") + implementation("javax.annotation:javax.annotation-api:1.3.2") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") + testImplementation("org.springframework.boot:spring-boot-starter-test") { + exclude(module = "junit") + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/gradle/wrapper/gradle-wrapper.jar b/samples/server/petstore/kotlin-springboot-no-response-entity/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..e6441136f3d4 Binary files /dev/null and b/samples/server/petstore/kotlin-springboot-no-response-entity/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-springboot-no-response-entity/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..80187ac30432 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/gradlew b/samples/server/petstore/kotlin-springboot-no-response-entity/gradlew new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while +APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path +[ -h "$app_path" ] +do +ls=$( ls -ld "$app_path" ) +link=${ls#*' -> '} +case $link in #( +/*) app_path=$link ;; #( +*) app_path=$APP_HOME$link ;; +esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { +echo "$*" +} >&2 + +die () { +echo +echo "$*" +echo +exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( +CYGWIN* ) cygwin=true ;; #( +Darwin* ) darwin=true ;; #( +MSYS* | MINGW* ) msys=true ;; #( +NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then +if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +# IBM's JDK on AIX uses strange locations for the executables +JAVACMD=$JAVA_HOME/jre/sh/java +else +JAVACMD=$JAVA_HOME/bin/java +fi +if [ ! -x "$JAVACMD" ] ; then +die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +else +JAVACMD=java +if ! command -v java >/dev/null 2>&1 +then +die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then +case $MAX_FD in #( +max*) +# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +MAX_FD=$( ulimit -H -n ) || +warn "Could not query maximum file descriptor limit" +esac +case $MAX_FD in #( +'' | soft) :;; #( +*) +# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +ulimit -n "$MAX_FD" || +warn "Could not set maximum file descriptor limit to $MAX_FD" +esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then +APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) +CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + +JAVACMD=$( cygpath --unix "$JAVACMD" ) + +# Now convert the arguments - kludge to limit ourselves to /bin/sh +for arg do +if +case $arg in #( +-*) false ;; # don't mess with options #( +/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath +[ -e "$t" ] ;; #( +*) false ;; +esac +then +arg=$( cygpath --path --ignore --mixed "$arg" ) +fi +# Roll the args list around exactly as many times as the number of +# args, so each arg winds up back in the position where it started, but +# possibly modified. +# +# NB: a `for` loop captures its iteration list before it begins, so +# changing the positional parameters here affects neither the number of +# iterations, nor the values presented in `arg`. +shift # remove old arg +set -- "$@" "$arg" # push replacement arg +done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ +"-Dorg.gradle.appname=$APP_BASE_NAME" \ +-classpath "$CLASSPATH" \ +org.gradle.wrapper.GradleWrapperMain \ +"$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then +die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( +printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | +xargs -n1 | +sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | +tr '\n' ' ' +)" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/gradlew.bat b/samples/server/petstore/kotlin-springboot-no-response-entity/gradlew.bat new file mode 100644 index 000000000000..25da30dbdeee --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/pom.xml b/samples/server/petstore/kotlin-springboot-no-response-entity/pom.xml new file mode 100644 index 000000000000..cab717f26a33 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/pom.xml @@ -0,0 +1,131 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 3.0.2 + 1.3.2 + 1.6.21 + + 1.6.21 + UTF-8 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.15 + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + spring + + 11 + + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + + + org.springframework.boot + spring-boot-starter-web + + + + + + + com.google.code.findbugs + jsr305 + ${findbugs-jsr305.version} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + javax.validation + validation-api + + + javax.annotation + javax.annotation-api + ${javax-annotation.version} + provided + + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin-test-junit5.version} + test + + + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/settings.gradle b/samples/server/petstore/kotlin-springboot-no-response-entity/settings.gradle new file mode 100644 index 000000000000..14844905cd40 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + maven { url = uri("https://repo.spring.io/snapshot") } + maven { url = uri("https://repo.spring.io/milestone") } + gradlePluginPortal() + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "org.springframework.boot") { + useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}") + } + } + } +} +rootProject.name = "openapi-spring" diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/Application.kt new file mode 100644 index 000000000000..2fe6de62479e --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/Application.kt @@ -0,0 +1,13 @@ +package org.openapitools + +import org.springframework.boot.runApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.context.annotation.ComponentScan + +@SpringBootApplication +@ComponentScan(basePackages = ["org.openapitools", "org.openapitools.api", "org.openapitools.model"]) +class Application + +fun main(args: Array) { + runApplication(*args) +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 000000000000..88e892d0f49a --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,19 @@ +package org.openapitools.api + +import org.springframework.web.context.request.NativeWebRequest + +import javax.servlet.http.HttpServletResponse +import java.io.IOException + +object ApiUtil { + fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { + try { + val res = req.getNativeResponse(HttpServletResponse::class.java) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) + } catch (e: IOException) { + throw RuntimeException(e) + } + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/Exceptions.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/Exceptions.kt new file mode 100644 index 000000000000..901db1237ee7 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/Exceptions.kt @@ -0,0 +1,30 @@ +package org.openapitools.api + +import org.springframework.context.annotation.Configuration +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.bind.annotation.ExceptionHandler +import javax.servlet.http.HttpServletResponse +import javax.validation.ConstraintViolationException + +// TODO Extend ApiException for custom exception handling, e.g. the below NotFound exception +sealed class ApiException(msg: String, val code: Int) : Exception(msg) + +class NotFoundException(msg: String, code: Int = HttpStatus.NOT_FOUND.value()) : ApiException(msg, code) + +@Configuration("org.openapitools.api.DefaultExceptionHandler") +@ControllerAdvice +class DefaultExceptionHandler { + + @ExceptionHandler(value = [ApiException::class]) + fun onApiException(ex: ApiException, response: HttpServletResponse): Unit = + response.sendError(ex.code, ex.message) + + @ExceptionHandler(value = [NotImplementedError::class]) + fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.NOT_IMPLEMENTED.value()) + + @ExceptionHandler(value = [ConstraintViolationException::class]) + fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message }) +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiController.kt new file mode 100644 index 000000000000..cb60d0e0d1d4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -0,0 +1,145 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.PetApiController.Companion.BASE_PATH + +import javax.validation.Valid +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") +class PetApiController(@Autowired(required = true) val service: PetApiService) { + + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_ADD_PET /* "/pet" */], + consumes = ["application/json", "application/xml"] + ) + fun addPet( + @Valid @RequestBody body: Pet + ): Unit { + return service.addPet(body) + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @RequestMapping( + method = [RequestMethod.DELETE], + value = [PATH_DELETE_PET /* "/pet/{petId}" */] + ) + fun deletePet( + @PathVariable("petId") petId: kotlin.Long, + @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): Unit { + return service.deletePet(petId, apiKey) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], + produces = ["application/xml", "application/json"] + ) + fun findPetsByStatus( + @NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): List { + return service.findPetsByStatus(status) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], + produces = ["application/xml", "application/json"] + ) + fun findPetsByTags( + @NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): List { + return service.findPetsByTags(tags) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], + produces = ["application/xml", "application/json"] + ) + fun getPetById( + @PathVariable("petId") petId: kotlin.Long + ): Pet { + return service.getPetById(petId) + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @RequestMapping( + method = [RequestMethod.PUT], + value = [PATH_UPDATE_PET /* "/pet" */], + consumes = ["application/json", "application/xml"] + ) + fun updatePet( + @Valid @RequestBody body: Pet + ): Unit { + return service.updatePet(body) + } + + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], + consumes = ["application/x-www-form-urlencoded"] + ) + fun updatePetWithForm( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): Unit { + return service.updatePetWithForm(petId, name, status) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], + produces = ["application/json"], + consumes = ["multipart/form-data"] + ) + fun uploadFile( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ModelApiResponse { + return service.uploadFile(petId, additionalMetadata, file) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiService.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiService.kt new file mode 100644 index 000000000000..db655b8a7978 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiService.kt @@ -0,0 +1,94 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet + +interface PetApiService { + + /** + * POST /pet : Add a new pet to the store + * + * @param body Pet object that needs to be added to the store (required) + * @return Invalid input (status code 405) + * @see PetApi#addPet + */ + fun addPet(body: Pet): Unit + + /** + * DELETE /pet/{petId} : Deletes a pet + * + * @param petId Pet id to delete (required) + * @param apiKey (optional) + * @return Invalid pet value (status code 400) + * @see PetApi#deletePet + */ + fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit + + /** + * GET /pet/findByStatus : Finds Pets by status + * Multiple status values can be provided with comma separated strings + * + * @param status Status values that need to be considered for filter (required) + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + * @see PetApi#findPetsByStatus + */ + fun findPetsByStatus(status: kotlin.collections.List): List + + /** + * GET /pet/findByTags : Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * + * @param tags Tags to filter by (required) + * @return successful operation (status code 200) + * or Invalid tag value (status code 400) + * @deprecated + * @see PetApi#findPetsByTags + */ + fun findPetsByTags(tags: kotlin.collections.List): List + + /** + * GET /pet/{petId} : Find pet by ID + * Returns a single pet + * + * @param petId ID of pet to return (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * @see PetApi#getPetById + */ + fun getPetById(petId: kotlin.Long): Pet + + /** + * PUT /pet : Update an existing pet + * + * @param body Pet object that needs to be added to the store (required) + * @return Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * or Validation exception (status code 405) + * @see PetApi#updatePet + */ + fun updatePet(body: Pet): Unit + + /** + * POST /pet/{petId} : Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated (required) + * @param name Updated name of the pet (optional) + * @param status Updated status of the pet (optional) + * @return Invalid input (status code 405) + * @see PetApi#updatePetWithForm + */ + fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit + + /** + * POST /pet/{petId}/uploadImage : uploads an image + * + * @param petId ID of pet to update (required) + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return successful operation (status code 200) + * @see PetApi#uploadFile + */ + fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.web.multipart.MultipartFile): ModelApiResponse +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt new file mode 100644 index 000000000000..a48482be32bd --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt @@ -0,0 +1,40 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.springframework.stereotype.Service +@Service +class PetApiServiceImpl : PetApiService { + + override fun addPet(body: Pet): Unit { + TODO("Implement me") + } + + override fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun findPetsByStatus(status: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun findPetsByTags(tags: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun getPetById(petId: kotlin.Long): Pet { + TODO("Implement me") + } + + override fun updatePet(body: Pet): Unit { + TODO("Implement me") + } + + override fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.web.multipart.MultipartFile): ModelApiResponse { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiController.kt new file mode 100644 index 000000000000..dce3fcd2c62e --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -0,0 +1,84 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.StoreApiController.Companion.BASE_PATH + +import javax.validation.Valid +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") +class StoreApiController(@Autowired(required = true) val service: StoreApiService) { + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @RequestMapping( + method = [RequestMethod.DELETE], + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] + ) + fun deleteOrder( + @PathVariable("orderId") orderId: kotlin.String + ): Unit { + return service.deleteOrder(orderId) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], + produces = ["application/json"] + ) + fun getInventory(): Map { + return service.getInventory() + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], + produces = ["application/xml", "application/json"] + ) + fun getOrderById( + @Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long + ): Order { + return service.getOrderById(orderId) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_PLACE_ORDER /* "/store/order" */], + produces = ["application/xml", "application/json"] + ) + fun placeOrder( + @Valid @RequestBody body: Order + ): Order { + return service.placeOrder(body) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiService.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiService.kt new file mode 100644 index 000000000000..60e754529448 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiService.kt @@ -0,0 +1,48 @@ +package org.openapitools.api + +import org.openapitools.model.Order + +interface StoreApiService { + + /** + * DELETE /store/order/{orderId} : Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * + * @param orderId ID of the order that needs to be deleted (required) + * @return Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#deleteOrder + */ + fun deleteOrder(orderId: kotlin.String): Unit + + /** + * GET /store/inventory : Returns pet inventories by status + * Returns a map of status codes to quantities + * + * @return successful operation (status code 200) + * @see StoreApi#getInventory + */ + fun getInventory(): Map + + /** + * GET /store/order/{orderId} : Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions + * + * @param orderId ID of pet that needs to be fetched (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#getOrderById + */ + fun getOrderById(orderId: kotlin.Long): Order + + /** + * POST /store/order : Place an order for a pet + * + * @param body order placed for purchasing the pet (required) + * @return successful operation (status code 200) + * or Invalid Order (status code 400) + * @see StoreApi#placeOrder + */ + fun placeOrder(body: Order): Order +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt new file mode 100644 index 000000000000..7e733e28dc50 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt @@ -0,0 +1,23 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.springframework.stereotype.Service +@Service +class StoreApiServiceImpl : StoreApiService { + + override fun deleteOrder(orderId: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getInventory(): Map { + TODO("Implement me") + } + + override fun getOrderById(orderId: kotlin.Long): Order { + TODO("Implement me") + } + + override fun placeOrder(body: Order): Order { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiController.kt new file mode 100644 index 000000000000..76afc5032efb --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -0,0 +1,133 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.UserApiController.Companion.BASE_PATH + +import javax.validation.Valid +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") +class UserApiController(@Autowired(required = true) val service: UserApiService) { + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_CREATE_USER /* "/user" */] + ) + fun createUser( + @Valid @RequestBody body: User + ): Unit { + return service.createUser(body) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */] + ) + fun createUsersWithArrayInput( + @Valid @RequestBody body: kotlin.collections.List + ): Unit { + return service.createUsersWithArrayInput(body) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */] + ) + fun createUsersWithListInput( + @Valid @RequestBody body: kotlin.collections.List + ): Unit { + return service.createUsersWithListInput(body) + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @RequestMapping( + method = [RequestMethod.DELETE], + value = [PATH_DELETE_USER /* "/user/{username}" */] + ) + fun deleteUser( + @PathVariable("username") username: kotlin.String + ): Unit { + return service.deleteUser(username) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], + produces = ["application/xml", "application/json"] + ) + fun getUserByName( + @PathVariable("username") username: kotlin.String + ): User { + return service.getUserByName(username) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_LOGIN_USER /* "/user/login" */], + produces = ["application/xml", "application/json"] + ) + fun loginUser( + @NotNull @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): kotlin.String { + return service.loginUser(username, password) + } + + @ResponseStatus(HttpStatus.OK) + @RequestMapping( + method = [RequestMethod.GET], + value = [PATH_LOGOUT_USER /* "/user/logout" */] + ) + fun logoutUser(): Unit { + return service.logoutUser() + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @RequestMapping( + method = [RequestMethod.PUT], + value = [PATH_UPDATE_USER /* "/user/{username}" */] + ) + fun updateUser( + @PathVariable("username") username: kotlin.String, + @Valid @RequestBody body: User + ): Unit { + return service.updateUser(username, body) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiService.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiService.kt new file mode 100644 index 000000000000..a1bcf6be237c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiService.kt @@ -0,0 +1,87 @@ +package org.openapitools.api + +import org.openapitools.model.User + +interface UserApiService { + + /** + * POST /user : Create user + * This can only be done by the logged in user. + * + * @param body Created user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUser + */ + fun createUser(body: User): Unit + + /** + * POST /user/createWithArray : Creates list of users with given input array + * + * @param body List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithArrayInput + */ + fun createUsersWithArrayInput(body: kotlin.collections.List): Unit + + /** + * POST /user/createWithList : Creates list of users with given input array + * + * @param body List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithListInput + */ + fun createUsersWithListInput(body: kotlin.collections.List): Unit + + /** + * DELETE /user/{username} : Delete user + * This can only be done by the logged in user. + * + * @param username The name that needs to be deleted (required) + * @return Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#deleteUser + */ + fun deleteUser(username: kotlin.String): Unit + + /** + * GET /user/{username} : Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. (required) + * @return successful operation (status code 200) + * or Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#getUserByName + */ + fun getUserByName(username: kotlin.String): User + + /** + * GET /user/login : Logs user into the system + * + * @param username The user name for login (required) + * @param password The password for login in clear text (required) + * @return successful operation (status code 200) + * or Invalid username/password supplied (status code 400) + * @see UserApi#loginUser + */ + fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String + + /** + * GET /user/logout : Logs out current logged in user session + * + * @return successful operation (status code 200) + * @see UserApi#logoutUser + */ + fun logoutUser(): Unit + + /** + * PUT /user/{username} : Updated user + * This can only be done by the logged in user. + * + * @param username name that need to be deleted (required) + * @param body Updated user object (required) + * @return Invalid user supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#updateUser + */ + fun updateUser(username: kotlin.String, body: User): Unit +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt new file mode 100644 index 000000000000..ebd822220153 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt @@ -0,0 +1,39 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.springframework.stereotype.Service +@Service +class UserApiServiceImpl : UserApiService { + + override fun createUser(body: User): Unit { + TODO("Implement me") + } + + override fun createUsersWithArrayInput(body: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun createUsersWithListInput(body: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun deleteUser(username: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getUserByName(username: kotlin.String): User { + TODO("Implement me") + } + + override fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String { + TODO("Implement me") + } + + override fun logoutUser(): Unit { + TODO("Implement me") + } + + override fun updateUser(username: kotlin.String, body: User): Unit { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Category.kt new file mode 100644 index 000000000000..0638b1718f3d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Category.kt @@ -0,0 +1,33 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * A category for a pet + * @param id + * @param name + */ +data class Category( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("name") val name: kotlin.String? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt new file mode 100644 index 000000000000..f520047d850d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt @@ -0,0 +1,36 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * Describes the result of uploading an image resource + * @param code + * @param type + * @param message + */ +data class ModelApiResponse( + + @get:JsonProperty("code") val code: kotlin.Int? = null, + + @get:JsonProperty("type") val type: kotlin.String? = null, + + @get:JsonProperty("message") val message: kotlin.String? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt new file mode 100644 index 000000000000..4ebe51e765ed --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt @@ -0,0 +1,67 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * An order for a pets from the pet store + * @param id + * @param petId + * @param quantity + * @param shipDate + * @param status Order Status + * @param complete + */ +data class Order( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("petId") val petId: kotlin.Long? = null, + + @get:JsonProperty("quantity") val quantity: kotlin.Int? = null, + + @get:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, + + @get:JsonProperty("status") val status: Order.Status? = null, + + @get:JsonProperty("complete") val complete: kotlin.Boolean? = false +) : Serializable { + + /** + * Order Status + * Values: placed,approved,delivered + */ + enum class Status(@get:JsonValue val value: kotlin.String) { + + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + } + } + } + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt new file mode 100644 index 000000000000..cf9ccf2f4f7d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt @@ -0,0 +1,71 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +import org.openapitools.model.Category +import org.openapitools.model.Tag +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * A pet for sale in the pet store + * @param name + * @param photoUrls + * @param id + * @param category + * @param tags + * @param status pet status in the store + */ +data class Pet( + + @get:JsonProperty("name", required = true) val name: kotlin.String, + + @get:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @field:Valid + @get:JsonProperty("category") val category: Category? = null, + + @field:Valid + @get:JsonProperty("tags") val tags: kotlin.collections.List? = null, + + @get:JsonProperty("status") val status: Pet.Status? = null +) : Serializable { + + /** + * pet status in the store + * Values: available,pending,sold + */ + enum class Status(@get:JsonValue val value: kotlin.String) { + + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + } + } + } + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Tag.kt new file mode 100644 index 000000000000..36f841600047 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Tag.kt @@ -0,0 +1,33 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * A tag for a pet + * @param id + * @param name + */ +data class Tag( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("name") val name: kotlin.String? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/User.kt new file mode 100644 index 000000000000..b04c9e312592 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/User.kt @@ -0,0 +1,51 @@ +package org.openapitools.model + +import java.util.Locale +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import java.io.Serializable +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid + +/** + * A User who is purchasing from the pet store + * @param id + * @param username + * @param firstName + * @param lastName + * @param email + * @param password + * @param phone + * @param userStatus User Status + */ +data class User( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("username") val username: kotlin.String? = null, + + @get:JsonProperty("firstName") val firstName: kotlin.String? = null, + + @get:JsonProperty("lastName") val lastName: kotlin.String? = null, + + @get:JsonProperty("email") val email: kotlin.String? = null, + + @get:JsonProperty("password") val password: kotlin.String? = null, + + @get:JsonProperty("phone") val phone: kotlin.String? = null, + + @get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null +) : Serializable { + + companion object { + private const val serialVersionUID: kotlin.Long = 1 + } +} + diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/resources/application.yaml b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/resources/application.yaml new file mode 100644 index 000000000000..8e2ebcde976d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/resources/application.yaml @@ -0,0 +1,10 @@ +spring: + application: + name: openAPIPetstore + + jackson: + serialization: + WRITE_DATES_AS_TIMESTAMPS: false + +server: + port: 8080 diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/test/kotlin/org/openapitools/api/PetApiTest.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/test/kotlin/org/openapitools/api/PetApiTest.kt new file mode 100644 index 000000000000..5a7baad83f26 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/test/kotlin/org/openapitools/api/PetApiTest.kt @@ -0,0 +1,137 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.junit.jupiter.api.Test +import org.springframework.http.HttpStatus + +class PetApiTest { + + private val service: PetApiService = PetApiServiceImpl() + private val api: PetApiController = PetApiController(service) + + /** + * To test PetApiController.addPet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun addPetTest() { + val body: Pet = TODO() + + val response: Unit = api.addPet(body) + + // TODO: test validations + } + + /** + * To test PetApiController.deletePet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deletePetTest() { + val petId: kotlin.Long = TODO() + val apiKey: kotlin.String? = TODO() + + val response: Unit = api.deletePet(petId, apiKey) + + // TODO: test validations + } + + /** + * To test PetApiController.findPetsByStatus + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun findPetsByStatusTest() { + val status: kotlin.collections.List = TODO() + + val response: List = api.findPetsByStatus(status) + + // TODO: test validations + } + + /** + * To test PetApiController.findPetsByTags + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun findPetsByTagsTest() { + val tags: kotlin.collections.List = TODO() + + val response: List = api.findPetsByTags(tags) + + // TODO: test validations + } + + /** + * To test PetApiController.getPetById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getPetByIdTest() { + val petId: kotlin.Long = TODO() + + val response: Pet = api.getPetById(petId) + + // TODO: test validations + } + + /** + * To test PetApiController.updatePet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updatePetTest() { + val body: Pet = TODO() + + val response: Unit = api.updatePet(body) + + // TODO: test validations + } + + /** + * To test PetApiController.updatePetWithForm + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updatePetWithFormTest() { + val petId: kotlin.Long = TODO() + val name: kotlin.String? = TODO() + val status: kotlin.String? = TODO() + + val response: Unit = api.updatePetWithForm(petId, name, status) + + // TODO: test validations + } + + /** + * To test PetApiController.uploadFile + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun uploadFileTest() { + val petId: kotlin.Long = TODO() + val additionalMetadata: kotlin.String? = TODO() + val file: org.springframework.web.multipart.MultipartFile = TODO() + + val response: ModelApiResponse = api.uploadFile(petId, additionalMetadata, file) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/test/kotlin/org/openapitools/api/StoreApiTest.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/test/kotlin/org/openapitools/api/StoreApiTest.kt new file mode 100644 index 000000000000..8a4438d8d588 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/test/kotlin/org/openapitools/api/StoreApiTest.kt @@ -0,0 +1,70 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.junit.jupiter.api.Test +import org.springframework.http.HttpStatus + +class StoreApiTest { + + private val service: StoreApiService = StoreApiServiceImpl() + private val api: StoreApiController = StoreApiController(service) + + /** + * To test StoreApiController.deleteOrder + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deleteOrderTest() { + val orderId: kotlin.String = TODO() + + val response: Unit = api.deleteOrder(orderId) + + // TODO: test validations + } + + /** + * To test StoreApiController.getInventory + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getInventoryTest() { + + val response: Map = api.getInventory() + + // TODO: test validations + } + + /** + * To test StoreApiController.getOrderById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getOrderByIdTest() { + val orderId: kotlin.Long = TODO() + + val response: Order = api.getOrderById(orderId) + + // TODO: test validations + } + + /** + * To test StoreApiController.placeOrder + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun placeOrderTest() { + val body: Order = TODO() + + val response: Order = api.placeOrder(body) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/test/kotlin/org/openapitools/api/UserApiTest.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/test/kotlin/org/openapitools/api/UserApiTest.kt new file mode 100644 index 000000000000..77c111370513 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/test/kotlin/org/openapitools/api/UserApiTest.kt @@ -0,0 +1,132 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.junit.jupiter.api.Test +import org.springframework.http.HttpStatus + +class UserApiTest { + + private val service: UserApiService = UserApiServiceImpl() + private val api: UserApiController = UserApiController(service) + + /** + * To test UserApiController.createUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUserTest() { + val body: User = TODO() + + val response: Unit = api.createUser(body) + + // TODO: test validations + } + + /** + * To test UserApiController.createUsersWithArrayInput + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUsersWithArrayInputTest() { + val body: kotlin.collections.List = TODO() + + val response: Unit = api.createUsersWithArrayInput(body) + + // TODO: test validations + } + + /** + * To test UserApiController.createUsersWithListInput + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUsersWithListInputTest() { + val body: kotlin.collections.List = TODO() + + val response: Unit = api.createUsersWithListInput(body) + + // TODO: test validations + } + + /** + * To test UserApiController.deleteUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deleteUserTest() { + val username: kotlin.String = TODO() + + val response: Unit = api.deleteUser(username) + + // TODO: test validations + } + + /** + * To test UserApiController.getUserByName + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getUserByNameTest() { + val username: kotlin.String = TODO() + + val response: User = api.getUserByName(username) + + // TODO: test validations + } + + /** + * To test UserApiController.loginUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun loginUserTest() { + val username: kotlin.String = TODO() + val password: kotlin.String = TODO() + + val response: kotlin.String = api.loginUser(username, password) + + // TODO: test validations + } + + /** + * To test UserApiController.logoutUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun logoutUserTest() { + + val response: Unit = api.logoutUser() + + // TODO: test validations + } + + /** + * To test UserApiController.updateUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updateUserTest() { + val username: kotlin.String = TODO() + val body: User = TODO() + + val response: Unit = api.updateUser(username, body) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiController.kt index 26f2ad661da4..a10f86c342b4 100644 --- a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.PetApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -32,7 +33,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class PetApiController(@Autowired(required = true) val service: PetApiService) { @Operation( @@ -46,11 +47,13 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet"], + value = [PATH_ADD_PET /* "/pet" */], produces = ["application/xml", "application/json"], consumes = ["application/json", "application/xml"] ) - suspend fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + suspend fun addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(service.addPet(pet), HttpStatus.valueOf(200)) } @@ -64,9 +67,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - suspend fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + suspend fun deletePet( + @Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) } @@ -81,10 +87,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByStatus"], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], produces = ["application/xml", "application/json"] ) - suspend fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + suspend fun findPetsByStatus( + @NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) } @@ -99,10 +107,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByTags"], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], produces = ["application/xml", "application/json"] ) - suspend fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + suspend fun findPetsByTags( + @NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) } @@ -118,10 +128,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/{petId}"], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], produces = ["application/xml", "application/json"] ) - suspend fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + suspend fun getPetById( + @Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } @@ -138,11 +150,13 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/pet"], + value = [PATH_UPDATE_PET /* "/pet" */], produces = ["application/xml", "application/json"], consumes = ["application/json", "application/xml"] ) - suspend fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + suspend fun updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(service.updatePet(pet), HttpStatus.valueOf(200)) } @@ -156,10 +170,14 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}"], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], consumes = ["application/x-www-form-urlencoded"] ) - suspend fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + suspend fun updatePetWithForm( + @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) } @@ -173,11 +191,28 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], produces = ["application/json"], consumes = ["multipart/form-data"] ) - suspend fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + suspend fun uploadFile( + @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiController.kt index db2e659b5edd..8967e0d637fd 100644 --- a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.StoreApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -31,7 +32,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class StoreApiController(@Autowired(required = true) val service: StoreApiService) { @Operation( @@ -44,9 +45,11 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - suspend fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + suspend fun deleteOrder( + @Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } @@ -60,7 +63,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/inventory"], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], produces = ["application/json"] ) suspend fun getInventory(): ResponseEntity> { @@ -78,10 +81,12 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], produces = ["application/xml", "application/json"] ) - suspend fun getOrderById(@Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + suspend fun getOrderById( + @Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) } @@ -95,11 +100,22 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.POST], - value = ["/store/order"], + value = [PATH_PLACE_ORDER /* "/store/order" */], produces = ["application/xml", "application/json"], consumes = ["application/json"] ) - suspend fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order): ResponseEntity { + suspend fun placeOrder( + @Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order + ): ResponseEntity { return ResponseEntity(service.placeOrder(order), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiController.kt index 8884b2a1a70f..6a15aea0c755 100644 --- a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.UserApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -31,7 +32,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class UserApiController(@Autowired(required = true) val service: UserApiService) { @Operation( @@ -44,10 +45,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user"], + value = [PATH_CREATE_USER /* "/user" */], consumes = ["application/json"] ) - suspend fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + suspend fun createUser( + @Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(service.createUser(user), HttpStatus.valueOf(200)) } @@ -61,10 +64,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithArray"], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], consumes = ["application/json"] ) - suspend fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow): ResponseEntity { + suspend fun createUsersWithArrayInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow + ): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(user), HttpStatus.valueOf(200)) } @@ -78,10 +83,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithList"], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], consumes = ["application/json"] ) - suspend fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow): ResponseEntity { + suspend fun createUsersWithListInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow + ): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(user), HttpStatus.valueOf(200)) } @@ -96,9 +103,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/user/{username}"] + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - suspend fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + suspend fun deleteUser( + @Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } @@ -113,10 +122,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/{username}"], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], produces = ["application/xml", "application/json"] ) - suspend fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + suspend fun getUserByName( + @Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } @@ -130,10 +141,13 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/login"], + value = [PATH_LOGIN_USER /* "/user/login" */], produces = ["application/xml", "application/json"] ) - suspend fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + suspend fun loginUser( + @NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } @@ -147,7 +161,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/logout"] + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) suspend fun logoutUser(): ResponseEntity { return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) @@ -164,10 +178,26 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/user/{username}"], + value = [PATH_UPDATE_USER /* "/user/{username}" */], consumes = ["application/json"] ) - suspend fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + suspend fun updateUser( + @Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String, + @Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(service.updateUser(username, user), HttpStatus.valueOf(400)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiController.kt index fff401053667..85560fcc7096 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.PetApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -32,7 +33,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class PetApiController(@Autowired(required = true) val service: PetApiService) { @Operation( @@ -46,11 +47,13 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet"], + value = [PATH_ADD_PET /* "/pet" */], produces = ["application/xml", "application/json"], consumes = ["application/json", "application/xml"] ) - suspend fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + suspend fun addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(service.addPet(pet), HttpStatus.valueOf(200)) } @@ -64,9 +67,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - suspend fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + suspend fun deletePet( + @Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) } @@ -81,10 +87,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByStatus"], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) } @@ -99,10 +107,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByTags"], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) } @@ -118,10 +128,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/{petId}"], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], produces = ["application/xml", "application/json"] ) - suspend fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + suspend fun getPetById( + @Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } @@ -138,11 +150,13 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/pet"], + value = [PATH_UPDATE_PET /* "/pet" */], produces = ["application/xml", "application/json"], consumes = ["application/json", "application/xml"] ) - suspend fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + suspend fun updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(service.updatePet(pet), HttpStatus.valueOf(200)) } @@ -156,10 +170,14 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}"], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], consumes = ["application/x-www-form-urlencoded"] ) - suspend fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + suspend fun updatePetWithForm( + @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) } @@ -173,11 +191,28 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], produces = ["application/json"], consumes = ["multipart/form-data"] ) - suspend fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + suspend fun uploadFile( + @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiController.kt index db2e659b5edd..8967e0d637fd 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.StoreApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -31,7 +32,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class StoreApiController(@Autowired(required = true) val service: StoreApiService) { @Operation( @@ -44,9 +45,11 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - suspend fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + suspend fun deleteOrder( + @Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } @@ -60,7 +63,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/inventory"], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], produces = ["application/json"] ) suspend fun getInventory(): ResponseEntity> { @@ -78,10 +81,12 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], produces = ["application/xml", "application/json"] ) - suspend fun getOrderById(@Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + suspend fun getOrderById( + @Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) } @@ -95,11 +100,22 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.POST], - value = ["/store/order"], + value = [PATH_PLACE_ORDER /* "/store/order" */], produces = ["application/xml", "application/json"], consumes = ["application/json"] ) - suspend fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order): ResponseEntity { + suspend fun placeOrder( + @Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order + ): ResponseEntity { return ResponseEntity(service.placeOrder(order), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiController.kt index 8884b2a1a70f..6a15aea0c755 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.UserApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -31,7 +32,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class UserApiController(@Autowired(required = true) val service: UserApiService) { @Operation( @@ -44,10 +45,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user"], + value = [PATH_CREATE_USER /* "/user" */], consumes = ["application/json"] ) - suspend fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + suspend fun createUser( + @Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(service.createUser(user), HttpStatus.valueOf(200)) } @@ -61,10 +64,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithArray"], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], consumes = ["application/json"] ) - suspend fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow): ResponseEntity { + suspend fun createUsersWithArrayInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow + ): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(user), HttpStatus.valueOf(200)) } @@ -78,10 +83,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithList"], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], consumes = ["application/json"] ) - suspend fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow): ResponseEntity { + suspend fun createUsersWithListInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow + ): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(user), HttpStatus.valueOf(200)) } @@ -96,9 +103,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/user/{username}"] + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - suspend fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + suspend fun deleteUser( + @Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } @@ -113,10 +122,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/{username}"], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], produces = ["application/xml", "application/json"] ) - suspend fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + suspend fun getUserByName( + @Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } @@ -130,10 +141,13 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/login"], + value = [PATH_LOGIN_USER /* "/user/login" */], produces = ["application/xml", "application/json"] ) - suspend fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + suspend fun loginUser( + @NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } @@ -147,7 +161,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/logout"] + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) suspend fun logoutUser(): ResponseEntity { return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) @@ -164,10 +178,26 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/user/{username}"], + value = [PATH_UPDATE_USER /* "/user/{username}" */], consumes = ["application/json"] ) - suspend fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + suspend fun updateUser( + @Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String, + @Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(service.updateUser(username, user), HttpStatus.valueOf(400)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FakeApi.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FakeApi.kt index 1b78bc27d45d..941858965272 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FakeApi.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FakeApi.kt @@ -47,11 +47,18 @@ interface FakeApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/fake/cookie-suggestion"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_FAKE_COOKIE_SUGGESTION /* "/fake/cookie-suggestion" */], + produces = ["application/json"] ) - fun fakeCookieSuggestion(@NotNull @CookieValue(name = "category.history") categoryHistory: kotlin.String): ResponseEntity> { + fun fakeCookieSuggestion( + @NotNull @CookieValue(name = "category.history") categoryHistory: kotlin.String + ): ResponseEntity> { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_FAKE_COOKIE_SUGGESTION: String = "/fake/cookie-suggestion" + } } diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FakeClassnameTestApi.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FakeClassnameTestApi.kt index 2b2ad61ab63d..4140a5b2bc8e 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FakeClassnameTestApi.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FakeClassnameTestApi.kt @@ -48,12 +48,19 @@ interface FakeClassnameTestApi { security = [ SecurityRequirement(name = "api_key_query") ] ) @RequestMapping( - method = [RequestMethod.PATCH], - value = ["/fake_classname_test"], - produces = ["application/json"], - consumes = ["application/json"] + method = [RequestMethod.PATCH], + value = [PATH_TEST_CLASSNAME /* "/fake_classname_test" */], + produces = ["application/json"], + consumes = ["application/json"] ) - fun testClassname(@Parameter(description = "client model", required = true) @Valid @RequestBody client: Client): ResponseEntity { + fun testClassname( + @Parameter(description = "client model", required = true) @Valid @RequestBody client: Client + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_TEST_CLASSNAME: String = "/fake_classname_test" + } } diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FooApi.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FooApi.kt index 1a2322eaa34b..14c9e4a6e035 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FooApi.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/FooApi.kt @@ -47,11 +47,16 @@ interface FooApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/foo"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_FOO_GET /* "/foo" */], + produces = ["application/json"] ) fun fooGet(): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_FOO_GET: String = "/foo" + } } diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/PetApi.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/PetApi.kt index 565b6264e4d7..c13edd06a380 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/PetApi.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/PetApi.kt @@ -50,11 +50,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet"], - consumes = ["application/json", "application/xml"] + method = [RequestMethod.POST], + value = [PATH_ADD_PET /* "/pet" */], + consumes = ["application/json", "application/xml"] ) - fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + fun addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -70,10 +72,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -89,11 +94,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByStatus"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], + produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -109,11 +116,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByTags"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], + produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -130,11 +139,13 @@ interface PetApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/{petId}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], + produces = ["application/xml", "application/json"] ) - fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -152,11 +163,13 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.PUT], - value = ["/pet"], - consumes = ["application/json", "application/xml"] + method = [RequestMethod.PUT], + value = [PATH_UPDATE_PET /* "/pet" */], + consumes = ["application/json", "application/xml"] ) - fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + fun updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -172,11 +185,15 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}"], - consumes = ["application/x-www-form-urlencoded"] - ) - fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + method = [RequestMethod.POST], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], + consumes = ["application/x-www-form-urlencoded"] + ) + fun updatePetWithForm( + @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -191,12 +208,28 @@ interface PetApi { security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], - produces = ["application/json"], - consumes = ["multipart/form-data"] - ) - fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + method = [RequestMethod.POST], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], + produces = ["application/json"], + consumes = ["multipart/form-data"] + ) + fun uploadFile( + @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/StoreApi.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/StoreApi.kt index 312e7f3d2365..f84338ca20ee 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/StoreApi.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/StoreApi.kt @@ -48,10 +48,12 @@ interface StoreApi { ] ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/store/order/{order_id}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_ORDER /* "/store/order/{order_id}" */] ) - fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("order_id") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("order_id") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -66,9 +68,9 @@ interface StoreApi { security = [ SecurityRequirement(name = "api_key") ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/inventory"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], + produces = ["application/json"] ) fun getInventory(): ResponseEntity> { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) @@ -86,11 +88,13 @@ interface StoreApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/order/{order_id}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{order_id}" */], + produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("order_id") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("order_id") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -105,12 +109,22 @@ interface StoreApi { ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/store/order"], - produces = ["application/xml", "application/json"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_PLACE_ORDER /* "/store/order" */], + produces = ["application/xml", "application/json"], + consumes = ["application/json"] ) - fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order): ResponseEntity { + fun placeOrder( + @Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_DELETE_ORDER: String = "/store/order/{order_id}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{order_id}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/UserApi.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/UserApi.kt index 101e862d02ef..7496c3fa4362 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/UserApi.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/api/UserApi.kt @@ -47,11 +47,13 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USER /* "/user" */], + consumes = ["application/json"] ) - fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + fun createUser( + @Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -65,11 +67,13 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithArray"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], + consumes = ["application/json"] ) - fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -83,11 +87,13 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithList"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], + consumes = ["application/json"] ) - fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -102,10 +108,12 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/user/{username}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -121,11 +129,13 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/{username}"], - produces = ["application/xml", "application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], + produces = ["application/xml", "application/json"] ) - fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -140,11 +150,14 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/login"], - produces = ["application/xml", "application/json"] - ) - fun loginUser(@NotNull @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + method = [RequestMethod.GET], + value = [PATH_LOGIN_USER /* "/user/login" */], + produces = ["application/xml", "application/json"] + ) + fun loginUser( + @NotNull @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } @@ -158,8 +171,8 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/logout"] + method = [RequestMethod.GET], + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) @@ -176,11 +189,26 @@ interface UserApi { ] ) @RequestMapping( - method = [RequestMethod.PUT], - value = ["/user/{username}"], - consumes = ["application/json"] - ) - fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + method = [RequestMethod.PUT], + value = [PATH_UPDATE_USER /* "/user/{username}" */], + consumes = ["application/json"] + ) + fun updateUser( + @Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String, + @Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User + ): ResponseEntity { return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiController.kt index 9f46d6767fea..c232a8585631 100644 --- a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.PetApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -34,7 +35,7 @@ import kotlin.collections.Map @RestController @Validated @Api(value = "pet", description = "The pet API") -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class PetApiController(@Autowired(required = true) val service: PetApiService) { @@ -47,10 +48,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 405, message = "Invalid input")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet"], + value = [PATH_ADD_PET /* "/pet" */], consumes = ["application/json", "application/xml"] ) - fun addPet(@ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + fun addPet( + @ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet + ): ResponseEntity { return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) } @@ -64,9 +67,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 400, message = "Invalid pet value")]) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet(@ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "") @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "") @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) } @@ -82,10 +88,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid status value")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByStatus"], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) } @@ -101,10 +109,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid tag value")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByTags"], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) } @@ -119,10 +129,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/{petId}"], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], produces = ["application/xml", "application/json"] ) - fun getPetById(@ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } @@ -136,10 +148,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found"),ApiResponse(code = 405, message = "Validation exception")]) @RequestMapping( method = [RequestMethod.PUT], - value = ["/pet"], + value = [PATH_UPDATE_PET /* "/pet" */], consumes = ["application/json", "application/xml"] ) - fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + fun updatePet( + @ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet + ): ResponseEntity { return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) } @@ -153,10 +167,14 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 405, message = "Invalid input")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}"], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@ApiParam(value = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + fun updatePetWithForm( + @ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @ApiParam(value = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) } @@ -171,11 +189,28 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], produces = ["application/json"], consumes = ["multipart/form-data"] ) - fun uploadFile(@ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@ApiParam(value = "file detail") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + fun uploadFile( + @ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @ApiParam(value = "file detail") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiController.kt index 9990c01e2d2a..1e58b22e2ca1 100644 --- a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.StoreApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -33,7 +34,7 @@ import kotlin.collections.Map @RestController @Validated @Api(value = "store", description = "The store API") -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class StoreApiController(@Autowired(required = true) val service: StoreApiService) { @@ -45,9 +46,11 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @ApiParam(value = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } @@ -63,7 +66,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/inventory"], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], produces = ["application/json"] ) fun getInventory(): ResponseEntity> { @@ -80,10 +83,12 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @ApiParam(value = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @ApiParam(value = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) } @@ -97,10 +102,21 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/store/order"], + value = [PATH_PLACE_ORDER /* "/store/order" */], produces = ["application/xml", "application/json"] ) - fun placeOrder(@ApiParam(value = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order): ResponseEntity { + fun placeOrder( + @ApiParam(value = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order + ): ResponseEntity { return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiController.kt index 5e7076f405c7..8043c5448ef0 100644 --- a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.UserApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -33,7 +34,7 @@ import kotlin.collections.Map @RestController @Validated @Api(value = "user", description = "The user API") -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class UserApiController(@Autowired(required = true) val service: UserApiService) { @@ -45,9 +46,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/user"] + value = [PATH_CREATE_USER /* "/user" */] ) - fun createUser(@ApiParam(value = "Created user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + fun createUser( + @ApiParam(value = "Created user object", required = true) @Valid @RequestBody body: User + ): ResponseEntity { return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) } @@ -60,9 +63,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithArray"] + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */] ) - fun createUsersWithArrayInput(@ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) } @@ -75,9 +80,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithList"] + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */] ) - fun createUsersWithListInput(@ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) } @@ -90,9 +97,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/user/{username}"] + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @ApiParam(value = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } @@ -106,10 +115,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation", response = User::class),ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/{username}"], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], produces = ["application/xml", "application/json"] ) - fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } @@ -123,10 +134,13 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/login"], + value = [PATH_LOGIN_USER /* "/user/login" */], produces = ["application/xml", "application/json"] ) - fun loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + fun loginUser( + @NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } @@ -139,7 +153,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/logout"] + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) @@ -154,9 +168,25 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 400, message = "Invalid user supplied"),ApiResponse(code = 404, message = "User not found")]) @RequestMapping( method = [RequestMethod.PUT], - value = ["/user/{username}"] + value = [PATH_UPDATE_USER /* "/user/{username}" */] ) - fun updateUser(@ApiParam(value = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@ApiParam(value = "Updated user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + fun updateUser( + @ApiParam(value = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String, + @ApiParam(value = "Updated user object", required = true) @Valid @RequestBody body: User + ): ResponseEntity { return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiController.kt index d227b75281a7..f13355fca1df 100644 --- a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.PetApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -31,7 +32,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class PetApiController(@Autowired(required = true) val service: PetApiService) { @Operation( @@ -44,10 +45,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet"], + value = [PATH_ADD_PET /* "/pet" */], consumes = ["application/json", "application/xml"] ) - fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + fun addPet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet + ): ResponseEntity { return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) } @@ -61,9 +64,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) } @@ -78,10 +84,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByStatus"], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) } @@ -96,10 +104,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByTags"], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) } @@ -115,10 +125,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/{petId}"], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], produces = ["application/xml", "application/json"] ) - fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } @@ -134,10 +146,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/pet"], + value = [PATH_UPDATE_PET /* "/pet" */], consumes = ["application/json", "application/xml"] ) - fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + fun updatePet( + @Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet + ): ResponseEntity { return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) } @@ -151,10 +165,14 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}"], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + fun updatePetWithForm( + @Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Parameter(description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) } @@ -168,11 +186,28 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { ) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], produces = ["application/json"], consumes = ["multipart/form-data"] ) - fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + fun uploadFile( + @Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @Parameter(description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiController.kt index a74a81d00667..d2afc77e43ae 100644 --- a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.StoreApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -30,7 +31,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class StoreApiController(@Autowired(required = true) val service: StoreApiService) { @Operation( @@ -43,9 +44,11 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } @@ -59,7 +62,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/inventory"], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], produces = ["application/json"] ) fun getInventory(): ResponseEntity> { @@ -77,10 +80,12 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) } @@ -94,10 +99,21 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic ) @RequestMapping( method = [RequestMethod.POST], - value = ["/store/order"], + value = [PATH_PLACE_ORDER /* "/store/order" */], produces = ["application/xml", "application/json"] ) - fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order): ResponseEntity { + fun placeOrder( + @Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order + ): ResponseEntity { return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiController.kt index 08160bfaf0fc..9ed8632dd6a3 100644 --- a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.UserApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -30,7 +31,7 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class UserApiController(@Autowired(required = true) val service: UserApiService) { @Operation( @@ -42,9 +43,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user"] + value = [PATH_CREATE_USER /* "/user" */] ) - fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + fun createUser( + @Parameter(description = "Created user object", required = true) @Valid @RequestBody body: User + ): ResponseEntity { return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) } @@ -57,9 +60,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithArray"] + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */] ) - fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) } @@ -72,9 +77,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithList"] + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */] ) - fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) } @@ -88,9 +95,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/user/{username}"] + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } @@ -105,10 +114,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/{username}"], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], produces = ["application/xml", "application/json"] ) - fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } @@ -122,10 +133,13 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/login"], + value = [PATH_LOGIN_USER /* "/user/login" */], produces = ["application/xml", "application/json"] ) - fun loginUser(@NotNull @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + fun loginUser( + @NotNull @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } @@ -138,7 +152,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/logout"] + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) @@ -154,9 +168,25 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) ) @RequestMapping( method = [RequestMethod.PUT], - value = ["/user/{username}"] + value = [PATH_UPDATE_USER /* "/user/{username}" */] ) - fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + fun updateUser( + @Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String, + @Parameter(description = "Updated user object", required = true) @Valid @RequestBody body: User + ): ResponseEntity { return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiController.kt index 9f46d6767fea..c232a8585631 100644 --- a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.PetApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -34,7 +35,7 @@ import kotlin.collections.Map @RestController @Validated @Api(value = "pet", description = "The pet API") -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class PetApiController(@Autowired(required = true) val service: PetApiService) { @@ -47,10 +48,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 405, message = "Invalid input")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet"], + value = [PATH_ADD_PET /* "/pet" */], consumes = ["application/json", "application/xml"] ) - fun addPet(@ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + fun addPet( + @ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet + ): ResponseEntity { return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) } @@ -64,9 +67,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 400, message = "Invalid pet value")]) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet(@ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "") @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "") @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) } @@ -82,10 +88,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid status value")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByStatus"], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) } @@ -101,10 +109,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid tag value")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByTags"], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) } @@ -119,10 +129,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/{petId}"], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], produces = ["application/xml", "application/json"] ) - fun getPetById(@ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } @@ -136,10 +148,12 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found"),ApiResponse(code = 405, message = "Validation exception")]) @RequestMapping( method = [RequestMethod.PUT], - value = ["/pet"], + value = [PATH_UPDATE_PET /* "/pet" */], consumes = ["application/json", "application/xml"] ) - fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + fun updatePet( + @ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet + ): ResponseEntity { return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) } @@ -153,10 +167,14 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 405, message = "Invalid input")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}"], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@ApiParam(value = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + fun updatePetWithForm( + @ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @ApiParam(value = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) } @@ -171,11 +189,28 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], produces = ["application/json"], consumes = ["multipart/form-data"] ) - fun uploadFile(@ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@ApiParam(value = "file detail") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + fun uploadFile( + @ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @ApiParam(value = "file detail") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiController.kt index 9990c01e2d2a..1e58b22e2ca1 100644 --- a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.StoreApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -33,7 +34,7 @@ import kotlin.collections.Map @RestController @Validated @Api(value = "store", description = "The store API") -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class StoreApiController(@Autowired(required = true) val service: StoreApiService) { @@ -45,9 +46,11 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @ApiParam(value = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } @@ -63,7 +66,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/inventory"], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], produces = ["application/json"] ) fun getInventory(): ResponseEntity> { @@ -80,10 +83,12 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @ApiParam(value = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @ApiParam(value = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) } @@ -97,10 +102,21 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/store/order"], + value = [PATH_PLACE_ORDER /* "/store/order" */], produces = ["application/xml", "application/json"] ) - fun placeOrder(@ApiParam(value = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order): ResponseEntity { + fun placeOrder( + @ApiParam(value = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order + ): ResponseEntity { return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiController.kt index 5e7076f405c7..8043c5448ef0 100644 --- a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.UserApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -33,7 +34,7 @@ import kotlin.collections.Map @RestController @Validated @Api(value = "user", description = "The user API") -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class UserApiController(@Autowired(required = true) val service: UserApiService) { @@ -45,9 +46,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/user"] + value = [PATH_CREATE_USER /* "/user" */] ) - fun createUser(@ApiParam(value = "Created user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + fun createUser( + @ApiParam(value = "Created user object", required = true) @Valid @RequestBody body: User + ): ResponseEntity { return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) } @@ -60,9 +63,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithArray"] + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */] ) - fun createUsersWithArrayInput(@ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) } @@ -75,9 +80,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation")]) @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithList"] + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */] ) - fun createUsersWithListInput(@ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) } @@ -90,9 +97,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) @RequestMapping( method = [RequestMethod.DELETE], - value = ["/user/{username}"] + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @ApiParam(value = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } @@ -106,10 +115,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation", response = User::class),ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/{username}"], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], produces = ["application/xml", "application/json"] ) - fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } @@ -123,10 +134,13 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/login"], + value = [PATH_LOGIN_USER /* "/user/login" */], produces = ["application/xml", "application/json"] ) - fun loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + fun loginUser( + @NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } @@ -139,7 +153,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation")]) @RequestMapping( method = [RequestMethod.GET], - value = ["/user/logout"] + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) @@ -154,9 +168,25 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 400, message = "Invalid user supplied"),ApiResponse(code = 404, message = "User not found")]) @RequestMapping( method = [RequestMethod.PUT], - value = ["/user/{username}"] + value = [PATH_UPDATE_USER /* "/user/{username}" */] ) - fun updateUser(@ApiParam(value = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@ApiParam(value = "Updated user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + fun updateUser( + @ApiParam(value = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String, + @ApiParam(value = "Updated user object", required = true) @Valid @RequestBody body: User + ): ResponseEntity { return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/PetApi.kt b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/PetApi.kt index e40570844574..74927d98aeb4 100644 --- a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/PetApi.kt +++ b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/PetApi.kt @@ -46,29 +46,40 @@ interface PetApi { value = "Add a new pet to the store", nickname = "addPet", notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + value = [ApiResponse(code = 405, message = "Invalid input")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_ADD_PET /* "/pet" */], + consumes = ["application/json"] ) - fun addPet(@ApiParam(value = "", required = true) @Valid @RequestBody pet: Pet, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun addPet( + @ApiParam(value = "", required = true) @Valid @RequestBody pet: Pet, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( value = "Deletes a pet", nickname = "deletePet", notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid pet value")]) + value = [ApiResponse(code = 400, message = "Invalid pet value")] + ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet(@ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "") @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun deletePet( + @ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "") @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( @@ -77,15 +88,20 @@ interface PetApi { notes = "Multiple status values can be provided with comma separated strings", response = Pet::class, responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"), ApiResponse(code = 400, message = "Invalid status value")]) + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"), ApiResponse(code = 400, message = "Invalid status value")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByStatus"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], + produces = ["application/json"] ) - fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity> + fun findPetsByStatus( + @NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity> @ApiOperation( @@ -94,15 +110,20 @@ interface PetApi { notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet::class, responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"), ApiResponse(code = 400, message = "Invalid tag value")]) + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"), ApiResponse(code = 400, message = "Invalid tag value")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/findByTags"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], + produces = ["application/json"] ) - fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity> + fun findPetsByTags( + @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity> @ApiOperation( @@ -110,45 +131,62 @@ interface PetApi { nickname = "getPetById", notes = "Returns a single pet", response = Pet::class, - authorizations = [Authorization(value = "api_key")]) + authorizations = [Authorization(value = "api_key")] + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class), ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Pet not found")]) + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class), ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Pet not found")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/pet/{petId}"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], + produces = ["application/json"] ) - fun getPetById(@ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun getPetById( + @ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( value = "Update an existing pet", nickname = "updatePet", notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Pet not found"), ApiResponse(code = 405, message = "Validation exception")]) + value = [ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Pet not found"), ApiResponse(code = 405, message = "Validation exception")] + ) @RequestMapping( - method = [RequestMethod.PUT], - value = ["/pet"], - consumes = ["application/json"] + method = [RequestMethod.PUT], + value = [PATH_UPDATE_PET /* "/pet" */], + consumes = ["application/json"] ) - fun updatePet(@ApiParam(value = "", required = true) @Valid @RequestBody pet: Pet, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun updatePet( + @ApiParam(value = "", required = true) @Valid @RequestBody pet: Pet, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( value = "Updates a pet in the store with form data", nickname = "updatePetWithForm", notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + value = [ApiResponse(code = 405, message = "Invalid input")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}"], - consumes = ["application/x-www-form-urlencoded"] + method = [RequestMethod.POST], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], + consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@ApiParam(value = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? , @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun updatePetWithForm( + @ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @ApiParam(value = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String?, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( @@ -156,14 +194,33 @@ interface PetApi { nickname = "uploadFile", notes = "", response = ModelApiResponse::class, - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])] + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) + value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], - produces = ["application/json"], - consumes = ["multipart/form-data"] + method = [RequestMethod.POST], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], + produces = ["application/json"], + consumes = ["multipart/form-data"] ) - fun uploadFile(@ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@ApiParam(value = "file detail") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun uploadFile( + @ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long, + @ApiParam(value = "") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @ApiParam(value = "file detail") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/StoreApi.kt b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/StoreApi.kt index 69b2aa749a65..40c176b58ce1 100644 --- a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/StoreApi.kt +++ b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/StoreApi.kt @@ -44,14 +44,19 @@ interface StoreApi { @ApiOperation( value = "Delete purchase order by ID", nickname = "deleteOrder", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Order not found")]) + value = [ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Order not found")] + ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder(@ApiParam(value = "", required = true) @PathVariable("orderId") orderId: kotlin.String, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun deleteOrder( + @ApiParam(value = "", required = true) @PathVariable("orderId") orderId: kotlin.String, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( @@ -60,13 +65,15 @@ interface StoreApi { notes = "", response = kotlin.Int::class, responseContainer = "Map", - authorizations = [Authorization(value = "api_key")]) + authorizations = [Authorization(value = "api_key")] + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")]) + value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/inventory"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], + produces = ["application/json"] ) fun getInventory(@ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity> @@ -75,29 +82,47 @@ interface StoreApi { value = "Find purchase order by ID", nickname = "getOrderById", notes = "", - response = Order::class) + response = Order::class + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class), ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Order not found")]) + value = [ApiResponse(code = 200, message = "successful operation", response = Order::class), ApiResponse(code = 400, message = "Invalid ID supplied"), ApiResponse(code = 404, message = "Order not found")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], + produces = ["application/json"] ) - fun getOrderById(@Min(value=1) @Max(value=5) @ApiParam(value = "", required = true) @PathVariable("orderId") orderId: kotlin.Int, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun getOrderById( + @Min(value=1) @Max(value=5) @ApiParam(value = "", required = true) @PathVariable("orderId") orderId: kotlin.Int, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( value = "Place an order for a pet", nickname = "placeOrder", notes = "", - response = Order::class) + response = Order::class + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class), ApiResponse(code = 400, message = "Invalid Order")]) + value = [ApiResponse(code = 200, message = "successful operation", response = Order::class), ApiResponse(code = 400, message = "Invalid Order")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/store/order"], - produces = ["application/json"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_PLACE_ORDER /* "/store/order" */], + produces = ["application/json"], + consumes = ["application/json"] ) - fun placeOrder(@ApiParam(value = "", required = true) @Valid @RequestBody order: Order, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun placeOrder( + @ApiParam(value = "", required = true) @Valid @RequestBody order: Order, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/UserApi.kt b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/UserApi.kt index acf9134e4931..db017f3558b1 100644 --- a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/UserApi.kt +++ b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/api/UserApi.kt @@ -44,97 +44,130 @@ interface UserApi { @ApiOperation( value = "Create user", nickname = "createUser", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + value = [ApiResponse(code = 200, message = "successful operation")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USER /* "/user" */], + consumes = ["application/json"] ) - fun createUser(@ApiParam(value = "", required = true) @Valid @RequestBody user: User, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun createUser( + @ApiParam(value = "", required = true) @Valid @RequestBody user: User, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( value = "Creates list of users with given input array", nickname = "createUsersWithArrayInput", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + value = [ApiResponse(code = 200, message = "successful operation")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithArray"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */], + consumes = ["application/json"] ) - fun createUsersWithArrayInput(@ApiParam(value = "", required = true) @Valid @RequestBody user: kotlin.collections.List, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun createUsersWithArrayInput( + @ApiParam(value = "", required = true) @Valid @RequestBody user: kotlin.collections.List, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( value = "Creates list of users with given input array", nickname = "createUsersWithListInput", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + value = [ApiResponse(code = 200, message = "successful operation")] + ) @RequestMapping( - method = [RequestMethod.POST], - value = ["/user/createWithList"], - consumes = ["application/json"] + method = [RequestMethod.POST], + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */], + consumes = ["application/json"] ) - fun createUsersWithListInput(@ApiParam(value = "", required = true) @Valid @RequestBody user: kotlin.collections.List, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun createUsersWithListInput( + @ApiParam(value = "", required = true) @Valid @RequestBody user: kotlin.collections.List, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( value = "Delete user", nickname = "deleteUser", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid username supplied"), ApiResponse(code = 404, message = "User not found")]) + value = [ApiResponse(code = 400, message = "Invalid username supplied"), ApiResponse(code = 404, message = "User not found")] + ) @RequestMapping( - method = [RequestMethod.DELETE], - value = ["/user/{username}"] + method = [RequestMethod.DELETE], + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser(@ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun deleteUser( + @ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( value = "Get user by user name", nickname = "getUserByName", notes = "", - response = User::class) + response = User::class + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = User::class), ApiResponse(code = 400, message = "Invalid username supplied"), ApiResponse(code = 404, message = "User not found")]) + value = [ApiResponse(code = 200, message = "successful operation", response = User::class), ApiResponse(code = 400, message = "Invalid username supplied"), ApiResponse(code = 404, message = "User not found")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/{username}"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], + produces = ["application/json"] ) - fun getUserByName(@ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun getUserByName( + @ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( value = "Logs user into the system", nickname = "loginUser", notes = "", - response = kotlin.String::class) + response = kotlin.String::class + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class), ApiResponse(code = 400, message = "Invalid username/password supplied")]) + value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class), ApiResponse(code = 400, message = "Invalid username/password supplied")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/login"], - produces = ["application/json"] + method = [RequestMethod.GET], + value = [PATH_LOGIN_USER /* "/user/login" */], + produces = ["application/json"] ) - fun loginUser(@NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun loginUser( + @NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity @ApiOperation( value = "Logs out current logged in user session", nickname = "logoutUser", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + value = [ApiResponse(code = 200, message = "successful operation")] + ) @RequestMapping( - method = [RequestMethod.GET], - value = ["/user/logout"] + method = [RequestMethod.GET], + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(@ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity @@ -142,13 +175,31 @@ interface UserApi { @ApiOperation( value = "Updated user", nickname = "updateUser", - notes = "") + notes = "" + ) @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid user supplied"), ApiResponse(code = 404, message = "User not found")]) + value = [ApiResponse(code = 400, message = "Invalid user supplied"), ApiResponse(code = 404, message = "User not found")] + ) @RequestMapping( - method = [RequestMethod.PUT], - value = ["/user/{username}"], - consumes = ["application/json"] + method = [RequestMethod.PUT], + value = [PATH_UPDATE_USER /* "/user/{username}" */], + consumes = ["application/json"] ) - fun updateUser(@ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String,@ApiParam(value = "", required = true) @Valid @RequestBody user: User, @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest): ResponseEntity + fun updateUser( + @ApiParam(value = "", required = true) @PathVariable("username") username: kotlin.String, + @ApiParam(value = "", required = true) @Valid @RequestBody user: User, + @ApiParam(hidden = true) request: javax.servlet.http.HttpServletRequest + ): ResponseEntity + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiController.kt index e704691f8020..10f3825dec2b 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.PetApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -26,86 +27,120 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class PetApiController(@Autowired(required = true) val service: PetApiService) { @RequestMapping( method = [RequestMethod.POST], - value = ["/pet"], + value = [PATH_ADD_PET /* "/pet" */], consumes = ["application/json", "application/xml"] ) - fun addPet( @Valid @RequestBody body: Pet): ResponseEntity { + fun addPet( + @Valid @RequestBody body: Pet + ): ResponseEntity { return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) } @RequestMapping( method = [RequestMethod.DELETE], - value = ["/pet/{petId}"] + value = [PATH_DELETE_PET /* "/pet/{petId}" */] ) - fun deletePet( @PathVariable("petId") petId: kotlin.Long, @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + fun deletePet( + @PathVariable("petId") petId: kotlin.Long, + @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByStatus"], + value = [PATH_FIND_PETS_BY_STATUS /* "/pet/findByStatus" */], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + fun findPetsByStatus( + @NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/findByTags"], + value = [PATH_FIND_PETS_BY_TAGS /* "/pet/findByTags" */], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + fun findPetsByTags( + @NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/pet/{petId}"], + value = [PATH_GET_PET_BY_ID /* "/pet/{petId}" */], produces = ["application/xml", "application/json"] ) - fun getPetById( @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + fun getPetById( + @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.PUT], - value = ["/pet"], + value = [PATH_UPDATE_PET /* "/pet" */], consumes = ["application/json", "application/xml"] ) - fun updatePet( @Valid @RequestBody body: Pet): ResponseEntity { + fun updatePet( + @Valid @RequestBody body: Pet + ): ResponseEntity { return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}"], + value = [PATH_UPDATE_PET_WITH_FORM /* "/pet/{petId}" */], consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm( @PathVariable("petId") petId: kotlin.Long, @Valid @RequestParam(value = "name", required = false) name: kotlin.String? , @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + fun updatePetWithForm( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/pet/{petId}/uploadImage"], + value = [PATH_UPLOAD_FILE /* "/pet/{petId}/uploadImage" */], produces = ["application/json"], consumes = ["multipart/form-data"] ) - fun uploadFile( @PathVariable("petId") petId: kotlin.Long, @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? , @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile): ResponseEntity { + fun uploadFile( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApiController.kt index 61477d325bfb..535986139adf 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.StoreApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -25,22 +26,24 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class StoreApiController(@Autowired(required = true) val service: StoreApiService) { @RequestMapping( method = [RequestMethod.DELETE], - value = ["/store/order/{orderId}"] + value = [PATH_DELETE_ORDER /* "/store/order/{orderId}" */] ) - fun deleteOrder( @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + fun deleteOrder( + @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/store/inventory"], + value = [PATH_GET_INVENTORY /* "/store/inventory" */], produces = ["application/json"] ) fun getInventory(): ResponseEntity> { @@ -50,20 +53,33 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic @RequestMapping( method = [RequestMethod.GET], - value = ["/store/order/{orderId}"], + value = [PATH_GET_ORDER_BY_ID /* "/store/order/{orderId}" */], produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + fun getOrderById( + @Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/store/order"], + value = [PATH_PLACE_ORDER /* "/store/order" */], produces = ["application/xml", "application/json"] ) - fun placeOrder( @Valid @RequestBody body: Order): ResponseEntity { + fun placeOrder( + @Valid @RequestBody body: Order + ): ResponseEntity { return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApiController.kt index daf5c943c2ec..a0e2d0504b67 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.* import org.springframework.validation.annotation.Validated import org.springframework.web.context.request.NativeWebRequest import org.springframework.beans.factory.annotation.Autowired +import org.openapitools.api.UserApiController.Companion.BASE_PATH import javax.validation.Valid import javax.validation.constraints.DecimalMax @@ -25,69 +26,82 @@ import kotlin.collections.Map @RestController @Validated -@RequestMapping("\${api.base-path:/v2}") +@RequestMapping("\${api.openAPIPetstore.base-path:api.base-path:$BASE_PATH}") class UserApiController(@Autowired(required = true) val service: UserApiService) { @RequestMapping( method = [RequestMethod.POST], - value = ["/user"] + value = [PATH_CREATE_USER /* "/user" */] ) - fun createUser( @Valid @RequestBody body: User): ResponseEntity { + fun createUser( + @Valid @RequestBody body: User + ): ResponseEntity { return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithArray"] + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT /* "/user/createWithArray" */] ) - fun createUsersWithArrayInput( @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + fun createUsersWithArrayInput( + @Valid @RequestBody body: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.POST], - value = ["/user/createWithList"] + value = [PATH_CREATE_USERS_WITH_LIST_INPUT /* "/user/createWithList" */] ) - fun createUsersWithListInput( @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + fun createUsersWithListInput( + @Valid @RequestBody body: kotlin.collections.List + ): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.DELETE], - value = ["/user/{username}"] + value = [PATH_DELETE_USER /* "/user/{username}" */] ) - fun deleteUser( @PathVariable("username") username: kotlin.String): ResponseEntity { + fun deleteUser( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/user/{username}"], + value = [PATH_GET_USER_BY_NAME /* "/user/{username}" */], produces = ["application/xml", "application/json"] ) - fun getUserByName( @PathVariable("username") username: kotlin.String): ResponseEntity { + fun getUserByName( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/user/login"], + value = [PATH_LOGIN_USER /* "/user/login" */], produces = ["application/xml", "application/json"] ) - fun loginUser(@NotNull @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + fun loginUser( + @NotNull @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } @RequestMapping( method = [RequestMethod.GET], - value = ["/user/logout"] + value = [PATH_LOGOUT_USER /* "/user/logout" */] ) fun logoutUser(): ResponseEntity { return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) @@ -96,9 +110,25 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) @RequestMapping( method = [RequestMethod.PUT], - value = ["/user/{username}"] + value = [PATH_UPDATE_USER /* "/user/{username}" */] ) - fun updateUser( @PathVariable("username") username: kotlin.String, @Valid @RequestBody body: User): ResponseEntity { + fun updateUser( + @PathVariable("username") username: kotlin.String, + @Valid @RequestBody body: User + ): ResponseEntity { return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "/v2" + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } }