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 db3b9ab45a7..a7d445eb3c8 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 @@ -583,10 +583,16 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen } } - if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider()) && !reactive) { - supportingFiles.add(new SupportingFile("openapiDocumentationConfig.mustache", - (sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), - "SpringFoxConfiguration.kt")); + if (!reactive) { + if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider())) { + supportingFiles.add(new SupportingFile("springfoxDocumentationConfig.mustache", + (sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), + "SpringFoxConfiguration.kt")); + } else if (DocumentationProvider.SPRINGDOC.equals(getDocumentationProvider())) { + supportingFiles.add(new SupportingFile("springdocDocumentationConfig.mustache", + (sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), + "SpringDocConfiguration.kt")); + } } // spring uses the jackson lib, and we disallow configuration. diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/springdocDocumentationConfig.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/springdocDocumentationConfig.mustache new file mode 100644 index 00000000000..fa2cacd025c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/springdocDocumentationConfig.mustache @@ -0,0 +1,54 @@ +package {{basePackage}} + +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +import io.swagger.v3.oas.models.OpenAPI +import io.swagger.v3.oas.models.info.Info +import io.swagger.v3.oas.models.info.Contact +import io.swagger.v3.oas.models.info.License +import io.swagger.v3.oas.models.Components +import io.swagger.v3.oas.models.security.SecurityScheme + +{{>generatedAnnotation}} +@Configuration +class SpringDocConfiguration { + + @Bean + fun apiInfo(): OpenAPI { + return OpenAPI() + .info( + Info(){{#appName}} + .title("{{appName}}"){{/appName}} + .description("{{{appDescription}}}"){{#termsOfService}} + .termsOfService("{{termsOfService}}"){{/termsOfService}}{{#openAPI}}{{#info}}{{#contact}} + .contact( + Contact(){{#infoName}} + .name("{{infoName}}"){{/infoName}}{{#infoUrl}} + .url("{{infoUrl}}"){{/infoUrl}}{{#infoEmail}} + .email("{{infoEmail}}"){{/infoEmail}} + ){{/contact}}{{#license}} + .license( + License() + {{#licenseInfo}}.name("{{licenseInfo}}") + {{/licenseInfo}}{{#licenseUrl}}.url("{{licenseUrl}}") + {{/licenseUrl}} + ){{/license}}{{/info}}{{/openAPI}} + .version("{{appVersion}}") + ){{#hasAuthMethods}} + .components( + Components(){{#authMethods}} + .addSecuritySchemes("{{name}}", SecurityScheme(){{#isBasic}} + .type(SecurityScheme.Type.HTTP) + .scheme("{{scheme}}"){{#bearerFormat}} + .bearerFormat("{{bearerFormat}}"){{/bearerFormat}}{{/isBasic}}{{#isApiKey}} + .type(SecurityScheme.Type.APIKEY){{#isKeyInHeader}} + .`in`(SecurityScheme.In.HEADER){{/isKeyInHeader}}{{#isKeyInQuery}} + .`in`(SecurityScheme.In.QUERY){{/isKeyInQuery}}{{#isKeyInCookie}} + .`in`(SecurityScheme.In.COOKIE){{/isKeyInCookie}} + .name("{{keyParamName}}"){{/isApiKey}}{{#isOAuth}} + .type(SecurityScheme.Type.OAUTH2){{/isOAuth}} + ){{/authMethods}} + ){{/hasAuthMethods}} + } +} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/openapiDocumentationConfig.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/springfoxDocumentationConfig.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-spring/openapiDocumentationConfig.mustache rename to modules/openapi-generator/src/main/resources/kotlin-spring/springfoxDocumentationConfig.mustache diff --git a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ApiResponse.kt b/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ApiResponse.kt deleted file mode 100644 index 974c9589a7f..00000000000 --- a/samples/server/petstore/kotlin-server/jaxrs-spec/src/main/kotlin/org/openapitools/server/models/ApiResponse.kt +++ /dev/null @@ -1,33 +0,0 @@ -/** - * OpenAPI Petstore - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - * - * The version of the OpenAPI document: 1.0.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. -*/ -package org.openapitools.server.models - -import com.fasterxml.jackson.annotation.JsonProperty -/** - * Describes the result of uploading an image resource - * - * @param code - * @param type - * @param message - */ - - -data class ApiResponse ( - - val code: kotlin.Int? = null, - - val type: kotlin.String? = null, - - val message: kotlin.String? = null - -) - diff --git a/samples/server/petstore/kotlin-server/ktor/pom.xml b/samples/server/petstore/kotlin-server/ktor/pom.xml deleted file mode 100644 index 3123ad353a5..00000000000 --- a/samples/server/petstore/kotlin-server/ktor/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - 4.0.0 - org.openapitools - KotlinPetstoreKtorTests - pom - 1.0-SNAPSHOT - kotlin-server-ktor - - - - maven-dependency-plugin - - - package - - copy-dependencies - - - ${project.build.directory} - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 - - - bundle-test - integration-test - - exec - - - gradle - - test - - - - - - - - diff --git a/samples/server/petstore/kotlin-springboot-delegate/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-delegate/.openapi-generator/FILES index c9dafaf7207..e6abbae22b6 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/.openapi-generator/FILES +++ b/samples/server/petstore/kotlin-springboot-delegate/.openapi-generator/FILES @@ -4,6 +4,7 @@ pom.xml settings.gradle src/main/kotlin/org/openapitools/Application.kt src/main/kotlin/org/openapitools/HomeController.kt +src/main/kotlin/org/openapitools/SpringDocConfiguration.kt src/main/kotlin/org/openapitools/api/ApiUtil.kt src/main/kotlin/org/openapitools/api/Exceptions.kt src/main/kotlin/org/openapitools/api/PetApi.kt diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/SpringDocConfiguration.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/SpringDocConfiguration.kt new file mode 100644 index 00000000000..63c69a43b27 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/SpringDocConfiguration.kt @@ -0,0 +1,43 @@ +package org.openapitools + +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +import io.swagger.v3.oas.models.OpenAPI +import io.swagger.v3.oas.models.info.Info +import io.swagger.v3.oas.models.info.Contact +import io.swagger.v3.oas.models.info.License +import io.swagger.v3.oas.models.Components +import io.swagger.v3.oas.models.security.SecurityScheme + +@jakarta.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"]) +@Configuration +class SpringDocConfiguration { + + @Bean + fun apiInfo(): OpenAPI { + return OpenAPI() + .info( + Info() + .title("OpenAPI Petstore") + .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( + License() + .name("Apache-2.0") + .url("https://www.apache.org/licenses/LICENSE-2.0.html") + ) + .version("1.0.0") + ) + .components( + Components() + .addSecuritySchemes("api_key", SecurityScheme() + .type(SecurityScheme.Type.APIKEY) + .`in`(SecurityScheme.In.HEADER) + .name("api_key") + ) + .addSecuritySchemes("petstore_auth", SecurityScheme() + .type(SecurityScheme.Type.OAUTH2) + ) + ) + } +} diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/FILES index 94bb84d6ac3..33690582d9a 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/FILES +++ b/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/FILES @@ -4,6 +4,7 @@ pom.xml settings.gradle src/main/kotlin/org/openapitools/Application.kt src/main/kotlin/org/openapitools/HomeController.kt +src/main/kotlin/org/openapitools/SpringDocConfiguration.kt src/main/kotlin/org/openapitools/api/ApiUtil.kt src/main/kotlin/org/openapitools/api/Exceptions.kt src/main/kotlin/org/openapitools/api/PetApiController.kt diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/SpringDocConfiguration.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/SpringDocConfiguration.kt new file mode 100644 index 00000000000..63c69a43b27 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/SpringDocConfiguration.kt @@ -0,0 +1,43 @@ +package org.openapitools + +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +import io.swagger.v3.oas.models.OpenAPI +import io.swagger.v3.oas.models.info.Info +import io.swagger.v3.oas.models.info.Contact +import io.swagger.v3.oas.models.info.License +import io.swagger.v3.oas.models.Components +import io.swagger.v3.oas.models.security.SecurityScheme + +@jakarta.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"]) +@Configuration +class SpringDocConfiguration { + + @Bean + fun apiInfo(): OpenAPI { + return OpenAPI() + .info( + Info() + .title("OpenAPI Petstore") + .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( + License() + .name("Apache-2.0") + .url("https://www.apache.org/licenses/LICENSE-2.0.html") + ) + .version("1.0.0") + ) + .components( + Components() + .addSecuritySchemes("api_key", SecurityScheme() + .type(SecurityScheme.Type.APIKEY) + .`in`(SecurityScheme.In.HEADER) + .name("api_key") + ) + .addSecuritySchemes("petstore_auth", SecurityScheme() + .type(SecurityScheme.Type.OAUTH2) + ) + ) + } +}