diff --git a/.github/workflows/samples-kotlin-server.yaml b/.github/workflows/samples-kotlin-server.yaml index 7721fbd44a3..67c7de89fe7 100644 --- a/.github/workflows/samples-kotlin-server.yaml +++ b/.github/workflows/samples-kotlin-server.yaml @@ -34,6 +34,8 @@ jobs: - samples/server/petstore/kotlin-springboot-delegate - samples/server/petstore/kotlin-springboot-modelMutable - samples/server/petstore/kotlin-springboot-reactive + - samples/server/petstore/kotlin-springboot-reactive-with-flow + - samples/server/petstore/kotlin-springboot-reactive-without-flow - samples/server/petstore/kotlin-springboot-source-swagger1 - samples/server/petstore/kotlin-springboot-source-swagger2 - samples/server/petstore/kotlin-springboot-springfox diff --git a/bin/configs/kotlin-spring-boot-reactive-with-flow.yaml b/bin/configs/kotlin-spring-boot-reactive-with-flow.yaml new file mode 100644 index 00000000000..f6eb67feb5e --- /dev/null +++ b/bin/configs/kotlin-spring-boot-reactive-with-flow.yaml @@ -0,0 +1,13 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-springboot-reactive-with-flow +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: springdoc + annotationLibrary: swagger2 + useSwaggerUI: "true" + serviceImplementation: "true" + reactive: "true" + beanValidations: "true" + useFlowForArrayReturnType: "true" diff --git a/bin/configs/kotlin-spring-boot-reactive-without-flow.yaml b/bin/configs/kotlin-spring-boot-reactive-without-flow.yaml new file mode 100644 index 00000000000..e2988c675d1 --- /dev/null +++ b/bin/configs/kotlin-spring-boot-reactive-without-flow.yaml @@ -0,0 +1,13 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-springboot-reactive-without-flow +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: springdoc + annotationLibrary: swagger2 + useSwaggerUI: "true" + serviceImplementation: "true" + reactive: "true" + beanValidations: "true" + useFlowForArrayReturnType: "false" diff --git a/docs/generators/kotlin-spring.md b/docs/generators/kotlin-spring.md index 5aa6a24c2f6..195c51460ef 100644 --- a/docs/generators/kotlin-spring.md +++ b/docs/generators/kotlin-spring.md @@ -52,6 +52,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |title|server title name or client service name| |OpenAPI Kotlin Spring| |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| |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 6a483ca6e8d..ea0c6c4e60f 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 @@ -105,6 +105,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen public static final String BEAN_QUALIFIERS = "beanQualifiers"; public static final String USE_SPRING_BOOT3 = "useSpringBoot3"; + public static final String USE_FLOW_FOR_ARRAY_RETURN_TYPE = "useFlowForArrayReturnType"; public static final String REQUEST_MAPPING_OPTION = "requestMappingMode"; public static final String USE_REQUEST_MAPPING_ON_CONTROLLER = "useRequestMappingOnController"; public static final String USE_REQUEST_MAPPING_ON_INTERFACE = "useRequestMappingOnInterface"; @@ -145,6 +146,8 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen @Setter private boolean serviceImplementation = false; @Getter @Setter private boolean reactive = false; + @Getter @Setter + private boolean useFlowForArrayReturnType = true; @Setter private boolean interfaceOnly = false; @Setter protected boolean useFeignClientUrl = true; @Setter protected boolean useFeignClient = false; @@ -235,6 +238,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen "@RestController annotations. May be used to prevent bean names clash if multiple generated libraries" + " (contexts) added to single project.", beanQualifiers); 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); supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application."); supportedLibraries.put(SPRING_CLOUD_LIBRARY, "Spring-Cloud-Feign client with Spring-Boot auto-configured settings."); @@ -527,10 +531,15 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen this.setReactive(convertPropertyToBoolean(REACTIVE)); // spring webflux doesn't support @ControllerAdvice this.setExceptionHandler(false); + + if (additionalProperties.containsKey(USE_FLOW_FOR_ARRAY_RETURN_TYPE)) { + this.setUseFlowForArrayReturnType(convertPropertyToBoolean(USE_FLOW_FOR_ARRAY_RETURN_TYPE)); + } } } writePropertyBack(REACTIVE, reactive); writePropertyBack(EXCEPTION_HANDLER, exceptionHandler); + writePropertyBack(USE_FLOW_FOR_ARRAY_RETURN_TYPE, useFlowForArrayReturnType); if (additionalProperties.containsKey(BEAN_QUALIFIERS) && library.equals(SPRING_BOOT)) { this.setBeanQualifiers(convertPropertyToBoolean(BEAN_QUALIFIERS)); @@ -685,7 +694,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen supportingFiles.add(new SupportingFile("buildGradleKts.mustache", "build.gradle.kts")); } supportingFiles.add(new SupportingFile("settingsGradle.mustache", "settings.gradle")); - + String gradleWrapperPackage = "gradle.wrapper"; supportingFiles.add(new SupportingFile("gradlew.mustache", "", "gradlew")); supportingFiles.add(new SupportingFile("gradlew.bat.mustache", "", "gradlew.bat")); diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/returnTypes.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/returnTypes.mustache index 12a74e5ad7a..612aa9ec059 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/returnTypes.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/returnTypes.mustache @@ -1 +1 @@ -{{#isMap}}Map{{/isMap}}{{#isArray}}{{#reactive}}Flow{{/reactive}}{{^reactive}}{{{returnContainer}}}{{/reactive}}<{{{returnType}}}>{{/isArray}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}} \ No newline at end of file +{{#isMap}}Map{{/isMap}}{{#isArray}}{{#reactive}}{{#useFlowForArrayReturnType}}Flow{{/useFlowForArrayReturnType}}{{^useFlowForArrayReturnType}}{{{returnContainer}}}{{/useFlowForArrayReturnType}}{{/reactive}}{{^reactive}}{{{returnContainer}}}{{/reactive}}<{{{returnType}}}>{{/isArray}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}} \ No newline at end of file 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 f579e593344..546e1582dac 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 @@ -911,4 +911,230 @@ public class KotlinSpringServerCodegenTest { "private const val serialVersionUID: kotlin.Long = 1" ); } + + @Test + public void reactiveWithoutFlow() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + codegen.additionalProperties().put(KotlinSpringServerCodegen.REACTIVE, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_FLOW_FOR_ARRAY_RETURN_TYPE, false); + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_TAGS, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVICE_IMPLEMENTATION, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.DELEGATE_PATTERN, true); + + List files = new DefaultGenerator() + .opts( + new ClientOptInput() + .openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue16130-add-useFlowForArrayReturnType-param.yaml")) + .config(codegen) + ) + .generate(); + + Assertions.assertThat(files).contains( + new File(output, "src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiService.kt") + ); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"), + "Flow"); + + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + "List"); + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + "Flow"); + + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + "List"); + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + "Flow"); + + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"), + "List"); + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"), + "Flow"); + } + + @Test + public void reactiveWithFlow() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + codegen.additionalProperties().put(KotlinSpringServerCodegen.REACTIVE, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_FLOW_FOR_ARRAY_RETURN_TYPE, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_TAGS, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVICE_IMPLEMENTATION, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.DELEGATE_PATTERN, true); + + List files = new DefaultGenerator() + .opts( + new ClientOptInput() + .openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue16130-add-useFlowForArrayReturnType-param.yaml")) + .config(codegen) + ) + .generate(); + + Assertions.assertThat(files).contains( + new File(output, "src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiService.kt") + ); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"), + "List"); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + "List"); + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + "Flow"); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + "List"); + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + "Flow"); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"), + "List"); + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"), + "Flow"); + } + + @Test + public void reactiveWithDefaultValueFlow() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + codegen.additionalProperties().put(KotlinSpringServerCodegen.REACTIVE, true); + // should use default 'true' instead + // codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_FLOW_FOR_ARRAY_RETURN_TYPE, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_TAGS, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVICE_IMPLEMENTATION, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.DELEGATE_PATTERN, true); + + List files = new DefaultGenerator() + .opts( + new ClientOptInput() + .openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue16130-add-useFlowForArrayReturnType-param.yaml")) + .config(codegen) + ) + .generate(); + + Assertions.assertThat(files).contains( + new File(output, "src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiService.kt") + ); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"), + "List"); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + "List"); + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + "Flow"); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + "List"); + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + "Flow"); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"), + "List"); + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"), + "Flow"); + } + + @Test + public void nonReactiveWithoutFlow() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + codegen.additionalProperties().put(KotlinSpringServerCodegen.REACTIVE, false); + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_FLOW_FOR_ARRAY_RETURN_TYPE, false); + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_TAGS, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVICE_IMPLEMENTATION, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.DELEGATE_PATTERN, true); + + List files = new DefaultGenerator() + .opts( + new ClientOptInput() + .openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue16130-add-useFlowForArrayReturnType-param.yaml")) + .config(codegen) + ) + .generate(); + + Assertions.assertThat(files).contains( + new File(output, "src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiService.kt") + ); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"), + "Flow"); + + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + "List"); + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + "Flow"); + + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + "List"); + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + "Flow"); + + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"), + "List"); + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"), + "Flow"); + } + + @Test + public void nonReactiveWithFlow() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + codegen.additionalProperties().put(KotlinSpringServerCodegen.REACTIVE, false); + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_FLOW_FOR_ARRAY_RETURN_TYPE, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_TAGS, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVICE_IMPLEMENTATION, true); + codegen.additionalProperties().put(KotlinSpringServerCodegen.DELEGATE_PATTERN, true); + + List files = new DefaultGenerator() + .opts( + new ClientOptInput() + .openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue16130-add-useFlowForArrayReturnType-param.yaml")) + .config(codegen) + ) + .generate(); + + Assertions.assertThat(files).contains( + new File(output, "src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiService.kt") + ); + + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"), + "Flow"); + + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + "List"); + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"), + "Flow"); + + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + "List"); + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"), + "Flow"); + + assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"), + "List"); + assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiService.kt"), + "Flow"); + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/kotlin/issue16130-add-useFlowForArrayReturnType-param.yaml b/modules/openapi-generator/src/test/resources/3_0/kotlin/issue16130-add-useFlowForArrayReturnType-param.yaml new file mode 100644 index 00000000000..4ec1c61f7f4 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/kotlin/issue16130-add-useFlowForArrayReturnType-param.yaml @@ -0,0 +1,20 @@ +openapi: "3.0.1" +info: + title: test + version: "1.0" + +paths: + + /api/v1/test: + get: + tags: [Test v1] + operationId: test1 + responses: + '200': + description: OK + content: + application/json: + schema: + type: array + items: + type: string diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/.openapi-generator-ignore b/samples/server/petstore/kotlin-springboot-reactive-with-flow/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/.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-reactive-with-flow/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-reactive-with-flow/.openapi-generator/FILES new file mode 100644 index 00000000000..7b4efc03051 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/.openapi-generator/FILES @@ -0,0 +1,28 @@ +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/HomeController.kt +src/main/kotlin/org/openapitools/api/ApiUtil.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 +src/main/resources/openapi.yaml diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/.openapi-generator/VERSION b/samples/server/petstore/kotlin-springboot-reactive-with-flow/.openapi-generator/VERSION new file mode 100644 index 00000000000..88411912639 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.11.0-SNAPSHOT diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/README.md b/samples/server/petstore/kotlin-springboot-reactive-with-flow/README.md new file mode 100644 index 00000000000..b6865a08113 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/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-reactive-with-flow/build.gradle.kts b/samples/server/petstore/kotlin-springboot-reactive-with-flow/build.gradle.kts new file mode 100644 index 00000000000..568be3488b1 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/build.gradle.kts @@ -0,0 +1,53 @@ +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 = "1.8" +} + +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 { + val kotlinxCoroutinesVersion = "1.6.1" + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion") + implementation("org.springdoc:springdoc-openapi-webflux-ui:1.6.8") + + 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") + } + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesVersion") +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/gradle/wrapper/gradle-wrapper.jar b/samples/server/petstore/kotlin-springboot-reactive-with-flow/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..e6441136f3d Binary files /dev/null and b/samples/server/petstore/kotlin-springboot-reactive-with-flow/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-springboot-reactive-with-flow/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..80187ac3043 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/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-reactive-with-flow/gradlew b/samples/server/petstore/kotlin-springboot-reactive-with-flow/gradlew new file mode 100644 index 00000000000..9d0ce634cb1 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/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-reactive-with-flow/gradlew.bat b/samples/server/petstore/kotlin-springboot-reactive-with-flow/gradlew.bat new file mode 100644 index 00000000000..25da30dbdee --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/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-reactive-with-flow/pom.xml b/samples/server/petstore/kotlin-springboot-reactive-with-flow/pom.xml new file mode 100644 index 00000000000..f555dc75a07 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/pom.xml @@ -0,0 +1,147 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 1.6.1 + 1.6.8 + 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 + + 1.8 + + + + 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-webflux + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + ${kotlinx-coroutines.version} + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + ${kotlinx-coroutines.version} + + + + + org.springdoc + springdoc-openapi-webflux-ui + ${springdoc-openapi.version} + + + + + 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-reactive-with-flow/settings.gradle b/samples/server/petstore/kotlin-springboot-reactive-with-flow/settings.gradle new file mode 100644 index 00000000000..14844905cd4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/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-reactive-with-flow/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/Application.kt new file mode 100644 index 00000000000..2fe6de62479 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/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-reactive-with-flow/src/main/kotlin/org/openapitools/HomeController.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/HomeController.kt new file mode 100644 index 00000000000..78f8cce7d83 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/HomeController.kt @@ -0,0 +1,26 @@ +package org.openapitools + +import org.springframework.context.annotation.Bean +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.reactive.function.server.HandlerFunction +import org.springframework.web.reactive.function.server.RequestPredicates.GET +import org.springframework.web.reactive.function.server.RouterFunction +import org.springframework.web.reactive.function.server.RouterFunctions.route +import org.springframework.web.reactive.function.server.ServerResponse +import java.net.URI + +/** + * Home redirection to OpenAPI api documentation + */ +@Controller +class HomeController { + + @Bean + fun index(): RouterFunction = route( + GET("/"), HandlerFunction { + ServerResponse.temporaryRedirect(URI.create("swagger-ui.html")).build() + }) +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 00000000000..7c275cbf30e --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,5 @@ +package org.openapitools.api + + +object ApiUtil { +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/PetApiController.kt new file mode 100644 index 00000000000..a2263f9ac22 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -0,0 +1,183 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import io.swagger.v3.oas.annotations.* +import io.swagger.v3.oas.annotations.enums.* +import io.swagger.v3.oas.annotations.media.* +import io.swagger.v3.oas.annotations.responses.* +import io.swagger.v3.oas.annotations.security.* +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 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 kotlinx.coroutines.flow.Flow +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@RequestMapping("\${api.base-path:/v2}") +class PetApiController(@Autowired(required = true) val service: PetApiService) { + + @Operation( + summary = "Add a new pet to the store", + operationId = "addPet", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "405", description = "Invalid input") ], + 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"] + ) + 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)) + } + + @Operation( + summary = "Deletes a pet", + operationId = "deletePet", + description = """""", + responses = [ + ApiResponse(responseCode = "400", description = "Invalid pet value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/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 { + return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) + } + + @Operation( + summary = "Finds Pets by status", + operationId = "findPetsByStatus", + description = """Multiple status values can be provided with comma separated strings""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(array = ArraySchema(schema = Schema(implementation = Pet::class)))]), + ApiResponse(responseCode = "400", description = "Invalid status value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/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> { + return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Finds Pets by tags", + operationId = "findPetsByTags", + description = """Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(array = ArraySchema(schema = Schema(implementation = Pet::class)))]), + ApiResponse(responseCode = "400", description = "Invalid tag value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/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> { + return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Find pet by ID", + operationId = "getPetById", + description = """Returns a single pet""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + ApiResponse(responseCode = "404", description = "Pet not found") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/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 { + return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Update an existing pet", + operationId = "updatePet", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + ApiResponse(responseCode = "404", description = "Pet not found"), + ApiResponse(responseCode = "405", description = "Validation exception") ], + 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"] + ) + 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)) + } + + @Operation( + summary = "Updates a pet in the store with form data", + operationId = "updatePetWithForm", + description = """""", + responses = [ + ApiResponse(responseCode = "405", description = "Invalid input") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/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") @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) + } + + @Operation( + summary = "uploads an image", + operationId = "uploadFile", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = ModelApiResponse::class))]) ], + 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"] + ) + 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") @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)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/PetApiService.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/PetApiService.kt new file mode 100644 index 00000000000..29ff5bc8561 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/PetApiService.kt @@ -0,0 +1,104 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import kotlinx.coroutines.flow.Flow + +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 + */ + suspend 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 + */ + suspend 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): Flow + + /** + * 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): Flow + + /** + * 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.web.multipart.MultipartFile?): ModelApiResponse +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt new file mode 100644 index 00000000000..58b6df4cc09 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt @@ -0,0 +1,41 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import kotlinx.coroutines.flow.Flow +import org.springframework.stereotype.Service +@Service +class PetApiServiceImpl : PetApiService { + + override suspend fun addPet(pet: Pet): Pet { + TODO("Implement me") + } + + override suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun findPetsByStatus(status: kotlin.collections.List): Flow { + TODO("Implement me") + } + + override fun findPetsByTags(tags: kotlin.collections.List): Flow { + TODO("Implement me") + } + + override suspend fun getPetById(petId: kotlin.Long): Pet { + TODO("Implement me") + } + + override suspend fun updatePet(pet: Pet): Pet { + TODO("Implement me") + } + + override suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit { + TODO("Implement me") + } + + override suspend 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-reactive-with-flow/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/StoreApiController.kt new file mode 100644 index 00000000000..d376c35f159 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -0,0 +1,105 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import io.swagger.v3.oas.annotations.* +import io.swagger.v3.oas.annotations.enums.* +import io.swagger.v3.oas.annotations.media.* +import io.swagger.v3.oas.annotations.responses.* +import io.swagger.v3.oas.annotations.security.* +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 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 kotlinx.coroutines.flow.Flow +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@RequestMapping("\${api.base-path:/v2}") +class StoreApiController(@Autowired(required = true) val service: StoreApiService) { + + @Operation( + summary = "Delete purchase order by ID", + operationId = "deleteOrder", + description = """For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors""", + responses = [ + ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + ApiResponse(responseCode = "404", description = "Order not found") ] + ) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/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 { + return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) + } + + @Operation( + summary = "Returns pet inventories by status", + operationId = "getInventory", + description = """Returns a map of status codes to quantities""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = kotlin.collections.Map::class))]) ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/store/inventory"], + produces = ["application/json"] + ) + suspend fun getInventory(): ResponseEntity> { + return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Find purchase order by ID", + operationId = "getOrderById", + description = """For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Order::class))]), + ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + ApiResponse(responseCode = "404", description = "Order not found") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/store/order/{orderId}"], + produces = ["application/xml", "application/json"] + ) + suspend fun getOrderById(@Min(1L) @Max(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)) + } + + @Operation( + summary = "Place an order for a pet", + operationId = "placeOrder", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Order::class))]), + ApiResponse(responseCode = "400", description = "Invalid Order") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/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 { + return ResponseEntity(service.placeOrder(order), HttpStatus.valueOf(200)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/StoreApiService.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/StoreApiService.kt new file mode 100644 index 00000000000..ca81edd9f2b --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/StoreApiService.kt @@ -0,0 +1,50 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import kotlinx.coroutines.flow.Flow + +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 + */ + suspend 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend fun placeOrder(order: Order): Order +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt new file mode 100644 index 00000000000..243487f52b7 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt @@ -0,0 +1,24 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import kotlinx.coroutines.flow.Flow +import org.springframework.stereotype.Service +@Service +class StoreApiServiceImpl : StoreApiService { + + override suspend fun deleteOrder(orderId: kotlin.String): Unit { + TODO("Implement me") + } + + override suspend fun getInventory(): Map { + TODO("Implement me") + } + + override suspend fun getOrderById(orderId: kotlin.Long): Order { + TODO("Implement me") + } + + override suspend fun placeOrder(order: Order): Order { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/UserApiController.kt new file mode 100644 index 00000000000..8884b2a1a70 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -0,0 +1,173 @@ +package org.openapitools.api + +import org.openapitools.model.User +import io.swagger.v3.oas.annotations.* +import io.swagger.v3.oas.annotations.enums.* +import io.swagger.v3.oas.annotations.media.* +import io.swagger.v3.oas.annotations.responses.* +import io.swagger.v3.oas.annotations.security.* +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 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 kotlinx.coroutines.flow.Flow +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@RequestMapping("\${api.base-path:/v2}") +class UserApiController(@Autowired(required = true) val service: UserApiService) { + + @Operation( + summary = "Create user", + operationId = "createUser", + description = """This can only be done by the logged in user.""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user"], + consumes = ["application/json"] + ) + suspend fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + return ResponseEntity(service.createUser(user), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Creates list of users with given input array", + operationId = "createUsersWithArrayInput", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user/createWithArray"], + consumes = ["application/json"] + ) + suspend fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow): ResponseEntity { + return ResponseEntity(service.createUsersWithArrayInput(user), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Creates list of users with given input array", + operationId = "createUsersWithListInput", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user/createWithList"], + consumes = ["application/json"] + ) + suspend fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow): ResponseEntity { + return ResponseEntity(service.createUsersWithListInput(user), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Delete user", + operationId = "deleteUser", + description = """This can only be done by the logged in user.""", + responses = [ + ApiResponse(responseCode = "400", description = "Invalid username supplied"), + ApiResponse(responseCode = "404", description = "User not found") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/user/{username}"] + ) + 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)) + } + + @Operation( + summary = "Get user by user name", + operationId = "getUserByName", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = User::class))]), + ApiResponse(responseCode = "400", description = "Invalid username supplied"), + ApiResponse(responseCode = "404", description = "User not found") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/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 { + return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Logs user into the system", + operationId = "loginUser", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = kotlin.String::class))]), + ApiResponse(responseCode = "400", description = "Invalid username/password supplied") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/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 { + return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Logs out current logged in user session", + operationId = "logoutUser", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/user/logout"] + ) + suspend fun logoutUser(): ResponseEntity { + return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Updated user", + operationId = "updateUser", + description = """This can only be done by the logged in user.""", + responses = [ + ApiResponse(responseCode = "400", description = "Invalid user supplied"), + ApiResponse(responseCode = "404", description = "User not found") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.PUT], + value = ["/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 { + return ResponseEntity(service.updateUser(username, user), HttpStatus.valueOf(400)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/UserApiService.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/UserApiService.kt new file mode 100644 index 00000000000..c166f1ff0d0 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/UserApiService.kt @@ -0,0 +1,93 @@ +package org.openapitools.api + +import org.openapitools.model.User +import kotlinx.coroutines.flow.Flow + +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 + */ + suspend 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 + */ + suspend fun createUsersWithArrayInput(user: Flow): 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 + */ + suspend fun createUsersWithListInput(user: Flow): 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend fun updateUser(username: kotlin.String, user: User): Unit +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt new file mode 100644 index 00000000000..c6c248ccfa0 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt @@ -0,0 +1,40 @@ +package org.openapitools.api + +import org.openapitools.model.User +import kotlinx.coroutines.flow.Flow +import org.springframework.stereotype.Service +@Service +class UserApiServiceImpl : UserApiService { + + override suspend fun createUser(user: User): Unit { + TODO("Implement me") + } + + override suspend fun createUsersWithArrayInput(user: Flow): Unit { + TODO("Implement me") + } + + override suspend fun createUsersWithListInput(user: Flow): Unit { + TODO("Implement me") + } + + override suspend fun deleteUser(username: kotlin.String): Unit { + TODO("Implement me") + } + + override suspend fun getUserByName(username: kotlin.String): User { + TODO("Implement me") + } + + override suspend fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String { + TODO("Implement me") + } + + override suspend fun logoutUser(): Unit { + TODO("Implement me") + } + + override suspend fun updateUser(username: kotlin.String, user: User): Unit { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Category.kt new file mode 100644 index 00000000000..0ca76806b7c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Category.kt @@ -0,0 +1,32 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +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 io.swagger.v3.oas.annotations.media.Schema + +/** + * A category for a pet + * @param id + * @param name + */ +data class Category( + + @Schema(example = "null", description = "") + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") + @Schema(example = "null", description = "") + @get:JsonProperty("name") val name: kotlin.String? = null + ) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt new file mode 100644 index 00000000000..b5a7eaeb711 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt @@ -0,0 +1,35 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +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 io.swagger.v3.oas.annotations.media.Schema + +/** + * Describes the result of uploading an image resource + * @param code + * @param type + * @param message + */ +data class ModelApiResponse( + + @Schema(example = "null", description = "") + @get:JsonProperty("code") val code: kotlin.Int? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("type") val type: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("message") val message: kotlin.String? = null + ) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Order.kt new file mode 100644 index 00000000000..55ccdbd9aad --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Order.kt @@ -0,0 +1,68 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +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 io.swagger.v3.oas.annotations.media.Schema + +/** + * 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( + + @Schema(example = "null", description = "") + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("petId") val petId: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("quantity") val quantity: kotlin.Int? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, + + @Schema(example = "null", description = "Order Status") + @get:JsonProperty("status") val status: Order.Status? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("complete") val complete: kotlin.Boolean? = false + ) { + + /** + * 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().first{it -> it.value == value} + } + } + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Pet.kt new file mode 100644 index 00000000000..66c6a74d15d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Pet.kt @@ -0,0 +1,73 @@ +package org.openapitools.model + +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 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 io.swagger.v3.oas.annotations.media.Schema + +/** + * 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( + + @Schema(example = "doggie", required = true, description = "") + @get:JsonProperty("name", required = true) val name: kotlin.String, + + @Schema(example = "null", required = true, description = "") + @get:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, + + @Schema(example = "null", description = "") + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @field:Valid + @Schema(example = "null", description = "") + @get:JsonProperty("category") val category: Category? = null, + + @field:Valid + @Schema(example = "null", description = "") + @get:JsonProperty("tags") val tags: kotlin.collections.List? = null, + + @Schema(example = "null", description = "pet status in the store") + @Deprecated(message = "") + @get:JsonProperty("status") val status: Pet.Status? = null + ) { + + /** + * 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().first{it -> it.value == value} + } + } + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Tag.kt new file mode 100644 index 00000000000..02b9a52259c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/Tag.kt @@ -0,0 +1,31 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +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 io.swagger.v3.oas.annotations.media.Schema + +/** + * A tag for a pet + * @param id + * @param name + */ +data class Tag( + + @Schema(example = "null", description = "") + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("name") val name: kotlin.String? = null + ) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/User.kt new file mode 100644 index 00000000000..e69df97f3f4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/kotlin/org/openapitools/model/User.kt @@ -0,0 +1,55 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +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 io.swagger.v3.oas.annotations.media.Schema + +/** + * 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( + + @Schema(example = "null", description = "") + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("username") val username: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("firstName") val firstName: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("lastName") val lastName: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("email") val email: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("password") val password: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("phone") val phone: kotlin.String? = null, + + @Schema(example = "null", description = "User Status") + @get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null + ) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/resources/application.yaml b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/resources/application.yaml new file mode 100644 index 00000000000..8e2ebcde976 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/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-reactive-with-flow/src/main/resources/openapi.yaml b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/resources/openapi.yaml new file mode 100644 index 00000000000..9a95adaefff --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/main/resources/openapi.yaml @@ -0,0 +1,811 @@ +openapi: 3.0.0 +info: + description: "This is a sample server Petstore server. For this sample, you can\ + \ use the api key `special-key` to test the authorization filters." + license: + name: Apache-2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html + title: OpenAPI Petstore + version: 1.0.0 +externalDocs: + description: Find out more about Swagger + url: http://swagger.io +servers: +- url: http://petstore.swagger.io/v2 +tags: +- description: Everything about your Pets + name: pet +- description: Access to Petstore orders + name: store +- description: Operations about user + name: user +paths: + /pet: + post: + description: "" + operationId: addPet + requestBody: + $ref: '#/components/requestBodies/Pet' + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "405": + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + put: + description: "" + externalDocs: + description: API documentation for the updatePet operation + url: http://petstore.swagger.io/v2/doc/updatePet + operationId: updatePet + requestBody: + $ref: '#/components/requestBodies/Pet' + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + "405": + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + /pet/findByStatus: + get: + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - deprecated: true + description: Status values that need to be considered for filter + explode: false + in: query + name: status + required: true + schema: + items: + default: available + enum: + - available + - pending + - sold + type: string + type: array + style: form + responses: + "200": + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + "400": + description: Invalid status value + security: + - petstore_auth: + - read:pets + summary: Finds Pets by status + tags: + - pet + /pet/findByTags: + get: + deprecated: true + description: "Multiple tags can be provided with comma separated strings. Use\ + \ tag1, tag2, tag3 for testing." + operationId: findPetsByTags + parameters: + - description: Tags to filter by + explode: false + in: query + name: tags + required: true + schema: + items: + type: string + type: array + style: form + responses: + "200": + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + "400": + description: Invalid tag value + security: + - petstore_auth: + - read:pets + summary: Finds Pets by tags + tags: + - pet + /pet/{petId}: + delete: + description: "" + operationId: deletePet + parameters: + - explode: false + in: header + name: api_key + required: false + schema: + type: string + style: simple + - description: Pet id to delete + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "400": + description: Invalid pet value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Deletes a pet + tags: + - pet + get: + description: Returns a single pet + operationId: getPetById + parameters: + - description: ID of pet to return + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + tags: + - pet + post: + description: "" + operationId: updatePetWithForm + parameters: + - description: ID of pet that needs to be updated + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/updatePetWithForm_request' + responses: + "405": + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Updates a pet in the store with form data + tags: + - pet + /pet/{petId}/uploadImage: + post: + description: "" + operationId: uploadFile + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/uploadFile_request' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an image + tags: + - pet + /store/inventory: + get: + description: Returns a map of status codes to quantities + operationId: getInventory + responses: + "200": + content: + application/json: + schema: + additionalProperties: + format: int32 + type: integer + type: object + description: successful operation + security: + - api_key: [] + summary: Returns pet inventories by status + tags: + - store + /store/order: + post: + description: "" + operationId: placeOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + required: true + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + description: Invalid Order + summary: Place an order for a pet + tags: + - store + /store/order/{orderId}: + delete: + description: For valid response try integer IDs with value < 1000. Anything + above 1000 or nonintegers will generate API errors + operationId: deleteOrder + parameters: + - description: ID of the order that needs to be deleted + explode: false + in: path + name: orderId + required: true + schema: + type: string + style: simple + responses: + "400": + description: Invalid ID supplied + "404": + description: Order not found + summary: Delete purchase order by ID + tags: + - store + get: + description: For valid response try integer IDs with value <= 5 or > 10. Other + values will generate exceptions + operationId: getOrderById + parameters: + - description: ID of pet that needs to be fetched + explode: false + in: path + name: orderId + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + style: simple + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Order not found + summary: Find purchase order by ID + tags: + - store + /user: + post: + description: This can only be done by the logged in user. + operationId: createUser + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Create user + tags: + - user + /user/createWithArray: + post: + description: "" + operationId: createUsersWithArrayInput + requestBody: + $ref: '#/components/requestBodies/UserArray' + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Creates list of users with given input array + tags: + - user + /user/createWithList: + post: + description: "" + operationId: createUsersWithListInput + requestBody: + $ref: '#/components/requestBodies/UserArray' + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Creates list of users with given input array + tags: + - user + /user/login: + get: + description: "" + operationId: loginUser + parameters: + - description: The user name for login + explode: true + in: query + name: username + required: true + schema: + pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$" + type: string + style: form + - description: The password for login in clear text + explode: true + in: query + name: password + required: true + schema: + type: string + style: form + responses: + "200": + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + Set-Cookie: + description: Cookie authentication key for use with the `api_key` apiKey + authentication. + explode: false + schema: + example: AUTH_KEY=abcde12345; Path=/; HttpOnly + type: string + style: simple + X-Rate-Limit: + description: calls per hour allowed by the user + explode: false + schema: + format: int32 + type: integer + style: simple + X-Expires-After: + description: date in UTC when token expires + explode: false + schema: + format: date-time + type: string + style: simple + "400": + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user + /user/logout: + get: + description: "" + operationId: logoutUser + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Logs out current logged in user session + tags: + - user + /user/{username}: + delete: + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - description: The name that needs to be deleted + explode: false + in: path + name: username + required: true + schema: + type: string + style: simple + responses: + "400": + description: Invalid username supplied + "404": + description: User not found + security: + - api_key: [] + summary: Delete user + tags: + - user + get: + description: "" + operationId: getUserByName + parameters: + - description: The name that needs to be fetched. Use user1 for testing. + explode: false + in: path + name: username + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + description: successful operation + "400": + description: Invalid username supplied + "404": + description: User not found + summary: Get user by user name + tags: + - user + put: + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - description: name that need to be deleted + explode: false + in: path + name: username + required: true + schema: + type: string + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + responses: + "400": + description: Invalid user supplied + "404": + description: User not found + security: + - api_key: [] + summary: Updated user + tags: + - user +components: + requestBodies: + UserArray: + content: + application/json: + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + schemas: + Order: + description: An order for a pets from the pet store + example: + petId: 6 + quantity: 1 + id: 0 + shipDate: 2000-01-23T04:56:07.000+00:00 + complete: false + status: placed + properties: + id: + format: int64 + type: integer + petId: + format: int64 + type: integer + quantity: + format: int32 + type: integer + shipDate: + format: date-time + type: string + status: + description: Order Status + enum: + - placed + - approved + - delivered + type: string + complete: + default: false + type: boolean + title: Pet Order + type: object + xml: + name: Order + Category: + description: A category for a pet + example: + name: name + id: 6 + properties: + id: + format: int64 + type: integer + name: + pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$" + type: string + title: Pet category + type: object + xml: + name: Category + User: + description: A User who is purchasing from the pet store + example: + firstName: firstName + lastName: lastName + password: password + userStatus: 6 + phone: phone + id: 0 + email: email + username: username + properties: + id: + format: int64 + type: integer + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + description: User Status + format: int32 + type: integer + title: a User + type: object + xml: + name: User + Tag: + description: A tag for a pet + example: + name: name + id: 1 + properties: + id: + format: int64 + type: integer + name: + type: string + title: Pet Tag + type: object + xml: + name: Tag + Pet: + description: A pet for sale in the pet store + example: + photoUrls: + - photoUrls + - photoUrls + name: doggie + id: 0 + category: + name: name + id: 6 + tags: + - name: name + id: 1 + - name: name + id: 1 + status: available + properties: + id: + format: int64 + type: integer + category: + $ref: '#/components/schemas/Category' + name: + example: doggie + type: string + photoUrls: + items: + type: string + type: array + xml: + name: photoUrl + wrapped: true + tags: + items: + $ref: '#/components/schemas/Tag' + type: array + xml: + name: tag + wrapped: true + status: + deprecated: true + description: pet status in the store + enum: + - available + - pending + - sold + type: string + required: + - name + - photoUrls + title: a Pet + type: object + xml: + name: Pet + ApiResponse: + description: Describes the result of uploading an image resource + example: + code: 0 + type: type + message: message + properties: + code: + format: int32 + type: integer + type: + type: string + message: + type: string + title: An uploaded response + type: object + updatePetWithForm_request: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + type: object + uploadFile_request: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + type: object + securitySchemes: + petstore_auth: + flows: + implicit: + authorizationUrl: http://petstore.swagger.io/api/oauth/dialog + scopes: + write:pets: modify pets in your account + read:pets: read your pets + type: oauth2 + api_key: + in: header + name: api_key + type: apiKey diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/test/kotlin/org/openapitools/api/PetApiTest.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/test/kotlin/org/openapitools/api/PetApiTest.kt new file mode 100644 index 00000000000..3623318105c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/test/kotlin/org/openapitools/api/PetApiTest.kt @@ -0,0 +1,131 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.junit.jupiter.api.Test +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.test.runBlockingTest +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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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-reactive-with-flow/src/test/kotlin/org/openapitools/api/StoreApiTest.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/test/kotlin/org/openapitools/api/StoreApiTest.kt new file mode 100644 index 00000000000..dbbb1e0a2fb --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/test/kotlin/org/openapitools/api/StoreApiTest.kt @@ -0,0 +1,68 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.junit.jupiter.api.Test +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.test.runBlockingTest +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() = runBlockingTest { + 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() = runBlockingTest { + val response: ResponseEntity> = api.getInventory() + + // TODO: test validations + } + + /** + * To test StoreApiController.getOrderById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getOrderByIdTest() = runBlockingTest { + 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() = runBlockingTest { + val order: Order = TODO() + val response: ResponseEntity = api.placeOrder(order) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/test/kotlin/org/openapitools/api/UserApiTest.kt b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/test/kotlin/org/openapitools/api/UserApiTest.kt new file mode 100644 index 00000000000..7c4a902e89b --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-with-flow/src/test/kotlin/org/openapitools/api/UserApiTest.kt @@ -0,0 +1,126 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.junit.jupiter.api.Test +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.test.runBlockingTest +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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + val response: ResponseEntity = api.logoutUser() + + // TODO: test validations + } + + /** + * To test UserApiController.updateUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updateUserTest() = runBlockingTest { + 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-reactive-without-flow/.openapi-generator-ignore b/samples/server/petstore/kotlin-springboot-reactive-without-flow/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/.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-reactive-without-flow/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-reactive-without-flow/.openapi-generator/FILES new file mode 100644 index 00000000000..7b4efc03051 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/.openapi-generator/FILES @@ -0,0 +1,28 @@ +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/HomeController.kt +src/main/kotlin/org/openapitools/api/ApiUtil.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 +src/main/resources/openapi.yaml diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/.openapi-generator/VERSION b/samples/server/petstore/kotlin-springboot-reactive-without-flow/.openapi-generator/VERSION new file mode 100644 index 00000000000..88411912639 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.11.0-SNAPSHOT diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/README.md b/samples/server/petstore/kotlin-springboot-reactive-without-flow/README.md new file mode 100644 index 00000000000..b6865a08113 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/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-reactive-without-flow/build.gradle.kts b/samples/server/petstore/kotlin-springboot-reactive-without-flow/build.gradle.kts new file mode 100644 index 00000000000..568be3488b1 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/build.gradle.kts @@ -0,0 +1,53 @@ +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 = "1.8" +} + +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 { + val kotlinxCoroutinesVersion = "1.6.1" + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion") + implementation("org.springdoc:springdoc-openapi-webflux-ui:1.6.8") + + 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") + } + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesVersion") +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/gradle/wrapper/gradle-wrapper.jar b/samples/server/petstore/kotlin-springboot-reactive-without-flow/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..e6441136f3d Binary files /dev/null and b/samples/server/petstore/kotlin-springboot-reactive-without-flow/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-springboot-reactive-without-flow/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..80187ac3043 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/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-reactive-without-flow/gradlew b/samples/server/petstore/kotlin-springboot-reactive-without-flow/gradlew new file mode 100644 index 00000000000..9d0ce634cb1 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/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-reactive-without-flow/gradlew.bat b/samples/server/petstore/kotlin-springboot-reactive-without-flow/gradlew.bat new file mode 100644 index 00000000000..25da30dbdee --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/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-reactive-without-flow/pom.xml b/samples/server/petstore/kotlin-springboot-reactive-without-flow/pom.xml new file mode 100644 index 00000000000..f555dc75a07 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/pom.xml @@ -0,0 +1,147 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 1.6.1 + 1.6.8 + 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 + + 1.8 + + + + 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-webflux + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + ${kotlinx-coroutines.version} + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + ${kotlinx-coroutines.version} + + + + + org.springdoc + springdoc-openapi-webflux-ui + ${springdoc-openapi.version} + + + + + 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-reactive-without-flow/settings.gradle b/samples/server/petstore/kotlin-springboot-reactive-without-flow/settings.gradle new file mode 100644 index 00000000000..14844905cd4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/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-reactive-without-flow/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/Application.kt new file mode 100644 index 00000000000..2fe6de62479 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/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-reactive-without-flow/src/main/kotlin/org/openapitools/HomeController.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/HomeController.kt new file mode 100644 index 00000000000..78f8cce7d83 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/HomeController.kt @@ -0,0 +1,26 @@ +package org.openapitools + +import org.springframework.context.annotation.Bean +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.reactive.function.server.HandlerFunction +import org.springframework.web.reactive.function.server.RequestPredicates.GET +import org.springframework.web.reactive.function.server.RouterFunction +import org.springframework.web.reactive.function.server.RouterFunctions.route +import org.springframework.web.reactive.function.server.ServerResponse +import java.net.URI + +/** + * Home redirection to OpenAPI api documentation + */ +@Controller +class HomeController { + + @Bean + fun index(): RouterFunction = route( + GET("/"), HandlerFunction { + ServerResponse.temporaryRedirect(URI.create("swagger-ui.html")).build() + }) +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 00000000000..7c275cbf30e --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,5 @@ +package org.openapitools.api + + +object ApiUtil { +} 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 new file mode 100644 index 00000000000..3223d0b91e8 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -0,0 +1,183 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import io.swagger.v3.oas.annotations.* +import io.swagger.v3.oas.annotations.enums.* +import io.swagger.v3.oas.annotations.media.* +import io.swagger.v3.oas.annotations.responses.* +import io.swagger.v3.oas.annotations.security.* +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 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 kotlinx.coroutines.flow.Flow +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@RequestMapping("\${api.base-path:/v2}") +class PetApiController(@Autowired(required = true) val service: PetApiService) { + + @Operation( + summary = "Add a new pet to the store", + operationId = "addPet", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "405", description = "Invalid input") ], + 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"] + ) + 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)) + } + + @Operation( + summary = "Deletes a pet", + operationId = "deletePet", + description = """""", + responses = [ + ApiResponse(responseCode = "400", description = "Invalid pet value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/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 { + return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) + } + + @Operation( + summary = "Finds Pets by status", + operationId = "findPetsByStatus", + description = """Multiple status values can be provided with comma separated strings""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(array = ArraySchema(schema = Schema(implementation = Pet::class)))]), + ApiResponse(responseCode = "400", description = "Invalid status value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/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> { + return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Finds Pets by tags", + operationId = "findPetsByTags", + description = """Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(array = ArraySchema(schema = Schema(implementation = Pet::class)))]), + ApiResponse(responseCode = "400", description = "Invalid tag value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/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> { + return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Find pet by ID", + operationId = "getPetById", + description = """Returns a single pet""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + ApiResponse(responseCode = "404", description = "Pet not found") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/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 { + return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Update an existing pet", + operationId = "updatePet", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + ApiResponse(responseCode = "404", description = "Pet not found"), + ApiResponse(responseCode = "405", description = "Validation exception") ], + 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"] + ) + 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)) + } + + @Operation( + summary = "Updates a pet in the store with form data", + operationId = "updatePetWithForm", + description = """""", + responses = [ + ApiResponse(responseCode = "405", description = "Invalid input") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/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") @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) + } + + @Operation( + summary = "uploads an image", + operationId = "uploadFile", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = ModelApiResponse::class))]) ], + 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"] + ) + 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") @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)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiService.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiService.kt new file mode 100644 index 00000000000..2667d977a4d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiService.kt @@ -0,0 +1,104 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import kotlinx.coroutines.flow.Flow + +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 + */ + suspend 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.web.multipart.MultipartFile?): ModelApiResponse +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt new file mode 100644 index 00000000000..7fde165ae2a --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt @@ -0,0 +1,41 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import kotlinx.coroutines.flow.Flow +import org.springframework.stereotype.Service +@Service +class PetApiServiceImpl : PetApiService { + + override suspend fun addPet(pet: Pet): Pet { + TODO("Implement me") + } + + override suspend 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 suspend fun getPetById(petId: kotlin.Long): Pet { + TODO("Implement me") + } + + override suspend fun updatePet(pet: Pet): Pet { + TODO("Implement me") + } + + override suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit { + TODO("Implement me") + } + + override suspend 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-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 new file mode 100644 index 00000000000..d376c35f159 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -0,0 +1,105 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import io.swagger.v3.oas.annotations.* +import io.swagger.v3.oas.annotations.enums.* +import io.swagger.v3.oas.annotations.media.* +import io.swagger.v3.oas.annotations.responses.* +import io.swagger.v3.oas.annotations.security.* +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 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 kotlinx.coroutines.flow.Flow +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@RequestMapping("\${api.base-path:/v2}") +class StoreApiController(@Autowired(required = true) val service: StoreApiService) { + + @Operation( + summary = "Delete purchase order by ID", + operationId = "deleteOrder", + description = """For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors""", + responses = [ + ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + ApiResponse(responseCode = "404", description = "Order not found") ] + ) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/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 { + return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) + } + + @Operation( + summary = "Returns pet inventories by status", + operationId = "getInventory", + description = """Returns a map of status codes to quantities""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = kotlin.collections.Map::class))]) ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/store/inventory"], + produces = ["application/json"] + ) + suspend fun getInventory(): ResponseEntity> { + return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Find purchase order by ID", + operationId = "getOrderById", + description = """For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Order::class))]), + ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + ApiResponse(responseCode = "404", description = "Order not found") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/store/order/{orderId}"], + produces = ["application/xml", "application/json"] + ) + suspend fun getOrderById(@Min(1L) @Max(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)) + } + + @Operation( + summary = "Place an order for a pet", + operationId = "placeOrder", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Order::class))]), + ApiResponse(responseCode = "400", description = "Invalid Order") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/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 { + return ResponseEntity(service.placeOrder(order), HttpStatus.valueOf(200)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiService.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiService.kt new file mode 100644 index 00000000000..ca81edd9f2b --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiService.kt @@ -0,0 +1,50 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import kotlinx.coroutines.flow.Flow + +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 + */ + suspend 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend fun placeOrder(order: Order): Order +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt new file mode 100644 index 00000000000..243487f52b7 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt @@ -0,0 +1,24 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import kotlinx.coroutines.flow.Flow +import org.springframework.stereotype.Service +@Service +class StoreApiServiceImpl : StoreApiService { + + override suspend fun deleteOrder(orderId: kotlin.String): Unit { + TODO("Implement me") + } + + override suspend fun getInventory(): Map { + TODO("Implement me") + } + + override suspend fun getOrderById(orderId: kotlin.Long): Order { + TODO("Implement me") + } + + override suspend fun placeOrder(order: Order): Order { + TODO("Implement me") + } +} 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 new file mode 100644 index 00000000000..8884b2a1a70 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -0,0 +1,173 @@ +package org.openapitools.api + +import org.openapitools.model.User +import io.swagger.v3.oas.annotations.* +import io.swagger.v3.oas.annotations.enums.* +import io.swagger.v3.oas.annotations.media.* +import io.swagger.v3.oas.annotations.responses.* +import io.swagger.v3.oas.annotations.security.* +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 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 kotlinx.coroutines.flow.Flow +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@RequestMapping("\${api.base-path:/v2}") +class UserApiController(@Autowired(required = true) val service: UserApiService) { + + @Operation( + summary = "Create user", + operationId = "createUser", + description = """This can only be done by the logged in user.""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user"], + consumes = ["application/json"] + ) + suspend fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + return ResponseEntity(service.createUser(user), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Creates list of users with given input array", + operationId = "createUsersWithArrayInput", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user/createWithArray"], + consumes = ["application/json"] + ) + suspend fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow): ResponseEntity { + return ResponseEntity(service.createUsersWithArrayInput(user), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Creates list of users with given input array", + operationId = "createUsersWithListInput", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user/createWithList"], + consumes = ["application/json"] + ) + suspend fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: Flow): ResponseEntity { + return ResponseEntity(service.createUsersWithListInput(user), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Delete user", + operationId = "deleteUser", + description = """This can only be done by the logged in user.""", + responses = [ + ApiResponse(responseCode = "400", description = "Invalid username supplied"), + ApiResponse(responseCode = "404", description = "User not found") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/user/{username}"] + ) + 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)) + } + + @Operation( + summary = "Get user by user name", + operationId = "getUserByName", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = User::class))]), + ApiResponse(responseCode = "400", description = "Invalid username supplied"), + ApiResponse(responseCode = "404", description = "User not found") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/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 { + return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Logs user into the system", + operationId = "loginUser", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = kotlin.String::class))]), + ApiResponse(responseCode = "400", description = "Invalid username/password supplied") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/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 { + return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Logs out current logged in user session", + operationId = "logoutUser", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/user/logout"] + ) + suspend fun logoutUser(): ResponseEntity { + return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Updated user", + operationId = "updateUser", + description = """This can only be done by the logged in user.""", + responses = [ + ApiResponse(responseCode = "400", description = "Invalid user supplied"), + ApiResponse(responseCode = "404", description = "User not found") ], + security = [ SecurityRequirement(name = "api_key") ] + ) + @RequestMapping( + method = [RequestMethod.PUT], + value = ["/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 { + return ResponseEntity(service.updateUser(username, user), HttpStatus.valueOf(400)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiService.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiService.kt new file mode 100644 index 00000000000..c166f1ff0d0 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiService.kt @@ -0,0 +1,93 @@ +package org.openapitools.api + +import org.openapitools.model.User +import kotlinx.coroutines.flow.Flow + +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 + */ + suspend 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 + */ + suspend fun createUsersWithArrayInput(user: Flow): 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 + */ + suspend fun createUsersWithListInput(user: Flow): 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend 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 + */ + suspend fun updateUser(username: kotlin.String, user: User): Unit +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt new file mode 100644 index 00000000000..c6c248ccfa0 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt @@ -0,0 +1,40 @@ +package org.openapitools.api + +import org.openapitools.model.User +import kotlinx.coroutines.flow.Flow +import org.springframework.stereotype.Service +@Service +class UserApiServiceImpl : UserApiService { + + override suspend fun createUser(user: User): Unit { + TODO("Implement me") + } + + override suspend fun createUsersWithArrayInput(user: Flow): Unit { + TODO("Implement me") + } + + override suspend fun createUsersWithListInput(user: Flow): Unit { + TODO("Implement me") + } + + override suspend fun deleteUser(username: kotlin.String): Unit { + TODO("Implement me") + } + + override suspend fun getUserByName(username: kotlin.String): User { + TODO("Implement me") + } + + override suspend fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String { + TODO("Implement me") + } + + override suspend fun logoutUser(): Unit { + TODO("Implement me") + } + + override suspend fun updateUser(username: kotlin.String, user: User): Unit { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Category.kt new file mode 100644 index 00000000000..0ca76806b7c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Category.kt @@ -0,0 +1,32 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +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 io.swagger.v3.oas.annotations.media.Schema + +/** + * A category for a pet + * @param id + * @param name + */ +data class Category( + + @Schema(example = "null", description = "") + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") + @Schema(example = "null", description = "") + @get:JsonProperty("name") val name: kotlin.String? = null + ) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt new file mode 100644 index 00000000000..b5a7eaeb711 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt @@ -0,0 +1,35 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +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 io.swagger.v3.oas.annotations.media.Schema + +/** + * Describes the result of uploading an image resource + * @param code + * @param type + * @param message + */ +data class ModelApiResponse( + + @Schema(example = "null", description = "") + @get:JsonProperty("code") val code: kotlin.Int? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("type") val type: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("message") val message: kotlin.String? = null + ) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Order.kt new file mode 100644 index 00000000000..55ccdbd9aad --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Order.kt @@ -0,0 +1,68 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +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 io.swagger.v3.oas.annotations.media.Schema + +/** + * 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( + + @Schema(example = "null", description = "") + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("petId") val petId: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("quantity") val quantity: kotlin.Int? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, + + @Schema(example = "null", description = "Order Status") + @get:JsonProperty("status") val status: Order.Status? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("complete") val complete: kotlin.Boolean? = false + ) { + + /** + * 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().first{it -> it.value == value} + } + } + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Pet.kt new file mode 100644 index 00000000000..66c6a74d15d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Pet.kt @@ -0,0 +1,73 @@ +package org.openapitools.model + +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 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 io.swagger.v3.oas.annotations.media.Schema + +/** + * 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( + + @Schema(example = "doggie", required = true, description = "") + @get:JsonProperty("name", required = true) val name: kotlin.String, + + @Schema(example = "null", required = true, description = "") + @get:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, + + @Schema(example = "null", description = "") + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @field:Valid + @Schema(example = "null", description = "") + @get:JsonProperty("category") val category: Category? = null, + + @field:Valid + @Schema(example = "null", description = "") + @get:JsonProperty("tags") val tags: kotlin.collections.List? = null, + + @Schema(example = "null", description = "pet status in the store") + @Deprecated(message = "") + @get:JsonProperty("status") val status: Pet.Status? = null + ) { + + /** + * 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().first{it -> it.value == value} + } + } + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Tag.kt new file mode 100644 index 00000000000..02b9a52259c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Tag.kt @@ -0,0 +1,31 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +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 io.swagger.v3.oas.annotations.media.Schema + +/** + * A tag for a pet + * @param id + * @param name + */ +data class Tag( + + @Schema(example = "null", description = "") + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("name") val name: kotlin.String? = null + ) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/User.kt new file mode 100644 index 00000000000..e69df97f3f4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/User.kt @@ -0,0 +1,55 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +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 io.swagger.v3.oas.annotations.media.Schema + +/** + * 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( + + @Schema(example = "null", description = "") + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("username") val username: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("firstName") val firstName: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("lastName") val lastName: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("email") val email: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("password") val password: kotlin.String? = null, + + @Schema(example = "null", description = "") + @get:JsonProperty("phone") val phone: kotlin.String? = null, + + @Schema(example = "null", description = "User Status") + @get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null + ) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/resources/application.yaml b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/resources/application.yaml new file mode 100644 index 00000000000..8e2ebcde976 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/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-reactive-without-flow/src/main/resources/openapi.yaml b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/resources/openapi.yaml new file mode 100644 index 00000000000..9a95adaefff --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/resources/openapi.yaml @@ -0,0 +1,811 @@ +openapi: 3.0.0 +info: + description: "This is a sample server Petstore server. For this sample, you can\ + \ use the api key `special-key` to test the authorization filters." + license: + name: Apache-2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html + title: OpenAPI Petstore + version: 1.0.0 +externalDocs: + description: Find out more about Swagger + url: http://swagger.io +servers: +- url: http://petstore.swagger.io/v2 +tags: +- description: Everything about your Pets + name: pet +- description: Access to Petstore orders + name: store +- description: Operations about user + name: user +paths: + /pet: + post: + description: "" + operationId: addPet + requestBody: + $ref: '#/components/requestBodies/Pet' + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "405": + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + put: + description: "" + externalDocs: + description: API documentation for the updatePet operation + url: http://petstore.swagger.io/v2/doc/updatePet + operationId: updatePet + requestBody: + $ref: '#/components/requestBodies/Pet' + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + "405": + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + /pet/findByStatus: + get: + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - deprecated: true + description: Status values that need to be considered for filter + explode: false + in: query + name: status + required: true + schema: + items: + default: available + enum: + - available + - pending + - sold + type: string + type: array + style: form + responses: + "200": + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + "400": + description: Invalid status value + security: + - petstore_auth: + - read:pets + summary: Finds Pets by status + tags: + - pet + /pet/findByTags: + get: + deprecated: true + description: "Multiple tags can be provided with comma separated strings. Use\ + \ tag1, tag2, tag3 for testing." + operationId: findPetsByTags + parameters: + - description: Tags to filter by + explode: false + in: query + name: tags + required: true + schema: + items: + type: string + type: array + style: form + responses: + "200": + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + "400": + description: Invalid tag value + security: + - petstore_auth: + - read:pets + summary: Finds Pets by tags + tags: + - pet + /pet/{petId}: + delete: + description: "" + operationId: deletePet + parameters: + - explode: false + in: header + name: api_key + required: false + schema: + type: string + style: simple + - description: Pet id to delete + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "400": + description: Invalid pet value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Deletes a pet + tags: + - pet + get: + description: Returns a single pet + operationId: getPetById + parameters: + - description: ID of pet to return + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + tags: + - pet + post: + description: "" + operationId: updatePetWithForm + parameters: + - description: ID of pet that needs to be updated + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/updatePetWithForm_request' + responses: + "405": + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Updates a pet in the store with form data + tags: + - pet + /pet/{petId}/uploadImage: + post: + description: "" + operationId: uploadFile + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/uploadFile_request' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an image + tags: + - pet + /store/inventory: + get: + description: Returns a map of status codes to quantities + operationId: getInventory + responses: + "200": + content: + application/json: + schema: + additionalProperties: + format: int32 + type: integer + type: object + description: successful operation + security: + - api_key: [] + summary: Returns pet inventories by status + tags: + - store + /store/order: + post: + description: "" + operationId: placeOrder + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + required: true + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + description: Invalid Order + summary: Place an order for a pet + tags: + - store + /store/order/{orderId}: + delete: + description: For valid response try integer IDs with value < 1000. Anything + above 1000 or nonintegers will generate API errors + operationId: deleteOrder + parameters: + - description: ID of the order that needs to be deleted + explode: false + in: path + name: orderId + required: true + schema: + type: string + style: simple + responses: + "400": + description: Invalid ID supplied + "404": + description: Order not found + summary: Delete purchase order by ID + tags: + - store + get: + description: For valid response try integer IDs with value <= 5 or > 10. Other + values will generate exceptions + operationId: getOrderById + parameters: + - description: ID of pet that needs to be fetched + explode: false + in: path + name: orderId + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + style: simple + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Order not found + summary: Find purchase order by ID + tags: + - store + /user: + post: + description: This can only be done by the logged in user. + operationId: createUser + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Create user + tags: + - user + /user/createWithArray: + post: + description: "" + operationId: createUsersWithArrayInput + requestBody: + $ref: '#/components/requestBodies/UserArray' + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Creates list of users with given input array + tags: + - user + /user/createWithList: + post: + description: "" + operationId: createUsersWithListInput + requestBody: + $ref: '#/components/requestBodies/UserArray' + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Creates list of users with given input array + tags: + - user + /user/login: + get: + description: "" + operationId: loginUser + parameters: + - description: The user name for login + explode: true + in: query + name: username + required: true + schema: + pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$" + type: string + style: form + - description: The password for login in clear text + explode: true + in: query + name: password + required: true + schema: + type: string + style: form + responses: + "200": + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + Set-Cookie: + description: Cookie authentication key for use with the `api_key` apiKey + authentication. + explode: false + schema: + example: AUTH_KEY=abcde12345; Path=/; HttpOnly + type: string + style: simple + X-Rate-Limit: + description: calls per hour allowed by the user + explode: false + schema: + format: int32 + type: integer + style: simple + X-Expires-After: + description: date in UTC when token expires + explode: false + schema: + format: date-time + type: string + style: simple + "400": + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user + /user/logout: + get: + description: "" + operationId: logoutUser + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Logs out current logged in user session + tags: + - user + /user/{username}: + delete: + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - description: The name that needs to be deleted + explode: false + in: path + name: username + required: true + schema: + type: string + style: simple + responses: + "400": + description: Invalid username supplied + "404": + description: User not found + security: + - api_key: [] + summary: Delete user + tags: + - user + get: + description: "" + operationId: getUserByName + parameters: + - description: The name that needs to be fetched. Use user1 for testing. + explode: false + in: path + name: username + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + description: successful operation + "400": + description: Invalid username supplied + "404": + description: User not found + summary: Get user by user name + tags: + - user + put: + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - description: name that need to be deleted + explode: false + in: path + name: username + required: true + schema: + type: string + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + responses: + "400": + description: Invalid user supplied + "404": + description: User not found + security: + - api_key: [] + summary: Updated user + tags: + - user +components: + requestBodies: + UserArray: + content: + application/json: + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + schemas: + Order: + description: An order for a pets from the pet store + example: + petId: 6 + quantity: 1 + id: 0 + shipDate: 2000-01-23T04:56:07.000+00:00 + complete: false + status: placed + properties: + id: + format: int64 + type: integer + petId: + format: int64 + type: integer + quantity: + format: int32 + type: integer + shipDate: + format: date-time + type: string + status: + description: Order Status + enum: + - placed + - approved + - delivered + type: string + complete: + default: false + type: boolean + title: Pet Order + type: object + xml: + name: Order + Category: + description: A category for a pet + example: + name: name + id: 6 + properties: + id: + format: int64 + type: integer + name: + pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$" + type: string + title: Pet category + type: object + xml: + name: Category + User: + description: A User who is purchasing from the pet store + example: + firstName: firstName + lastName: lastName + password: password + userStatus: 6 + phone: phone + id: 0 + email: email + username: username + properties: + id: + format: int64 + type: integer + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + description: User Status + format: int32 + type: integer + title: a User + type: object + xml: + name: User + Tag: + description: A tag for a pet + example: + name: name + id: 1 + properties: + id: + format: int64 + type: integer + name: + type: string + title: Pet Tag + type: object + xml: + name: Tag + Pet: + description: A pet for sale in the pet store + example: + photoUrls: + - photoUrls + - photoUrls + name: doggie + id: 0 + category: + name: name + id: 6 + tags: + - name: name + id: 1 + - name: name + id: 1 + status: available + properties: + id: + format: int64 + type: integer + category: + $ref: '#/components/schemas/Category' + name: + example: doggie + type: string + photoUrls: + items: + type: string + type: array + xml: + name: photoUrl + wrapped: true + tags: + items: + $ref: '#/components/schemas/Tag' + type: array + xml: + name: tag + wrapped: true + status: + deprecated: true + description: pet status in the store + enum: + - available + - pending + - sold + type: string + required: + - name + - photoUrls + title: a Pet + type: object + xml: + name: Pet + ApiResponse: + description: Describes the result of uploading an image resource + example: + code: 0 + type: type + message: message + properties: + code: + format: int32 + type: integer + type: + type: string + message: + type: string + title: An uploaded response + type: object + updatePetWithForm_request: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + type: object + uploadFile_request: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + type: object + securitySchemes: + petstore_auth: + flows: + implicit: + authorizationUrl: http://petstore.swagger.io/api/oauth/dialog + scopes: + write:pets: modify pets in your account + read:pets: read your pets + type: oauth2 + api_key: + in: header + name: api_key + type: apiKey diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/test/kotlin/org/openapitools/api/PetApiTest.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/test/kotlin/org/openapitools/api/PetApiTest.kt new file mode 100644 index 00000000000..401b2fc8829 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/test/kotlin/org/openapitools/api/PetApiTest.kt @@ -0,0 +1,131 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.junit.jupiter.api.Test +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.test.runBlockingTest +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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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-reactive-without-flow/src/test/kotlin/org/openapitools/api/StoreApiTest.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/test/kotlin/org/openapitools/api/StoreApiTest.kt new file mode 100644 index 00000000000..dbbb1e0a2fb --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/test/kotlin/org/openapitools/api/StoreApiTest.kt @@ -0,0 +1,68 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.junit.jupiter.api.Test +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.test.runBlockingTest +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() = runBlockingTest { + 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() = runBlockingTest { + val response: ResponseEntity> = api.getInventory() + + // TODO: test validations + } + + /** + * To test StoreApiController.getOrderById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getOrderByIdTest() = runBlockingTest { + 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() = runBlockingTest { + val order: Order = TODO() + val response: ResponseEntity = api.placeOrder(order) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/test/kotlin/org/openapitools/api/UserApiTest.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/test/kotlin/org/openapitools/api/UserApiTest.kt new file mode 100644 index 00000000000..7c4a902e89b --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/test/kotlin/org/openapitools/api/UserApiTest.kt @@ -0,0 +1,126 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.junit.jupiter.api.Test +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.test.runBlockingTest +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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + 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() = runBlockingTest { + val response: ResponseEntity = api.logoutUser() + + // TODO: test validations + } + + /** + * To test UserApiController.updateUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updateUserTest() = runBlockingTest { + val username: kotlin.String = TODO() + val user: User = TODO() + val response: ResponseEntity = api.updateUser(username, user) + + // TODO: test validations + } +}