forked from loafle/openapi-generator-original
[Kotlin-spring] add springdoc config (#12377)
* Adding Springdoc config to Kotlin-Spring * Updating relevant samples * Updating unrelated samples
This commit is contained in:
parent
2ecbf324ef
commit
770c1cb053
@ -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.
|
||||
|
54
modules/openapi-generator/src/main/resources/kotlin-spring/springdocDocumentationConfig.mustache
vendored
Normal file
54
modules/openapi-generator/src/main/resources/kotlin-spring/springdocDocumentationConfig.mustache
vendored
Normal file
@ -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}}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
||||
)
|
||||
|
@ -1,46 +0,0 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>KotlinPetstoreKtorTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>kotlin-server-ktor</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>bundle-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>gradle</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -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
|
||||
|
@ -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)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user