diff --git a/.github/workflows/samples-kotlin-server.yaml b/.github/workflows/samples-kotlin-server.yaml index ad511123408..ca54c38e5db 100644 --- a/.github/workflows/samples-kotlin-server.yaml +++ b/.github/workflows/samples-kotlin-server.yaml @@ -21,9 +21,12 @@ jobs: sample: # server - samples/server/petstore/kotlin-springboot - - samples/server/petstore/kotlin-springboot-modelMutable - samples/server/petstore/kotlin-springboot-delegate + - samples/server/petstore/kotlin-springboot-modelMutable - samples/server/petstore/kotlin-springboot-reactive + - samples/server/petstore/kotlin-springboot-source-swagger1 + - samples/server/petstore/kotlin-springboot-source-swagger2 + - samples/server/petstore/kotlin-springboot-springfox - samples/server/petstore/kotlin-server/ktor - samples/server/petstore/kotlin-server/jaxrs-spec - samples/server/petstore/kotlin-server-modelMutable diff --git a/bin/configs/kotlin-spring-boot-delegate.yaml b/bin/configs/kotlin-spring-boot-delegate.yaml index bd6d7956b08..56adfb9f46c 100644 --- a/bin/configs/kotlin-spring-boot-delegate.yaml +++ b/bin/configs/kotlin-spring-boot-delegate.yaml @@ -4,6 +4,8 @@ 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" delegatePattern: "true" - swaggerAnnotations: "true" beanValidations: "true" diff --git a/bin/configs/kotlin-spring-boot-modelMutable.yaml b/bin/configs/kotlin-spring-boot-modelMutable.yaml index 772d0dd7f55..6a75dc2d04a 100644 --- a/bin/configs/kotlin-spring-boot-modelMutable.yaml +++ b/bin/configs/kotlin-spring-boot-modelMutable.yaml @@ -4,8 +4,10 @@ library: spring-boot inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/kotlin-spring additionalProperties: + documentationProvider: springdoc + annotationLibrary: swagger2 + useSwaggerUI: "true" serializableModel: "true" - swaggerAnnotations: "true" serviceImplementation: "true" beanValidations: "true" modelMutable: "true" diff --git a/bin/configs/kotlin-spring-boot-reactive.yaml b/bin/configs/kotlin-spring-boot-reactive.yaml index 01b616d2122..f9a3f199679 100644 --- a/bin/configs/kotlin-spring-boot-reactive.yaml +++ b/bin/configs/kotlin-spring-boot-reactive.yaml @@ -4,7 +4,9 @@ library: spring-boot inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/kotlin-spring additionalProperties: + documentationProvider: springdoc + annotationLibrary: swagger2 + useSwaggerUI: "true" serviceImplementation: "true" reactive: "true" - swaggerAnnotations: "true" beanValidations: "true" diff --git a/bin/configs/kotlin-spring-boot-source-swagger1.yaml b/bin/configs/kotlin-spring-boot-source-swagger1.yaml new file mode 100644 index 00000000000..5f877b6c9a1 --- /dev/null +++ b/bin/configs/kotlin-spring-boot-source-swagger1.yaml @@ -0,0 +1,12 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-springboot-source-swagger1 +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + documentationProvider: source + annotationLibrary: swagger1 + useSwaggerUI: "true" + serviceImplementation: "true" + serializableModel: "true" + beanValidations: "true" diff --git a/bin/configs/kotlin-spring-boot-source-swagger2.yaml b/bin/configs/kotlin-spring-boot-source-swagger2.yaml new file mode 100644 index 00000000000..bd08d444d47 --- /dev/null +++ b/bin/configs/kotlin-spring-boot-source-swagger2.yaml @@ -0,0 +1,12 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-springboot-source-swagger2 +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + documentationProvider: source + annotationLibrary: swagger2 + useSwaggerUI: "true" + serviceImplementation: "true" + serializableModel: "true" + beanValidations: "true" diff --git a/bin/configs/kotlin-spring-boot-springfox.yaml b/bin/configs/kotlin-spring-boot-springfox.yaml new file mode 100644 index 00000000000..9e0bc3e274c --- /dev/null +++ b/bin/configs/kotlin-spring-boot-springfox.yaml @@ -0,0 +1,12 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-springboot-springfox +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + documentationProvider: springfox + annotationLibrary: swagger1 + useSwaggerUI: "true" + serviceImplementation: "true" + serializableModel: "true" + beanValidations: "true" diff --git a/bin/configs/kotlin-spring-boot.yaml b/bin/configs/kotlin-spring-boot.yaml index bc8da5b24a3..e727be7ebdf 100644 --- a/bin/configs/kotlin-spring-boot.yaml +++ b/bin/configs/kotlin-spring-boot.yaml @@ -4,7 +4,9 @@ library: spring-boot inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/kotlin-spring additionalProperties: + documentationProvider: none + annotationLibrary: none + useSwaggerUI: "false" serviceImplementation: "true" serializableModel: "true" - swaggerAnnotations: "true" beanValidations: "true" diff --git a/bin/configs/other/kotlin-spring-boot-reactive.yaml b/bin/configs/other/kotlin-spring-boot-reactive.yaml index 791905ed1b0..9c21c305bd8 100644 --- a/bin/configs/other/kotlin-spring-boot-reactive.yaml +++ b/bin/configs/other/kotlin-spring-boot-reactive.yaml @@ -4,7 +4,9 @@ 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" - swaggerAnnotations: "true" beanValidations: "true" diff --git a/bin/configs/other/kotlin-spring-boot.yaml b/bin/configs/other/kotlin-spring-boot.yaml index 29745bc6065..a1a137b865b 100644 --- a/bin/configs/other/kotlin-spring-boot.yaml +++ b/bin/configs/other/kotlin-spring-boot.yaml @@ -4,7 +4,9 @@ library: spring-boot inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/kotlin-spring additionalProperties: + documentationProvider: none + annotationLibrary: none + useSwaggerUI: "false" serviceImplementation: "true" serializableModel: "true" - swaggerAnnotations: "true" beanValidations: "true" diff --git a/docs/generators/kotlin-spring.md b/docs/generators/kotlin-spring.md index 100115ca3cc..030356edbc1 100644 --- a/docs/generators/kotlin-spring.md +++ b/docs/generators/kotlin-spring.md @@ -18,6 +18,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | Option | Description | Values | Default | | ------ | ----------- | ------ | ------- | +|annotationLibrary|Select the complementary documentation annotation library.|
**none**
Do not annotate Model and Api with complementary annotations.
**swagger1**
Annotate Model and Api using the Swagger Annotations 1.x library.
**swagger2**
Annotate Model and Api using the Swagger Annotations 2.x library.
|swagger2| |apiPackage|api package for generated code| |org.openapitools.api| |apiSuffix|suffix for api classes| |Api| |artifactId|Generated artifact id (name of jar).| |openapi-spring| @@ -25,6 +26,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |basePackage|base package (invokerPackage) for generated code| |org.openapitools| |beanQualifiers|Whether to add fully-qualifier class names as bean qualifiers in @Component and @RestController annotations. May be used to prevent bean names clash if multiple generated libraries (contexts) added to single project.| |false| |delegatePattern|Whether to generate the server files using the delegate pattern| |false| +|documentationProvider|Select the OpenAPI documentation provider.|
**none**
Do not publish an OpenAPI specification.
**source**
Publish the original input OpenAPI specification.
**springfox**
Generate an OpenAPI 2 (fka Swagger RESTful API Documentation Specification) specification using SpringFox 2.x. Deprecated (for removal); use springdoc instead.
**springdoc**
Generate an OpenAPI 3 specification using SpringDoc.
|springdoc| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |camelCase| |exceptionHandler|generate default global exception handlers (not compatible with reactive. enabling reactive will disable exceptionHandler )| |true| |gradleBuildFile|generate a gradle build file using the Kotlin DSL| |true| @@ -44,9 +46,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |null| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |null| |sourceFolder|source folder for generated code| |src/main/kotlin| -|swaggerAnnotations|generate swagger annotations to go alongside controllers and models| |false| |title|server title name or client service name| |OpenAPI Kotlin Spring| |useBeanValidation|Use BeanValidation API annotations to validate data types| |true| +|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| ## IMPORT MAPPING diff --git a/docs/usage.md b/docs/usage.md index bad47c90ade..d6a976fa30a 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -555,7 +555,7 @@ openapi-generator-cli generate \ -i petstore.yaml \ -g kotlin-spring \ -o out \ - --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true \ + --additional-properties=library=spring-boot,beanValidations=true,serviceImplementation=true \ --import-mappings=DateTime=java.time.LocalDateTime \ --type-mappings=DateTime=java.time.LocalDateTime ``` 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 8cfdc202638..db3b9ab45a7 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 @@ -20,9 +20,12 @@ import com.google.common.collect.ImmutableMap; import com.samskivert.mustache.Mustache; import com.samskivert.mustache.Mustache.Lambda; import com.samskivert.mustache.Template; - +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; import org.openapitools.codegen.*; import org.openapitools.codegen.languages.features.BeanValidationFeatures; +import org.openapitools.codegen.languages.features.DocumentationProviderFeatures; +import org.openapitools.codegen.languages.features.SwaggerUIFeatures; import org.openapitools.codegen.meta.features.*; import org.openapitools.codegen.model.ModelMap; import org.openapitools.codegen.model.ModelsMap; @@ -39,13 +42,10 @@ import java.net.URL; import java.util.*; import java.util.regex.Matcher; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.Operation; - import static org.openapitools.codegen.utils.StringUtils.camelize; public class KotlinSpringServerCodegen extends AbstractKotlinCodegen - implements BeanValidationFeatures { + implements BeanValidationFeatures, DocumentationProviderFeatures, SwaggerUIFeatures { private final Logger LOGGER = LoggerFactory.getLogger(KotlinSpringServerCodegen.class); @@ -63,7 +63,6 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen public static final String SPRING_BOOT = "spring-boot"; public static final String EXCEPTION_HANDLER = "exceptionHandler"; public static final String GRADLE_BUILD_FILE = "gradleBuildFile"; - public static final String SWAGGER_ANNOTATIONS = "swaggerAnnotations"; public static final String SERVICE_INTERFACE = "serviceInterface"; public static final String SERVICE_IMPLEMENTATION = "serviceImplementation"; public static final String REACTIVE = "reactive"; @@ -80,7 +79,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen private boolean useBeanValidation = true; private boolean exceptionHandler = true; private boolean gradleBuildFile = true; - private boolean swaggerAnnotations = false; + private boolean useSwaggerUI = true; private boolean serviceInterface = false; private boolean serviceImplementation = false; private boolean reactive = false; @@ -88,6 +87,8 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen private boolean delegatePattern = false; protected boolean useTags = false; private boolean beanQualifiers = false; + private DocumentationProvider documentationProvider; + private AnnotationLibrary annotationLibrary; public KotlinSpringServerCodegen() { super(); @@ -141,7 +142,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen addOption(CodegenConstants.API_PACKAGE, "api package for generated code", apiPackage); addSwitch(EXCEPTION_HANDLER, "generate default global exception handlers (not compatible with reactive. enabling reactive will disable exceptionHandler )", exceptionHandler); addSwitch(GRADLE_BUILD_FILE, "generate a gradle build file using the Kotlin DSL", gradleBuildFile); - addSwitch(SWAGGER_ANNOTATIONS, "generate swagger annotations to go alongside controllers and models", swaggerAnnotations); + addSwitch(USE_SWAGGER_UI, "Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies", useSwaggerUI); addSwitch(SERVICE_INTERFACE, "generate service interfaces to go alongside controllers. In most " + "cases this option would be used to update an existing project, so not to override implementations. " + "Useful to help facilitate the generation gap pattern", serviceInterface); @@ -162,6 +163,75 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen cliOpt.setDefault(SPRING_BOOT); cliOpt.setEnum(supportedLibraries); cliOptions.add(cliOpt); + + if (null != defaultDocumentationProvider()) { + CliOption documentationProviderCliOption = new CliOption(DOCUMENTATION_PROVIDER, + "Select the OpenAPI documentation provider.") + .defaultValue(defaultDocumentationProvider().toCliOptValue()); + supportedDocumentationProvider().forEach(dp -> + documentationProviderCliOption.addEnum(dp.toCliOptValue(), dp.getDescription())); + cliOptions.add(documentationProviderCliOption); + + CliOption annotationLibraryCliOption = new CliOption(ANNOTATION_LIBRARY, + "Select the complementary documentation annotation library.") + .defaultValue(defaultDocumentationProvider().getPreferredAnnotationLibrary().toCliOptValue()); + supportedAnnotationLibraries().forEach(al -> + annotationLibraryCliOption.addEnum(al.toCliOptValue(), al.getDescription())); + cliOptions.add(annotationLibraryCliOption); + } + } + @Override + public DocumentationProvider getDocumentationProvider() { + return documentationProvider; + } + + @Override + public void setDocumentationProvider(DocumentationProvider documentationProvider) { + this.documentationProvider = documentationProvider; + } + + @Override + public AnnotationLibrary getAnnotationLibrary() { + return annotationLibrary; + } + + @Override + public void setAnnotationLibrary(AnnotationLibrary annotationLibrary) { + this.annotationLibrary = annotationLibrary; + } + + @Override + public DocumentationProvider defaultDocumentationProvider() { + return DocumentationProvider.SPRINGDOC; + } + + public List supportedDocumentationProvider() { + return Arrays.asList( + DocumentationProvider.NONE, + DocumentationProvider.SOURCE, + DocumentationProvider.SPRINGFOX, + DocumentationProvider.SPRINGDOC + ); + } + + @Override + public List supportedAnnotationLibraries() { + return Arrays.asList( + AnnotationLibrary.NONE, + AnnotationLibrary.SWAGGER1, + AnnotationLibrary.SWAGGER2 + ); + } + + /** + * Whether the selected {@link DocumentationProviderFeatures.DocumentationProvider} requires us to bootstrap and + * configure swagger-ui by ourselves. Springdoc, for example ships its own swagger-ui integration. + * + * @return true if the selected DocumentationProvider requires us to bootstrap swagger-ui. + */ + private boolean selectedDocumentationProviderRequiresSwaggerUiBootstrap() { + return getDocumentationProvider().equals(DocumentationProvider.SPRINGFOX) || + getDocumentationProvider().equals(DocumentationProvider.SOURCE); } public String getResourceFolder() { @@ -212,12 +282,13 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen this.gradleBuildFile = gradleBuildFile; } - public boolean getSwaggerAnnotations() { - return this.swaggerAnnotations; + public boolean getUseSwaggerUI() { + return this.useSwaggerUI; } - public void setSwaggerAnnotations(boolean swaggerAnnotations) { - this.swaggerAnnotations = swaggerAnnotations; + @Override + public void setUseSwaggerUI(boolean useSwaggerUI) { + this.useSwaggerUI = useSwaggerUI; } public boolean getServiceInterface() { @@ -292,6 +363,50 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen public void processOpts() { super.processOpts(); + if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider())) { + LOGGER.warn("The springfox documentation provider is deprecated for removal. Use the springdoc provider instead."); + } + + if (null != defaultDocumentationProvider()) { + documentationProvider = DocumentationProvider.ofCliOption( + (String)additionalProperties.getOrDefault(DOCUMENTATION_PROVIDER, + defaultDocumentationProvider().toCliOptValue()) + ); + + if (! supportedDocumentationProvider().contains(documentationProvider)) { + String msg = String.format(Locale.ROOT, + "The [%s] Documentation Provider is not supported by this generator", + documentationProvider.toCliOptValue()); + throw new IllegalArgumentException(msg); + } + + annotationLibrary = AnnotationLibrary.ofCliOption( + (String) additionalProperties.getOrDefault(ANNOTATION_LIBRARY, + documentationProvider.getPreferredAnnotationLibrary().toCliOptValue()) + ); + + if (! supportedAnnotationLibraries().contains(annotationLibrary)) { + String msg = String.format(Locale.ROOT, "The Annotation Library [%s] is not supported by this generator", + annotationLibrary.toCliOptValue()); + throw new IllegalArgumentException(msg); + } + + if (! documentationProvider.supportedAnnotationLibraries().contains(annotationLibrary)) { + String msg = String.format(Locale.ROOT, + "The [%s] documentation provider does not support [%s] as complementary annotation library", + documentationProvider.toCliOptValue(), annotationLibrary.toCliOptValue()); + throw new IllegalArgumentException(msg); + } + + additionalProperties.put(DOCUMENTATION_PROVIDER, documentationProvider.toCliOptValue()); + additionalProperties.put(documentationProvider.getPropertyName(), true); + additionalProperties.put(ANNOTATION_LIBRARY, annotationLibrary.toCliOptValue()); + additionalProperties.put(annotationLibrary.getPropertyName(), true); + } else { + additionalProperties.put(DOCUMENTATION_PROVIDER, DocumentationProvider.NONE); + additionalProperties.put(ANNOTATION_LIBRARY, AnnotationLibrary.NONE); + } + if (isModelMutable()) { typeMapping.put("array", "kotlin.collections.MutableList"); typeMapping.put("list", "kotlin.collections.MutableList"); @@ -352,10 +467,13 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen } writePropertyBack(GRADLE_BUILD_FILE, gradleBuildFile); - if (additionalProperties.containsKey(SWAGGER_ANNOTATIONS)) { - this.setSwaggerAnnotations(Boolean.parseBoolean(additionalProperties.get(SWAGGER_ANNOTATIONS).toString())); + if (additionalProperties.containsKey(USE_SWAGGER_UI)) { + this.setUseSwaggerUI(Boolean.parseBoolean(additionalProperties.get(USE_SWAGGER_UI).toString())); } - writePropertyBack(SWAGGER_ANNOTATIONS, swaggerAnnotations); + if (getDocumentationProvider().equals(DocumentationProvider.NONE)) { + this.setUseSwaggerUI(false); + } + writePropertyBack(USE_SWAGGER_UI, useSwaggerUI); if (additionalProperties.containsKey(SERVICE_INTERFACE)) { this.setServiceInterface(Boolean.parseBoolean(additionalProperties.get(SERVICE_INTERFACE).toString())); @@ -391,9 +509,6 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen if (additionalProperties.containsKey(DELEGATE_PATTERN)) { this.setDelegatePattern(Boolean.parseBoolean(additionalProperties.get(DELEGATE_PATTERN).toString())); - if (!this.interfaceOnly) { - this.setSwaggerAnnotations(true); - } } if (additionalProperties.containsKey(USE_TAGS)) { @@ -449,12 +564,31 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen } if (!this.interfaceOnly) { + if (this.documentationProvider != DocumentationProvider.NONE) { + supportingFiles.add(new SupportingFile("homeController.mustache", + (sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), + "HomeController.kt")); + supportingFiles.add(new SupportingFile("openapi.mustache", + ("src/main/resources").replace("/", java.io.File.separator), "openapi.yaml")); + } + supportingFiles.add(new SupportingFile("application.mustache", resourceFolder, "application.yaml")); supportingFiles.add(new SupportingFile("springBootApplication.mustache", sanitizeDirectory(sourceFolder + File.separator + basePackage), "Application.kt")); + + if (useSwaggerUI && selectedDocumentationProviderRequiresSwaggerUiBootstrap()) { + supportingFiles.add(new SupportingFile("swagger-ui.mustache", + "src/main/resources/static", "swagger-ui.html")); + } } } + if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider()) && !reactive) { + supportingFiles.add(new SupportingFile("openapiDocumentationConfig.mustache", + (sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), + "SpringFoxConfiguration.kt")); + } + // spring uses the jackson lib, and we disallow configuration. additionalProperties.put("jackson", "true"); @@ -462,7 +596,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen additionalProperties.put("lambdaEscapeDoubleQuote", (Mustache.Lambda) (fragment, writer) -> writer.write(fragment.execute().replaceAll("\"", Matcher.quoteReplacement("\\\"")))); additionalProperties.put("lambdaRemoveLineBreak", - (Mustache.Lambda) (fragment, writer) -> writer.write(fragment.execute().replaceAll("\\r|\\n", ""))); + (Mustache.Lambda) (fragment, writer) -> writer.write(fragment.execute().replaceAll("[\\r\\n]", ""))); } @Override @@ -644,6 +778,13 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen return objs; } + @Override + public Map postProcessSupportingFileData(Map objs) { + generateYAMLSpecFile(objs); + return objs; + } + + private String getNonMutableContainerTypeIfNeeded(String type) { if (type != null && type.contains("kotlin.collections.Mutable")) { return type.replaceAll("kotlin\\.collections\\.Mutable", "kotlin.collections."); @@ -697,8 +838,8 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen // TODO could probably be made more generic, and moved to the `mustache` package if required by other components. private static class EscapeLambda implements Mustache.Lambda { - private String from; - private String to; + private final String from; + private final String to; EscapeLambda(final String from, final String to) { this.from = from; @@ -736,7 +877,6 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen @Override protected boolean needToImport(String type) { // provides extra protection against improperly trying to import language primitives and java types - boolean imports = !type.startsWith("org.springframework.") && super.needToImport(type); - return imports; + return !type.startsWith("org.springframework.") && super.needToImport(type); } } diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache index 1df7886bf2d..db59e8b2d29 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache @@ -2,7 +2,14 @@ package {{package}} {{#imports}}import {{import}} {{/imports}} -{{#swaggerAnnotations}} +{{#swagger2AnnotationLibrary}} +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.* +{{/swagger2AnnotationLibrary}} +{{#swagger1AnnotationLibrary}} import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam @@ -10,7 +17,7 @@ import io.swagger.annotations.ApiResponse import io.swagger.annotations.ApiResponses import io.swagger.annotations.Authorization import io.swagger.annotations.AuthorizationScope -{{/swaggerAnnotations}} +{{/swagger1AnnotationLibrary}} import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity @@ -35,7 +42,7 @@ import javax.validation.constraints.Size {{/useBeanValidation}} {{#reactive}} -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow {{/reactive}} import kotlin.collections.List import kotlin.collections.Map @@ -44,9 +51,9 @@ import kotlin.collections.Map {{#useBeanValidation}} @Validated {{/useBeanValidation}} -{{#swaggerAnnotations}} +{{#swagger1AnnotationLibrary}} @Api(value = "{{{baseName}}}", description = "The {{{baseName}}} API") -{{/swaggerAnnotations}} +{{/swagger1AnnotationLibrary}} {{=<% %>=}} @RequestMapping("\${api.base-path:<%contextPath%>}") <%={{ }}=%> @@ -54,7 +61,15 @@ import kotlin.collections.Map class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) val service: {{classname}}Service{{/serviceInterface}}) { {{#operation}} - {{#swaggerAnnotations}} + {{#swagger2AnnotationLibrary}} + @Operation( + summary = "{{{summary}}}", + operationId = "{{{operationId}}}", + description = "{{{notes}}}", + responses = [{{#responses}} + ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = [Content(schema = Schema(implementation = {{{baseType}}}::class))]{{/baseType}}){{^-last}},{{/-last}}{{/responses}} ]{{#hasAuthMethods}}, + security = [ {{#authMethods}}SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = [ {{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}} ]{{/isOAuth}}){{^-last}},{{/-last}}{{/authMethods}} ]{{/hasAuthMethods}} + ){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}} @ApiOperation( value = "{{{summary}}}", nickname = "{{{operationId}}}", @@ -63,7 +78,7 @@ class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) v responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = [{{#authMethods}}Authorization(value = "{{name}}"{{#isOAuth}}, scopes = [{{#scopes}}AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, {{/-last}}{{/scopes}}]{{/isOAuth}}){{^-last}}, {{/-last}}{{/authMethods}}]{{/hasAuthMethods}}) @ApiResponses( - value = [{{#responses}}ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}::class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}}]){{/swaggerAnnotations}} + value = [{{#responses}}ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}::class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}}]){{/swagger1AnnotationLibrary}} @RequestMapping( method = [RequestMethod.{{httpMethod}}], value = ["{{#lambda.escapeDoubleQuote}}{{path}}{{/lambda.escapeDoubleQuote}}"]{{#singleContentTypes}}{{#hasProduces}}, diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/apiController.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/apiController.mustache index 6e5fdb78a78..037b9d93d73 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/apiController.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/apiController.mustache @@ -1,10 +1,10 @@ -package {{package}}; +package {{package}} + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import java.util.Optional -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import java.util.Optional; {{>generatedAnnotation}} - @Controller{{#beanQualifiers}}("{{package}}.{{classname}}Controller"){{/beanQualifiers}} {{=<% %>=}} @RequestMapping("\${openapi.<%title%>.base-path:<%>defaultBasePath%>}") diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache index 484dca9ca28..391fef9fad5 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache @@ -7,7 +7,14 @@ package {{package}} {{#imports}}import {{import}} {{/imports}} -{{#swaggerAnnotations}} +{{#swagger2AnnotationLibrary}} +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.* +{{/swagger2AnnotationLibrary}} +{{#swagger1AnnotationLibrary}} import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam @@ -15,7 +22,7 @@ import io.swagger.annotations.ApiResponse import io.swagger.annotations.ApiResponses import io.swagger.annotations.Authorization import io.swagger.annotations.AuthorizationScope -{{/swaggerAnnotations}} +{{/swagger1AnnotationLibrary}} import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity @@ -40,7 +47,7 @@ import javax.validation.constraints.Size {{/useBeanValidation}} {{#reactive}} -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow {{/reactive}} import kotlin.collections.List import kotlin.collections.Map @@ -48,9 +55,9 @@ import kotlin.collections.Map {{#useBeanValidation}} @Validated {{/useBeanValidation}} -{{#swaggerAnnotations}} +{{#swagger1AnnotationLibrary}} @Api(value = "{{{baseName}}}", description = "The {{{baseName}}} API") -{{/swaggerAnnotations}} +{{/swagger1AnnotationLibrary}} {{=<% %>=}} @RequestMapping("\${api.base-path:<%contextPath%>}") <%={{ }}=%> @@ -62,7 +69,16 @@ interface {{classname}} { {{/isDelegate}} {{#operation}} - {{#swaggerAnnotations}} + {{#swagger2AnnotationLibrary}} + @Operation( + summary = "{{{summary}}}", + operationId = "{{{operationId}}}", + description = "{{{notes}}}", + responses = [{{#responses}} + ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = [Content(schema = Schema(implementation = {{{baseType}}}::class))]{{/baseType}}){{^-last}},{{/-last}}{{/responses}} + ]{{#hasAuthMethods}}, + security = [ {{#authMethods}}SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = [ {{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}} ]{{/isOAuth}}){{^-last}},{{/-last}}{{/authMethods}} ]{{/hasAuthMethods}} + ){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}} @ApiOperation( value = "{{{summary}}}", nickname = "{{{operationId}}}", @@ -71,7 +87,7 @@ interface {{classname}} { responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = [{{#authMethods}}Authorization(value = "{{name}}"{{#isOAuth}}, scopes = [{{#scopes}}AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, {{/-last}}{{/scopes}}]{{/isOAuth}}){{^-last}}, {{/-last}}{{/authMethods}}]{{/hasAuthMethods}}) @ApiResponses( - value = [{{#responses}}ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}::class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}{{/responses}}]){{/swaggerAnnotations}} + value = [{{#responses}}ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}::class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}}, {{/-last}}{{/responses}}]){{/swagger1AnnotationLibrary}} @RequestMapping( method = [RequestMethod.{{httpMethod}}], value = ["{{#lambda.escapeDoubleQuote}}{{path}}{{/lambda.escapeDoubleQuote}}"]{{#singleContentTypes}}{{#hasProduces}}, @@ -85,7 +101,7 @@ interface {{classname}} { return {{>returnValue}} {{/isDelegate}} {{#isDelegate}} - return getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}); + return getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) {{/isDelegate}} } {{/operation}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/api_test.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/api_test.mustache index 8cca99bb5b5..d8e02649934 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/api_test.mustache @@ -4,7 +4,7 @@ package {{package}} {{/imports}} import org.junit.jupiter.api.Test {{#reactive}} -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.test.runBlockingTest {{/reactive}} import org.springframework.http.ResponseEntity @@ -15,9 +15,9 @@ class {{classname}}Test { private val service: {{classname}}Service = {{classname}}ServiceImpl() {{/serviceInterface}} private val api: {{classname}}Controller = {{classname}}Controller({{#serviceInterface}}service{{/serviceInterface}}) - {{#operations}} {{#operation}} + /** * To test {{classname}}Controller.{{operationId}} * @@ -27,13 +27,12 @@ class {{classname}}Test { @Test fun {{operationId}}Test() {{#reactive}}= runBlockingTest {{/reactive}}{ {{#allParams}} - val {{paramName}}:{{>optionalDataType}} = TODO() + val {{paramName}}: {{>optionalDataType}} = TODO() {{/allParams}} val response: ResponseEntity<{{>returnTypes}}> = api.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) // TODO: test validations } - {{/operation}} {{/operations}} } diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/bodyParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/bodyParams.mustache index 116cdbdb7d2..321b15e5154 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/bodyParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/bodyParams.mustache @@ -1 +1 @@ -{{#isBodyParam}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{^isContainer}}{{#allowableValues}}, allowableValues="{{{.}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue="{{{.}}}"{{/defaultValue}}){{/swaggerAnnotations}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{paramName}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}} \ No newline at end of file +{{#isBodyParam}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"], defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"]){{/defaultValue}}{{/allowableValues}}{{/isContainer}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}, allowableValues = "{{{.}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{paramName}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache index 17191e94dd5..e56f233800c 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache @@ -26,9 +26,8 @@ * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} */ enum class {{{nameInCamelCase}}}(val value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}) { - {{#allowableValues}}{{#enumVars}} - @JsonProperty({{{value}}}) {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} - {{/enumVars}}{{/allowableValues}} +{{#allowableValues}}{{#enumVars}} + @JsonProperty({{{value}}}) {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} } {{/isEnum}}{{/vars}}{{/hasEnums}} } diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassOptVar.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassOptVar.mustache index 64b91fd260e..a937222e862 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassOptVar.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassOptVar.mustache @@ -1,4 +1,5 @@ -{{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}} - @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}{{#deprecated}} +{{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}} + @Schema({{#example}}example = "{{{.}}}", {{/example}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}} + @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}{{#deprecated}} @Deprecated(message = ""){{/deprecated}} @field:JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInCamelCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassReqVar.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassReqVar.mustache index d69a07dd85a..30ff9e9a7c9 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassReqVar.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClassReqVar.mustache @@ -1,3 +1,4 @@ -{{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}} - @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}} +{{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}} + @Schema({{#example}}example = "{{{.}}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}} + @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}} @field:JsonProperty("{{{baseName}}}", required = true){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInCamelCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isReadOnly}}?{{/isReadOnly}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{#isReadOnly}}{{^defaultValue}} = null{{/defaultValue}}{{/isReadOnly}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/enumClass.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/enumClass.mustache index bd0794c7f12..572875356af 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/enumClass.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/enumClass.mustache @@ -4,6 +4,5 @@ */ enum class {{classname}}(val value: {{dataType}}) { {{#allowableValues}}{{#enumVars}} - @JsonProperty({{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} -{{/enumVars}}{{/allowableValues}} + @JsonProperty({{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} } diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/formParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/formParams.mustache index 97eeec42693..ec72b53b7d8 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/formParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/formParams.mustache @@ -1 +1 @@ -{{#isFormParam}}{{^isFile}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{.}}}"{{/defaultValue}}){{/swaggerAnnotations}} @RequestParam(value="{{baseName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{paramName}}: {{>optionalDataType}} {{/isFile}}{{#isFile}}{{#swaggerAnnotations}}@ApiParam(value = "file detail"){{/swaggerAnnotations}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestPart("file") {{baseName}}: {{>optionalDataType}}{{/isFile}}{{/isFormParam}} +{{#isFormParam}}{{^isFile}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @RequestParam(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}) {{paramName}}: {{>optionalDataType}} {{/isFile}}{{#isFile}}{{#swagger2AnnotationLibrary}}@Parameter(description = "file detail"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "file detail"){{/swagger1AnnotationLibrary}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestPart("file") {{baseName}}: {{>optionalDataType}}{{/isFile}}{{/isFormParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/headerParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/headerParams.mustache index 826e24a4416..9bc3f6002e9 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/headerParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/headerParams.mustache @@ -1 +1 @@ -{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationPath}}{{/useBeanValidation}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{.}}}"{{/defaultValue}}){{/swaggerAnnotations}} @RequestHeader(value="{{baseName}}", required={{#required}}true{{/required}}{{^required}}false{{/required}}) {{paramName}}: {{>optionalDataType}}{{/isHeaderParam}} \ No newline at end of file +{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationPath}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}", `in` = ParameterIn.HEADER{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @RequestHeader(value = "{{baseName}}", required = {{#required}}true{{/required}}{{^required}}false{{/required}}) {{paramName}}: {{>optionalDataType}}{{/isHeaderParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/homeController.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/homeController.mustache new file mode 100644 index 00000000000..609ebcd790c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/homeController.mustache @@ -0,0 +1,89 @@ +package {{basePackage}} + +import org.springframework.context.annotation.Bean +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +{{#sourceDocumentationProvider}} +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper +import org.springframework.beans.factory.annotation.Value +import org.springframework.core.io.Resource +import org.springframework.util.StreamUtils +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.GetMapping +{{/sourceDocumentationProvider}} +{{^sourceDocumentationProvider}} +{{#useSwaggerUI}} +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.GetMapping +{{/useSwaggerUI}} +{{/sourceDocumentationProvider}} +{{#reactive}} +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 +{{/reactive}} +{{#sourceDocumentationProvider}} +import java.nio.charset.Charset +{{/sourceDocumentationProvider}} + +/** + * Home redirection to OpenAPI api documentation + */ +@Controller +class HomeController { +{{#useSwaggerUI}} +{{^springDocDocumentationProvider}} +{{#sourceDocumentationProvider}} + private val apiDocsPath = "/openapi.json" +{{/sourceDocumentationProvider}} +{{#springFoxDocumentationProvider}} + private val apiDocsPath = "/v2/api-docs" +{{/springFoxDocumentationProvider}} +{{/springDocDocumentationProvider}} +{{/useSwaggerUI}} +{{#sourceDocumentationProvider}} + private val yamlMapper = YAMLMapper() + + @Value("classpath:/openapi.yaml") + private lateinit var openapi: Resource + + @Bean + fun openapiContent(): String { + return openapi.inputStream.use { + StreamUtils.copyToString(it, Charset.defaultCharset()) + } + } + + @GetMapping(value = ["/openapi.yaml"], produces = ["application/vnd.oai.openapi"]) + @ResponseBody + fun openapiYaml(): String = openapiContent() + + @GetMapping(value = ["/openapi.json"], produces = ["application/json"]) + @ResponseBody + fun openapiJson(): Any = yamlMapper.readValue(openapiContent(), Any::class.java) +{{/sourceDocumentationProvider}} +{{#useSwaggerUI}} +{{^springDocDocumentationProvider}} + + @GetMapping(value = ["/swagger-config.yaml"], produces = ["text/plain"]) + @ResponseBody + fun swaggerConfig(): String = "url: $apiDocsPath\n" +{{/springDocDocumentationProvider}} +{{#reactive}} + + @Bean + fun index(): RouterFunction = route( + GET("/"), HandlerFunction { + ServerResponse.temporaryRedirect(URI.create("swagger-ui.html")).build() + }) +{{/reactive}} +{{^reactive}} + + @RequestMapping("/") + fun index(): String = "redirect:swagger-ui.html" +{{/reactive}} +{{/useSwaggerUI}} +} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/interfaceOptVar.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/interfaceOptVar.mustache index 2011f366408..28ad4702783 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/interfaceOptVar.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/interfaceOptVar.mustache @@ -1,3 +1,4 @@ -{{#swaggerAnnotations}} - @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}} - {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/discriminator}} \ No newline at end of file +{{#swagger2AnnotationLibrary}} + @Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}} + @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}} + {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/discriminator}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/interfaceReqVar.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/interfaceReqVar.mustache index 32119c0dfd0..c742f0ec5c9 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/interfaceReqVar.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/interfaceReqVar.mustache @@ -1,3 +1,4 @@ -{{#swaggerAnnotations}} - @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}} - {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}} \ No newline at end of file +{{#swagger2AnnotationLibrary}} + @Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}} + @ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}} + {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/buildGradleKts.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/buildGradleKts.mustache index 699361be13f..6d3eac02783 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/buildGradleKts.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/buildGradleKts.mustache @@ -30,23 +30,29 @@ plugins { } dependencies { - val kotlinxCoroutinesVersion="1.2.0" - compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - compile("org.jetbrains.kotlin:kotlin-reflect") -{{^reactive}} - compile("org.springframework.boot:spring-boot-starter-web") -{{/reactive}} -{{#reactive}} +{{#reactive}} val kotlinxCoroutinesVersion = "1.2.0" +{{/reactive}} compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + compile("org.jetbrains.kotlin:kotlin-reflect"){{^reactive}} + compile("org.springframework.boot:spring-boot-starter-web"){{/reactive}}{{#reactive}} compile("org.springframework.boot:spring-boot-starter-webflux") compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") - compile("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion") -{{/reactive}} -{{#swaggerAnnotations}} - compile("io.swagger:swagger-annotations:1.5.21") -{{/swaggerAnnotations}} + compile("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion"){{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}} + compile("org.springdoc:springdoc-openapi-{{#reactive}}webflux-{{/reactive}}ui:1.6.6"){{/useSwaggerUI}}{{^useSwaggerUI}} + compile("org.springdoc:springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core:1.6.6"){{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}} + compile("io.springfox:springfox-swagger2:2.9.2"){{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}} + compile("org.webjars:swagger-ui:4.8.1") + compile("org.webjars:webjars-locator-core"){{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}} + compile("io.swagger:swagger-annotations:1.6.5"){{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}} + compile("io.swagger.core.v3:swagger-annotations:2.1.13"){{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}} + + compile("com.google.code.findbugs:jsr305:3.0.2") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") compile("com.fasterxml.jackson.module:jackson-module-kotlin") +{{#useBeanValidation}} + compile("jakarta.validation:jakarta.validation-api"){{/useBeanValidation}} + compile("jakarta.annotation:jakarta.annotation-api:1.3.5") testCompile("org.jetbrains.kotlin:kotlin-test-junit5") testCompile("org.springframework.boot:spring-boot-starter-test") { diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/pom.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/pom.mustache index 7c11199c579..2ac4871e094 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/pom.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/pom.mustache @@ -5,11 +5,19 @@ jar {{artifactId}} {{artifactVersion}} - - UTF-8 + {{#reactive}} + 1.2.0{{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}} + 1.6.6{{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}} + 2.9.2{{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}} + 4.8.1{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}} + 1.6.5{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}} + 2.1.13{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}} + 3.0.2 + 1.3.5 + 1.3.31 + 1.3.30 - 1.2.0 - 1.3.5 + UTF-8 org.springframework.boot @@ -77,17 +85,15 @@ org.jetbrains.kotlin kotlin-reflect ${kotlin.version} - + {{^reactive}} org.springframework.boot -{{^reactive}} spring-boot-starter-web -{{/reactive}} -{{#reactive}} + {{/reactive}}{{#reactive}} + + org.springframework.boot spring-boot-starter-webflux -{{/reactive}} -{{#reactive}} org.jetbrains.kotlinx kotlinx-coroutines-core @@ -97,21 +103,51 @@ org.jetbrains.kotlinx kotlinx-coroutines-reactor ${kotlinx-coroutines.version} - -{{/reactive}} + {{/reactive}} - {{#swaggerAnnotations}} +{{#springDocDocumentationProvider}} + {{#useSwaggerUI}} + + org.springdoc + springdoc-openapi-{{#reactive}}webflux-{{/reactive}}ui + ${springdoc-openapi.version} + {{/useSwaggerUI}}{{^useSwaggerUI}} + + org.springdoc + springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core + ${springdoc-openapi.version} + {{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}} + + + io.springfox + springfox-swagger2 + ${springfox-swagger2.version} + {{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}} + + org.webjars + swagger-ui + ${swagger-ui.version} + + + org.webjars + webjars-locator-core + {{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}} io.swagger swagger-annotations - 1.5.21 - - {{/swaggerAnnotations}} + ${swagger-annotations.version} + {{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}} + + io.swagger.core.v3 + swagger-annotations + ${swagger-annotations.version} + {{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}} + com.google.code.findbugs jsr305 - 3.0.2 + ${findbugs-jsr305.version} com.fasterxml.jackson.dataformat @@ -129,23 +165,22 @@ com.fasterxml.jackson.module jackson-module-kotlin - {{#useBeanValidation}} +{{#useBeanValidation}} jakarta.validation jakarta.validation-api - - {{/useBeanValidation}} + {{/useBeanValidation}} jakarta.annotation jakarta.annotation-api - ${jakarta-annotation-version} + ${jakarta-annotation.version} provided org.jetbrains.kotlin kotlin-test-junit5 - 1.3.31 + ${kotlin-test-junit5.version} test diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/springBootApplication.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/springBootApplication.mustache index 5b0d62ebf0a..3692d6d763f 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/springBootApplication.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/springBootApplication.mustache @@ -1,9 +1,8 @@ package {{basePackage}} import org.springframework.boot.runApplication -import org.springframework.context.annotation.ComponentScan import org.springframework.boot.autoconfigure.SpringBootApplication - +import org.springframework.context.annotation.ComponentScan @SpringBootApplication @ComponentScan(basePackages = ["{{basePackage}}", "{{apiPackage}}", "{{modelPackage}}"]) diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/swagger-ui.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/swagger-ui.mustache new file mode 100644 index 00000000000..f85b6654f67 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/swagger-ui.mustache @@ -0,0 +1,60 @@ + + + + + + Swagger UI + + + + + + + +
+ + + + + + diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/model.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/model.mustache index 4dcc67b81b3..f7bdf28fd68 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/model.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/model.mustache @@ -14,9 +14,12 @@ import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid {{/useBeanValidation}} -{{#swaggerAnnotations}} +{{#swagger2AnnotationLibrary}} +import io.swagger.v3.oas.annotations.media.Schema +{{/swagger2AnnotationLibrary}} +{{#swagger1AnnotationLibrary}} import io.swagger.annotations.ApiModelProperty -{{/swaggerAnnotations}} +{{/swagger1AnnotationLibrary}} {{#models}} {{#model}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/openapi.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/openapi.mustache new file mode 100644 index 00000000000..51ebafb0187 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/openapi.mustache @@ -0,0 +1 @@ +{{{openapi-yaml}}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/openapiDocumentationConfig.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/openapiDocumentationConfig.mustache new file mode 100644 index 00000000000..ee84664ee3f --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/openapiDocumentationConfig.mustache @@ -0,0 +1,65 @@ +package {{basePackage}} + +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.web.util.UriComponentsBuilder +import springfox.documentation.builders.ApiInfoBuilder +import springfox.documentation.builders.RequestHandlerSelectors +import springfox.documentation.service.ApiInfo +import springfox.documentation.service.Contact +import springfox.documentation.spi.DocumentationType +import springfox.documentation.spring.web.paths.Paths +import springfox.documentation.spring.web.paths.RelativePathProvider +import springfox.documentation.spring.web.plugins.Docket +import springfox.documentation.swagger2.annotations.EnableSwagger2 +import javax.servlet.ServletContext + +{{>generatedAnnotation}} +@Configuration +@EnableSwagger2 +class SpringFoxConfiguration { + + fun apiInfo(): ApiInfo { + return ApiInfoBuilder() + .title("{{appName}}") + .description("{{{appDescription}}}") + .license("{{licenseInfo}}") + .licenseUrl("{{licenseUrl}}") + .termsOfServiceUrl("{{infoUrl}}") + .version("{{appVersion}}") + .contact(Contact("", "", "{{infoEmail}}")) + .build() + } + + @Bean +{{=<% %>=}} + fun customImplementation(servletContext: ServletContext, @Value("\${openapi.<%title%>.base-path:<%>defaultBasePath%>}") basePath: String): Docket { +<%={{ }}=%> + return Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.basePackage("{{apiPackage}}")) + .build() + .pathProvider(BasePathAwareRelativePathProvider(servletContext, basePath)) + .directModelSubstitute(java.time.LocalDate::class.java, java.sql.Date::class.java) + .directModelSubstitute(java.time.OffsetDateTime::class.java, java.util.Date::class.java) + .apiInfo(apiInfo()) + } + + class BasePathAwareRelativePathProvider(servletContext: ServletContext, private val basePath: String) : + RelativePathProvider(servletContext) { + + override fun applicationPath(): String { + return Paths.removeAdjacentForwardSlashes( + UriComponentsBuilder.fromPath(super.applicationPath()).path(basePath).build().toString() + ) + } + + override fun getOperationPath(operationPath: String): String { + val uriComponentsBuilder = UriComponentsBuilder.fromPath("/") + return Paths.removeAdjacentForwardSlashes( + uriComponentsBuilder.path(operationPath.replaceFirst("^$basePath", "")).build().toString() + ) + } + } +} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/pathParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/pathParams.mustache index a944d72af26..957ca220c3d 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/pathParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/pathParams.mustache @@ -1 +1 @@ -{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, allowableValues = "{{#enumVars}}{{#lambda.escapeDoubleQuote}}{{{value}}}{{/lambda.escapeDoubleQuote}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/enumVars}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{.}}}"{{/defaultValue}}){{/swaggerAnnotations}} @PathVariable("{{baseName}}") {{paramName}}: {{>optionalDataType}}{{/isPathParam}} \ No newline at end of file +{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#enumVars}}"{{#lambdaEscapeDoubleQuote}}{{{value}}}{{/lambdaEscapeDoubleQuote}}"{{^-last}}, {{/-last}}{{/enumVars}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}{{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#enumVars}}"{{#lambdaEscapeDoubleQuote}}{{{value}}}{{/lambdaEscapeDoubleQuote}}"{{^-last}}, {{/-last}}{{/enumVars}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#enumVars}}{{#lambda.escapeDoubleQuote}}{{{value}}}{{/lambda.escapeDoubleQuote}}{{^-last}}, {{/-last}}{{/enumVars}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @PathVariable("{{baseName}}") {{paramName}}: {{>optionalDataType}}{{/isPathParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/queryParams.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/queryParams.mustache index d160962517f..3c254c53ff0 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/queryParams.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/queryParams.mustache @@ -1 +1 @@ -{{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{#swaggerAnnotations}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/allowableValues}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}) {{#useBeanValidation}}@Valid{{/useBeanValidation}}{{/swaggerAnnotations}}{{^isModel}} @RequestParam(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{^isContainer}}{{#defaultValue}}, defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}){{/isModel}}{{#isDate}} @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE){{/isDate}}{{#isDateTime}} @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME){{/isDateTime}} {{paramName}}: {{>optionalDataType}}{{/isQueryParam}} \ No newline at end of file +{{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}){{/swagger1AnnotationLibrary}}{{#useBeanValidation}} @Valid{{/useBeanValidation}}{{^isModel}} @RequestParam(value = "{{baseName}}"{{#required}}, required = true{{/required}}{{^required}}, required = false{{/required}}{{^isContainer}}{{#defaultValue}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}){{/isModel}}{{#isDate}} @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE){{/isDate}}{{#isDateTime}} @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME){{/isDateTime}} {{paramName}}: {{>optionalDataType}}{{/isQueryParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/service.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/service.mustache index c823d7a32ac..875cdfba2dd 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/service.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/service.mustache @@ -3,7 +3,7 @@ package {{package}} {{#imports}}import {{import}} {{/imports}} {{#reactive}} -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow {{/reactive}} {{#operations}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/serviceImpl.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/serviceImpl.mustache index 9f7d18a5301..75f4fda598c 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/serviceImpl.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/serviceImpl.mustache @@ -3,7 +3,7 @@ package {{package}} {{#imports}}import {{import}} {{/imports}} {{#reactive}} -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow {{/reactive}} import org.springframework.stereotype.Service @Service 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 20be80f2f55..f65380a13c5 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 @@ -1,17 +1,11 @@ package org.openapitools.codegen.kotlin.spring; -import static org.openapitools.codegen.TestUtils.assertFileContains; -import static org.openapitools.codegen.TestUtils.assertFileNotContains; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Collections; -import java.util.List; - import com.google.common.collect.testing.Helpers; - +import io.swagger.parser.OpenAPIParser; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.servers.Server; +import io.swagger.v3.parser.core.models.ParseOptions; import org.apache.commons.io.FileUtils; import org.openapitools.codegen.ClientOptInput; import org.openapitools.codegen.CodegenConstants; @@ -23,11 +17,15 @@ import org.openapitools.codegen.languages.features.CXFServerFeatures; import org.testng.Assert; import org.testng.annotations.Test; -import io.swagger.parser.OpenAPIParser; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.servers.Server; -import io.swagger.v3.parser.core.models.ParseOptions; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.List; + +import static org.openapitools.codegen.TestUtils.assertFileContains; +import static org.openapitools.codegen.TestUtils.assertFileNotContains; public class KotlinSpringServerCodegenTest { @@ -48,7 +46,7 @@ public class KotlinSpringServerCodegenTest { File outputModel = Files.createTempDirectory("test").toFile().getCanonicalFile(); FileUtils.copyDirectory(new File(resultSourcePath, baseModelPackage), new File(outputModel, baseModelPackage)); //no exception - ClassLoader cl = KotlinTestUtils.buildModule(Collections.singletonList(outputModel.getAbsolutePath()), Thread.currentThread().getContextClassLoader()); + KotlinTestUtils.buildModule(Collections.singletonList(outputModel.getAbsolutePath()), Thread.currentThread().getContextClassLoader()); } @Test @@ -85,7 +83,6 @@ public class KotlinSpringServerCodegenTest { codegen.setServerPort("8181"); codegen.setExceptionHandler(false); codegen.setGradleBuildFile(false); - codegen.setSwaggerAnnotations(true); codegen.setServiceInterface(true); codegen.setServiceImplementation(true); codegen.setUseBeanValidation(false); @@ -104,8 +101,6 @@ public class KotlinSpringServerCodegenTest { Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.EXCEPTION_HANDLER), false); Assert.assertFalse(codegen.getGradleBuildFile()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.GRADLE_BUILD_FILE), false); - Assert.assertTrue(codegen.getSwaggerAnnotations()); - Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SWAGGER_ANNOTATIONS), true); Assert.assertTrue(codegen.getServiceInterface()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVICE_INTERFACE), true); Assert.assertTrue(codegen.getServiceImplementation()); @@ -125,7 +120,6 @@ public class KotlinSpringServerCodegenTest { codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVER_PORT, "8088"); codegen.additionalProperties().put(KotlinSpringServerCodegen.EXCEPTION_HANDLER, false); codegen.additionalProperties().put(KotlinSpringServerCodegen.GRADLE_BUILD_FILE, false); - codegen.additionalProperties().put(KotlinSpringServerCodegen.SWAGGER_ANNOTATIONS, true); codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVICE_INTERFACE, true); codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVICE_IMPLEMENTATION, true); codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_BEANVALIDATION, false); @@ -150,8 +144,6 @@ public class KotlinSpringServerCodegenTest { Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.EXCEPTION_HANDLER), false); Assert.assertFalse(codegen.getGradleBuildFile()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.GRADLE_BUILD_FILE), false); - Assert.assertTrue(codegen.getSwaggerAnnotations()); - Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SWAGGER_ANNOTATIONS), true); Assert.assertTrue(codegen.getServiceInterface()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVICE_INTERFACE), true); Assert.assertTrue(codegen.getServiceImplementation()); @@ -180,8 +172,6 @@ public class KotlinSpringServerCodegenTest { Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.DELEGATE_PATTERN), true); Assert.assertEquals(codegen.additionalProperties().get("isDelegate"), "true"); - Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SWAGGER_ANNOTATIONS), false); - Assert.assertTrue(codegen.getSwaggerAnnotations()); Assert.assertEquals(codegen.apiTemplateFiles().get("apiController.mustache"), "Controller.kt"); Assert.assertEquals(codegen.apiTemplateFiles().get("apiDelegate.mustache"), "Delegate.kt"); diff --git a/samples/server/petstore/kotlin-springboot-delegate/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-delegate/.openapi-generator/FILES index c02ae2405be..c9dafaf7207 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/.openapi-generator/FILES +++ b/samples/server/petstore/kotlin-springboot-delegate/.openapi-generator/FILES @@ -3,6 +3,7 @@ build.gradle.kts 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/Exceptions.kt src/main/kotlin/org/openapitools/api/PetApi.kt @@ -21,3 +22,4 @@ 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-delegate/build.gradle.kts b/samples/server/petstore/kotlin-springboot-delegate/build.gradle.kts index ea7f93398da..f7432a5df77 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/build.gradle.kts +++ b/samples/server/petstore/kotlin-springboot-delegate/build.gradle.kts @@ -30,14 +30,18 @@ plugins { } dependencies { - val kotlinxCoroutinesVersion="1.2.0" compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") compile("org.jetbrains.kotlin:kotlin-reflect") compile("org.springframework.boot:spring-boot-starter-web") - compile("io.swagger:swagger-annotations:1.5.21") + compile("org.springdoc:springdoc-openapi-ui:1.6.6") + + compile("com.google.code.findbugs:jsr305:3.0.2") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") compile("com.fasterxml.jackson.module:jackson-module-kotlin") + compile("jakarta.validation:jakarta.validation-api") + compile("jakarta.annotation:jakarta.annotation-api:1.3.5") testCompile("org.jetbrains.kotlin:kotlin-test-junit5") testCompile("org.springframework.boot:spring-boot-starter-test") { diff --git a/samples/server/petstore/kotlin-springboot-delegate/pom.xml b/samples/server/petstore/kotlin-springboot-delegate/pom.xml index 4d5fc7828f6..63eff7b8561 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/pom.xml +++ b/samples/server/petstore/kotlin-springboot-delegate/pom.xml @@ -6,10 +6,13 @@ openapi-spring 1.0.0 - UTF-8 + 1.6.6 + 3.0.2 + 1.3.5 + 1.3.31 + 1.3.30 - 1.2.0 - 1.3.5 + UTF-8 org.springframework.boot @@ -83,16 +86,18 @@ spring-boot-starter-web + - io.swagger - swagger-annotations - 1.5.21 + org.springdoc + springdoc-openapi-ui + ${springdoc-openapi.version} + com.google.code.findbugs jsr305 - 3.0.2 + ${findbugs-jsr305.version} com.fasterxml.jackson.dataformat @@ -118,13 +123,13 @@ jakarta.annotation jakarta.annotation-api - ${jakarta-annotation-version} + ${jakarta-annotation.version} provided org.jetbrains.kotlin kotlin-test-junit5 - 1.3.31 + ${kotlin-test-junit5.version} test diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/Application.kt index f2ee49d476b..2fe6de62479 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/Application.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/Application.kt @@ -1,9 +1,8 @@ package org.openapitools import org.springframework.boot.runApplication -import org.springframework.context.annotation.ComponentScan import org.springframework.boot.autoconfigure.SpringBootApplication - +import org.springframework.context.annotation.ComponentScan @SpringBootApplication @ComponentScan(basePackages = ["org.openapitools", "org.openapitools.api", "org.openapitools.model"]) diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/HomeController.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/HomeController.kt new file mode 100644 index 00000000000..0b75544d7a1 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/HomeController.kt @@ -0,0 +1,17 @@ +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 + +/** + * Home redirection to OpenAPI api documentation + */ +@Controller +class HomeController { + + @RequestMapping("/") + fun index(): String = "redirect:swagger-ui.html" +} diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt index 3115f0adfb9..82ef7c598f3 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApi.kt @@ -7,13 +7,11 @@ package org.openapitools.api import org.openapitools.model.ModelApiResponse import org.openapitools.model.Pet -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope +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 @@ -37,160 +35,162 @@ import kotlin.collections.List import kotlin.collections.Map @Validated -@Api(value = "pet", description = "The pet API") @RequestMapping("\${api.base-path:/v2}") interface PetApi { fun getDelegate(): PetApiDelegate = object: PetApiDelegate {} - @ApiOperation( - value = "Add a new pet to the store", - nickname = "addPet", - notes = "", - response = Pet::class, - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 405, message = "Invalid input")]) + @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"] ) - fun addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody pet: Pet -): ResponseEntity { - return getDelegate().addPet(pet); + fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + return getDelegate().addPet(pet) } - @ApiOperation( - value = "Deletes a pet", - nickname = "deletePet", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid pet value")]) + @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}"] ) - fun deletePet(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: kotlin.String? -): ResponseEntity { - return getDelegate().deletePet(petId, apiKey); + fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + return getDelegate().deletePet(petId, apiKey) } - @ApiOperation( - value = "Finds Pets by status", - nickname = "findPetsByStatus", - notes = "Multiple status values can be provided with comma separated strings", - response = Pet::class, - responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid status value")]) + @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(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 @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List -): ResponseEntity> { - return getDelegate().findPetsByStatus(status); + fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + return getDelegate().findPetsByStatus(status) } - @ApiOperation( - value = "Finds Pets by tags", - nickname = "findPetsByTags", - notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", - response = Pet::class, - responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid tag value")]) + @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(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 @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List -): ResponseEntity> { - return getDelegate().findPetsByTags(tags); + fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + return getDelegate().findPetsByTags(tags) } - @ApiOperation( - value = "Find pet by ID", - nickname = "getPetById", - notes = "Returns a single pet", - response = Pet::class, - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found")]) + @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"] ) - fun getPetById(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: kotlin.Long -): ResponseEntity { - return getDelegate().getPetById(petId); + fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + return getDelegate().getPetById(petId) } - @ApiOperation( - value = "Update an existing pet", - nickname = "updatePet", - notes = "", - response = Pet::class, - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found"),ApiResponse(code = 405, message = "Validation exception")]) + @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"] ) - fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody pet: Pet -): ResponseEntity { - return getDelegate().updatePet(pet); + fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity { + return getDelegate().updatePet(pet) } - @ApiOperation( - value = "Updates a pet in the store with form data", - nickname = "updatePetWithForm", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + @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"] ) - fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "Updated name of the pet") @RequestParam(value="name", required=false) name: kotlin.String? -,@ApiParam(value = "Updated status of the pet") @RequestParam(value="status", required=false) status: kotlin.String? -): ResponseEntity { - return getDelegate().updatePetWithForm(petId, name, status); + 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 getDelegate().updatePetWithForm(petId, name, status) } - @ApiOperation( - value = "uploads an image", - nickname = "uploadFile", - notes = "", - response = ModelApiResponse::class, - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) + @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"] ) - fun uploadFile(@ApiParam(value = "ID of pet to update", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "Additional data to pass to server") @RequestParam(value="additionalMetadata", required=false) additionalMetadata: kotlin.String? -,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource? -): ResponseEntity { - return getDelegate().uploadFile(petId, additionalMetadata, file); + 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 detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?): ResponseEntity { + return getDelegate().uploadFile(petId, additionalMetadata, file) } } diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApiController.kt index d54d3090b74..ac2e8fb6076 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -1,10 +1,10 @@ -package org.openapitools.api; +package org.openapitools.api + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import java.util.Optional -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import java.util.Optional; @javax.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"]) - @Controller @RequestMapping("\${openapi.openAPIPetstore.base-path:/v2}") class PetApiController( diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt index fba10fa0b6b..dbbc8cf13a8 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApi.kt @@ -6,13 +6,11 @@ package org.openapitools.api import org.openapitools.model.Order -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope +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 @@ -36,77 +34,81 @@ import kotlin.collections.List import kotlin.collections.Map @Validated -@Api(value = "store", description = "The store API") @RequestMapping("\${api.base-path:/v2}") interface StoreApi { fun getDelegate(): StoreApiDelegate = object: StoreApiDelegate {} - @ApiOperation( - value = "Delete purchase order by ID", - nickname = "deleteOrder", - notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors") - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @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}"] ) - fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required=true) @PathVariable("orderId") orderId: kotlin.String -): ResponseEntity { - return getDelegate().deleteOrder(orderId); + fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + return getDelegate().deleteOrder(orderId) } - @ApiOperation( - value = "Returns pet inventories by status", - nickname = "getInventory", - notes = "Returns a map of status codes to quantities", - response = kotlin.Int::class, - responseContainer = "Map", - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")]) + @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"] ) fun getInventory(): ResponseEntity> { - return getDelegate().getInventory(); + return getDelegate().getInventory() } - @ApiOperation( - value = "Find purchase order by ID", - nickname = "getOrderById", - notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", - response = Order::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @Operation( + summary = "Find purchase order by ID", + operationId = "getOrderById", + description = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated 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"] ) - fun getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required=true) @PathVariable("orderId") orderId: kotlin.Long -): ResponseEntity { - return getDelegate().getOrderById(orderId); + 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 getDelegate().getOrderById(orderId) } - @ApiOperation( - value = "Place an order for a pet", - nickname = "placeOrder", - notes = "", - response = Order::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")]) + @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"] ) - fun placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody order: Order -): ResponseEntity { - return getDelegate().placeOrder(order); + fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order): ResponseEntity { + return getDelegate().placeOrder(order) } } diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApiController.kt index 61e0896b172..3f52082c4c0 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -1,10 +1,10 @@ -package org.openapitools.api; +package org.openapitools.api + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import java.util.Optional -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import java.util.Optional; @javax.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"]) - @Controller @RequestMapping("\${openapi.openAPIPetstore.base-path:/v2}") class StoreApiController( diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt index 2cbe1742aed..2621f922eb9 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApi.kt @@ -6,13 +6,11 @@ package org.openapitools.api import org.openapitools.model.User -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope +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 @@ -36,144 +34,153 @@ import kotlin.collections.List import kotlin.collections.Map @Validated -@Api(value = "user", description = "The user API") @RequestMapping("\${api.base-path:/v2}") interface UserApi { fun getDelegate(): UserApiDelegate = object: UserApiDelegate {} - @ApiOperation( - value = "Create user", - nickname = "createUser", - notes = "This can only be done by the logged in user.", - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @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"] ) - fun createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody user: User -): ResponseEntity { - return getDelegate().createUser(user); + fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + return getDelegate().createUser(user) } - @ApiOperation( - value = "Creates list of users with given input array", - nickname = "createUsersWithArrayInput", - notes = "", - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @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"] ) - fun createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody user: kotlin.collections.List -): ResponseEntity { - return getDelegate().createUsersWithArrayInput(user); + fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + return getDelegate().createUsersWithArrayInput(user) } - @ApiOperation( - value = "Creates list of users with given input array", - nickname = "createUsersWithListInput", - notes = "", - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @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"] ) - fun createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody user: kotlin.collections.List -): ResponseEntity { - return getDelegate().createUsersWithListInput(user); + fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List): ResponseEntity { + return getDelegate().createUsersWithListInput(user) } - @ApiOperation( - value = "Delete user", - nickname = "deleteUser", - notes = "This can only be done by the logged in user.", - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @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}"] ) - fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true) @PathVariable("username") username: kotlin.String -): ResponseEntity { - return getDelegate().deleteUser(username); + fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + return getDelegate().deleteUser(username) } - @ApiOperation( - value = "Get user by user name", - nickname = "getUserByName", - notes = "", - response = User::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = User::class),ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @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"] ) - fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required=true) @PathVariable("username") username: kotlin.String -): ResponseEntity { - return getDelegate().getUserByName(username); + fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + return getDelegate().getUserByName(username) } - @ApiOperation( - value = "Logs user into the system", - nickname = "loginUser", - notes = "", - response = kotlin.String::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")]) + @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"] ) - fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String -,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String -): ResponseEntity { - return getDelegate().loginUser(username, password); + fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + return getDelegate().loginUser(username, password) } - @ApiOperation( - value = "Logs out current logged in user session", - nickname = "logoutUser", - notes = "", - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @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"] ) fun logoutUser(): ResponseEntity { - return getDelegate().logoutUser(); + return getDelegate().logoutUser() } - @ApiOperation( - value = "Updated user", - nickname = "updateUser", - notes = "This can only be done by the logged in user.", - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid user supplied"),ApiResponse(code = 404, message = "User not found")]) + @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"] ) - fun updateUser(@ApiParam(value = "name that need to be deleted", required=true) @PathVariable("username") username: kotlin.String -,@ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody user: User -): ResponseEntity { - return getDelegate().updateUser(username, user); + fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User): ResponseEntity { + return getDelegate().updateUser(username, user) } } diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApiController.kt index a3f243b7552..a9b1b3300c0 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -1,10 +1,10 @@ -package org.openapitools.api; +package org.openapitools.api + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import java.util.Optional -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import java.util.Optional; @javax.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"]) - @Controller @RequestMapping("\${openapi.openAPIPetstore.base-path:/v2}") class UserApiController( diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Category.kt index 5459864c074..3819c9bc2d0 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Category.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Category.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A category for a pet @@ -20,11 +20,11 @@ import io.swagger.annotations.ApiModelProperty */ data class Category( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") val id: kotlin.Long? = null, @get:Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("name") val name: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt index 6b3e10c5694..b8a5657e99d 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * Describes the result of uploading an image resource @@ -21,13 +21,13 @@ import io.swagger.annotations.ApiModelProperty */ data class ModelApiResponse( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("code") val code: kotlin.Int? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("type") val type: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("message") val message: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Order.kt index c81e062d3f9..4494ffa95bd 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Order.kt @@ -12,7 +12,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * An order for a pets from the pet store @@ -25,22 +25,22 @@ import io.swagger.annotations.ApiModelProperty */ data class Order( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("petId") val petId: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("quantity") val quantity: kotlin.Int? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, - @ApiModelProperty(example = "null", value = "Order Status") + @Schema(example = "null", description = "Order Status") @field:JsonProperty("status") val status: Order.Status? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("complete") val complete: kotlin.Boolean? = false ) { @@ -49,13 +49,10 @@ data class Order( * Values: placed,approved,delivered */ enum class Status(val value: kotlin.String) { - + @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - - @JsonProperty("delivered") delivered("delivered"); - + @JsonProperty("delivered") delivered("delivered") } } diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Pet.kt index c37375167f9..73c71328b6c 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Pet.kt @@ -14,7 +14,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A pet for sale in the pet store @@ -27,24 +27,24 @@ import io.swagger.annotations.ApiModelProperty */ data class Pet( - @ApiModelProperty(example = "doggie", required = true, value = "") + @Schema(example = "doggie", required = true, description = "") @field:JsonProperty("name", required = true) val name: kotlin.String, - @ApiModelProperty(example = "null", required = true, value = "") + @Schema(example = "null", required = true, description = "") @field:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") val id: kotlin.Long? = null, @field:Valid - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("category") val category: Category? = null, @field:Valid - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("tags") val tags: kotlin.collections.List? = null, - @ApiModelProperty(example = "null", value = "pet status in the store") + @Schema(example = "null", description = "pet status in the store") @Deprecated(message = "") @field:JsonProperty("status") val status: Pet.Status? = null ) { @@ -54,13 +54,10 @@ data class Pet( * Values: available,pending,sold */ enum class Status(val value: kotlin.String) { - + @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - - @JsonProperty("sold") sold("sold"); - + @JsonProperty("sold") sold("sold") } } diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Tag.kt index 1d540aa1677..e6f18b5e01b 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Tag.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Tag.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A tag for a pet @@ -20,10 +20,10 @@ import io.swagger.annotations.ApiModelProperty */ data class Tag( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("name") val name: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/User.kt index 87e20405d96..0192450f9d0 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/User.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/User.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A User who is purchasing from the pet store @@ -26,28 +26,28 @@ import io.swagger.annotations.ApiModelProperty */ data class User( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("username") val username: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("firstName") val firstName: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("lastName") val lastName: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("email") val email: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("password") val password: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("phone") val phone: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "User Status") + @Schema(example = "null", description = "User Status") @field:JsonProperty("userStatus") val userStatus: kotlin.Int? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/resources/openapi.yaml b/samples/server/petstore/kotlin-springboot-delegate/src/main/resources/openapi.yaml new file mode 100644 index 00000000000..da52949d044 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/resources/openapi.yaml @@ -0,0 +1,835 @@ +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: "" + 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: + $ref: '#/components/requestBodies/inline_object' + content: + application/x-www-form-urlencoded: + schema: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + type: object + 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: + $ref: '#/components/requestBodies/inline_object_1' + content: + multipart/form-data: + schema: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + type: object + 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 generated 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 + inline_object: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/inline_object' + inline_object_1: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/inline_object_1' + 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 + inline_object: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + type: object + inline_object_1: + 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-modelMutable/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/FILES index 50a9d2bc75d..94bb84d6ac3 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/FILES +++ b/samples/server/petstore/kotlin-springboot-modelMutable/.openapi-generator/FILES @@ -3,6 +3,7 @@ build.gradle.kts 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/Exceptions.kt src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -21,3 +22,4 @@ 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-modelMutable/build.gradle.kts b/samples/server/petstore/kotlin-springboot-modelMutable/build.gradle.kts index ea7f93398da..f7432a5df77 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/build.gradle.kts +++ b/samples/server/petstore/kotlin-springboot-modelMutable/build.gradle.kts @@ -30,14 +30,18 @@ plugins { } dependencies { - val kotlinxCoroutinesVersion="1.2.0" compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") compile("org.jetbrains.kotlin:kotlin-reflect") compile("org.springframework.boot:spring-boot-starter-web") - compile("io.swagger:swagger-annotations:1.5.21") + compile("org.springdoc:springdoc-openapi-ui:1.6.6") + + compile("com.google.code.findbugs:jsr305:3.0.2") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") compile("com.fasterxml.jackson.module:jackson-module-kotlin") + compile("jakarta.validation:jakarta.validation-api") + compile("jakarta.annotation:jakarta.annotation-api:1.3.5") testCompile("org.jetbrains.kotlin:kotlin-test-junit5") testCompile("org.springframework.boot:spring-boot-starter-test") { diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/pom.xml b/samples/server/petstore/kotlin-springboot-modelMutable/pom.xml index 4d5fc7828f6..63eff7b8561 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/pom.xml +++ b/samples/server/petstore/kotlin-springboot-modelMutable/pom.xml @@ -6,10 +6,13 @@ openapi-spring 1.0.0 - UTF-8 + 1.6.6 + 3.0.2 + 1.3.5 + 1.3.31 + 1.3.30 - 1.2.0 - 1.3.5 + UTF-8 org.springframework.boot @@ -83,16 +86,18 @@ spring-boot-starter-web + - io.swagger - swagger-annotations - 1.5.21 + org.springdoc + springdoc-openapi-ui + ${springdoc-openapi.version} + com.google.code.findbugs jsr305 - 3.0.2 + ${findbugs-jsr305.version} com.fasterxml.jackson.dataformat @@ -118,13 +123,13 @@ jakarta.annotation jakarta.annotation-api - ${jakarta-annotation-version} + ${jakarta-annotation.version} provided org.jetbrains.kotlin kotlin-test-junit5 - 1.3.31 + ${kotlin-test-junit5.version} test diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/Application.kt index f2ee49d476b..2fe6de62479 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/Application.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/Application.kt @@ -1,9 +1,8 @@ package org.openapitools import org.springframework.boot.runApplication -import org.springframework.context.annotation.ComponentScan import org.springframework.boot.autoconfigure.SpringBootApplication - +import org.springframework.context.annotation.ComponentScan @SpringBootApplication @ComponentScan(basePackages = ["org.openapitools", "org.openapitools.api", "org.openapitools.model"]) diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/HomeController.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/HomeController.kt new file mode 100644 index 00000000000..0b75544d7a1 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/HomeController.kt @@ -0,0 +1,17 @@ +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 + +/** + * Home redirection to OpenAPI api documentation + */ +@Controller +class HomeController { + + @RequestMapping("/") + fun index(): String = "redirect:swagger-ui.html" +} diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/PetApiController.kt index e9ad5c44589..0213ba5ba3f 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -2,13 +2,11 @@ package org.openapitools.api import org.openapitools.model.ModelApiResponse import org.openapitools.model.Pet -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope +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 @@ -33,154 +31,148 @@ import kotlin.collections.Map @RestController @Validated -@Api(value = "pet", description = "The pet API") @RequestMapping("\${api.base-path:/v2}") class PetApiController(@Autowired(required = true) val service: PetApiService) { - @ApiOperation( - value = "Add a new pet to the store", - nickname = "addPet", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + @Operation( + summary = "Add a new pet to the store", + operationId = "addPet", + description = "", + responses = [ + ApiResponse(responseCode = "405", description = "Invalid input") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) @RequestMapping( method = [RequestMethod.POST], value = ["/pet"], consumes = ["application/json", "application/xml"] ) - fun addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet -): ResponseEntity { + fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) } - @ApiOperation( - value = "Deletes a pet", - nickname = "deletePet", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid pet value")]) + @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}"] ) - fun deletePet(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: kotlin.String? -): ResponseEntity { + fun deletePet(@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)) } - @ApiOperation( - value = "Finds Pets by status", - nickname = "findPetsByStatus", - notes = "Multiple status values can be provided with comma separated strings", - response = Pet::class, - responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid status value")]) + @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(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "400", description = "Invalid status value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) @RequestMapping( method = [RequestMethod.GET], value = ["/pet/findByStatus"], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List -): ResponseEntity> { + fun findPetsByStatus(@NotNull @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)) } - @ApiOperation( - value = "Finds Pets by tags", - nickname = "findPetsByTags", - notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", - response = Pet::class, - responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid tag value")]) + @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(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "400", description = "Invalid tag value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) @RequestMapping( method = [RequestMethod.GET], value = ["/pet/findByTags"], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List -): ResponseEntity> { + fun findPetsByTags(@NotNull @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)) } - @ApiOperation( - value = "Find pet by ID", - nickname = "getPetById", - notes = "Returns a single pet", - response = Pet::class, - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found")]) + @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"] ) - fun getPetById(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: kotlin.Long -): ResponseEntity { + fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Update an existing pet", - nickname = "updatePet", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found"),ApiResponse(code = 405, message = "Validation exception")]) + @Operation( + summary = "Update an existing pet", + operationId = "updatePet", + description = "", + responses = [ + 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"], consumes = ["application/json", "application/xml"] ) - fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet -): ResponseEntity { + fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) } - @ApiOperation( - value = "Updates a pet in the store with form data", - nickname = "updatePetWithForm", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + @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"] ) - fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "Updated name of the pet") @RequestParam(value="name", required=false) name: kotlin.String? -,@ApiParam(value = "Updated status of the pet") @RequestParam(value="status", required=false) status: kotlin.String? -): ResponseEntity { + fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @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)) } - @ApiOperation( - value = "uploads an image", - nickname = "uploadFile", - notes = "", - response = ModelApiResponse::class, - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) + @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"] ) - fun uploadFile(@ApiParam(value = "ID of pet to update", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "Additional data to pass to server") @RequestParam(value="additionalMetadata", required=false) additionalMetadata: kotlin.String? -,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource? -): ResponseEntity { + fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/StoreApiController.kt index 31f54ce0246..4106e3ed94f 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -1,13 +1,11 @@ package org.openapitools.api import org.openapitools.model.Order -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope +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 @@ -32,34 +30,33 @@ import kotlin.collections.Map @RestController @Validated -@Api(value = "store", description = "The store API") @RequestMapping("\${api.base-path:/v2}") class StoreApiController(@Autowired(required = true) val service: StoreApiService) { - @ApiOperation( - value = "Delete purchase order by ID", - nickname = "deleteOrder", - notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors") - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @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}"] ) - fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required=true) @PathVariable("orderId") orderId: kotlin.String -): ResponseEntity { + fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } - @ApiOperation( - value = "Returns pet inventories by status", - nickname = "getInventory", - notes = "Returns a map of status codes to quantities", - response = kotlin.Int::class, - responseContainer = "Map", - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")]) + @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"], @@ -69,37 +66,38 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Find purchase order by ID", - nickname = "getOrderById", - notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", - response = Order::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @Operation( + summary = "Find purchase order by ID", + operationId = "getOrderById", + description = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated 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"] ) - fun getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required=true) @PathVariable("orderId") orderId: kotlin.Long -): ResponseEntity { + 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)) } - @ApiOperation( - value = "Place an order for a pet", - nickname = "placeOrder", - notes = "", - response = Order::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")]) + @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"] ) - fun placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody body: Order -): ResponseEntity { + fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order): ResponseEntity { return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) } } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/UserApiController.kt index 92050c6e481..ad2a558493b 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -1,13 +1,11 @@ package org.openapitools.api import org.openapitools.model.User -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope +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 @@ -32,111 +30,112 @@ import kotlin.collections.Map @RestController @Validated -@Api(value = "user", description = "The user API") @RequestMapping("\${api.base-path:/v2}") class UserApiController(@Autowired(required = true) val service: UserApiService) { - @ApiOperation( - value = "Create user", - nickname = "createUser", - notes = "This can only be done by the logged in user.") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @Operation( + summary = "Create user", + operationId = "createUser", + description = "This can only be done by the logged in user.", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) @RequestMapping( method = [RequestMethod.POST], value = ["/user"] ) - fun createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody body: User -): ResponseEntity { + fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody body: User): ResponseEntity { return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Creates list of users with given input array", - nickname = "createUsersWithArrayInput", - notes = "") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @Operation( + summary = "Creates list of users with given input array", + operationId = "createUsersWithArrayInput", + description = "", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) @RequestMapping( method = [RequestMethod.POST], value = ["/user/createWithArray"] ) - fun createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: kotlin.collections.List -): ResponseEntity { + fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Creates list of users with given input array", - nickname = "createUsersWithListInput", - notes = "") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @Operation( + summary = "Creates list of users with given input array", + operationId = "createUsersWithListInput", + description = "", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) @RequestMapping( method = [RequestMethod.POST], value = ["/user/createWithList"] ) - fun createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: kotlin.collections.List -): ResponseEntity { + fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Delete user", - nickname = "deleteUser", - notes = "This can only be done by the logged in user.") - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @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") ] + ) @RequestMapping( method = [RequestMethod.DELETE], value = ["/user/{username}"] ) - fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true) @PathVariable("username") username: kotlin.String -): ResponseEntity { + fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } - @ApiOperation( - value = "Get user by user name", - nickname = "getUserByName", - notes = "", - response = User::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = User::class),ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @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"] ) - fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required=true) @PathVariable("username") username: kotlin.String -): ResponseEntity { + fun getUserByName(@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)) } - @ApiOperation( - value = "Logs user into the system", - nickname = "loginUser", - notes = "", - response = kotlin.String::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")]) + @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"] ) - fun loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String -,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String -): ResponseEntity { + fun loginUser(@NotNull @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)) } - @ApiOperation( - value = "Logs out current logged in user session", - nickname = "logoutUser", - notes = "") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @Operation( + summary = "Logs out current logged in user session", + operationId = "logoutUser", + description = "", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) @RequestMapping( method = [RequestMethod.GET], value = ["/user/logout"] @@ -145,19 +144,19 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Updated user", - nickname = "updateUser", - notes = "This can only be done by the logged in user.") - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid user supplied"),ApiResponse(code = 404, message = "User not found")]) + @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") ] + ) @RequestMapping( method = [RequestMethod.PUT], value = ["/user/{username}"] ) - fun updateUser(@ApiParam(value = "name that need to be deleted", required=true) @PathVariable("username") username: kotlin.String -,@ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody body: User -): ResponseEntity { + fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody body: User): ResponseEntity { return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) } } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Category.kt index 55a87b1bdc5..c70efbdd4ef 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Category.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Category.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A category for a pet @@ -20,10 +20,10 @@ import io.swagger.annotations.ApiModelProperty */ data class Category( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") var id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("name") var name: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt index e1564399e52..11126554b59 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * Describes the result of uploading an image resource @@ -21,13 +21,13 @@ import io.swagger.annotations.ApiModelProperty */ data class ModelApiResponse( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("code") var code: kotlin.Int? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("type") var type: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("message") var message: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Order.kt index 8e0ff334563..42afb455200 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Order.kt @@ -12,7 +12,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * An order for a pets from the pet store @@ -25,22 +25,22 @@ import io.swagger.annotations.ApiModelProperty */ data class Order( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") var id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("petId") var petId: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("quantity") var quantity: kotlin.Int? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("shipDate") var shipDate: java.time.OffsetDateTime? = null, - @ApiModelProperty(example = "null", value = "Order Status") + @Schema(example = "null", description = "Order Status") @field:JsonProperty("status") var status: Order.Status? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("complete") var complete: kotlin.Boolean? = false ) { @@ -49,13 +49,10 @@ data class Order( * Values: placed,approved,delivered */ enum class Status(val value: kotlin.String) { - + @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - - @JsonProperty("delivered") delivered("delivered"); - + @JsonProperty("delivered") delivered("delivered") } } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt index 40ab9eb34dd..d6f845e733a 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt @@ -14,7 +14,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A pet for sale in the pet store @@ -27,24 +27,24 @@ import io.swagger.annotations.ApiModelProperty */ data class Pet( - @ApiModelProperty(example = "doggie", required = true, value = "") + @Schema(example = "doggie", required = true, description = "") @field:JsonProperty("name", required = true) var name: kotlin.String, - @ApiModelProperty(example = "null", required = true, value = "") + @Schema(example = "null", required = true, description = "") @field:JsonProperty("photoUrls", required = true) var photoUrls: kotlin.collections.MutableList, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") var id: kotlin.Long? = null, @field:Valid - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("category") var category: Category? = null, @field:Valid - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("tags") var tags: kotlin.collections.MutableList? = null, - @ApiModelProperty(example = "null", value = "pet status in the store") + @Schema(example = "null", description = "pet status in the store") @field:JsonProperty("status") var status: Pet.Status? = null ) { @@ -53,13 +53,10 @@ data class Pet( * Values: available,pending,sold */ enum class Status(val value: kotlin.String) { - + @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - - @JsonProperty("sold") sold("sold"); - + @JsonProperty("sold") sold("sold") } } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Tag.kt index 3d93696f37a..1c7cfa202ec 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Tag.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Tag.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A tag for a pet @@ -20,10 +20,10 @@ import io.swagger.annotations.ApiModelProperty */ data class Tag( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") var id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("name") var name: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/User.kt index a18ff38ef0e..7cf5020daf5 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/User.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/User.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A User who is purchasing from the pet store @@ -26,28 +26,28 @@ import io.swagger.annotations.ApiModelProperty */ data class User( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") var id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("username") var username: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("firstName") var firstName: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("lastName") var lastName: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("email") var email: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("password") var password: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("phone") var phone: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "User Status") + @Schema(example = "null", description = "User Status") @field:JsonProperty("userStatus") var userStatus: kotlin.Int? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/resources/openapi.yaml b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/resources/openapi.yaml new file mode 100644 index 00000000000..847cd9d2767 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/resources/openapi.yaml @@ -0,0 +1,763 @@ +openapi: 3.0.1 +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 +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: + operationId: addPet + requestBody: + 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 + responses: + "405": + content: {} + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + x-codegen-request-body-name: body + put: + operationId: updatePet + requestBody: + 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 + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + "405": + content: {} + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + x-codegen-request-body-name: body + /pet/findByStatus: + get: + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - 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": + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - 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": + content: {} + description: Invalid tag value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Finds Pets by tags + tags: + - pet + /pet/{petId}: + delete: + operationId: deletePet + parameters: + - in: header + name: api_key + schema: + type: string + - description: Pet id to delete + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "400": + content: {} + 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 + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + tags: + - pet + post: + operationId: updatePetWithForm + parameters: + - description: ID of pet that needs to be updated + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + application/x-www-form-urlencoded: + schema: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + responses: + "405": + content: {} + 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: + operationId: uploadFile + parameters: + - description: ID of pet to update + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + multipart/form-data: + schema: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + 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: + operationId: placeOrder + requestBody: + content: + '*/*': + 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": + content: {} + description: Invalid Order + summary: Place an order for a pet + tags: + - store + x-codegen-request-body-name: body + /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 + in: path + name: orderId + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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 generated exceptions + operationId: getOrderById + parameters: + - description: ID of pet that needs to be fetched + in: path + name: orderId + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Create user + tags: + - user + x-codegen-request-body-name: body + /user/createWithArray: + post: + operationId: createUsersWithArrayInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + /user/createWithList: + post: + operationId: createUsersWithListInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + /user/login: + get: + operationId: loginUser + parameters: + - description: The user name for login + in: query + name: username + required: true + schema: + type: string + - description: The password for login in clear text + in: query + name: password + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + format: int32 + type: integer + X-Expires-After: + description: date in UTC when token expires + schema: + format: date-time + type: string + "400": + content: {} + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user + /user/logout: + get: + operationId: logoutUser + responses: + default: + content: {} + description: successful operation + 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 + in: path + name: username + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + description: User not found + summary: Delete user + tags: + - user + get: + operationId: getUserByName + parameters: + - description: The name that needs to be fetched. Use user1 for testing. + in: path + name: username + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + description: successful operation + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + 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 + in: path + name: username + required: true + schema: + type: string + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + responses: + "400": + content: {} + description: Invalid user supplied + "404": + content: {} + description: User not found + summary: Updated user + tags: + - user + x-codegen-request-body-name: body +components: + 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: + 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: + 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 + 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 +x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/PetApiTest.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/PetApiTest.kt index 0d3ccd3989f..6625bcb8d5c 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/PetApiTest.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/PetApiTest.kt @@ -18,7 +18,7 @@ class PetApiTest { */ @Test fun addPetTest() { - val body:Pet = TODO() + val body: Pet = TODO() val response: ResponseEntity = api.addPet(body) // TODO: test validations @@ -32,8 +32,8 @@ class PetApiTest { */ @Test fun deletePetTest() { - val petId:kotlin.Long = TODO() - val apiKey:kotlin.String? = TODO() + val petId: kotlin.Long = TODO() + val apiKey: kotlin.String? = TODO() val response: ResponseEntity = api.deletePet(petId, apiKey) // TODO: test validations @@ -47,7 +47,7 @@ class PetApiTest { */ @Test fun findPetsByStatusTest() { - val status:kotlin.collections.List = TODO() + val status: kotlin.collections.List = TODO() val response: ResponseEntity> = api.findPetsByStatus(status) // TODO: test validations @@ -61,7 +61,7 @@ class PetApiTest { */ @Test fun findPetsByTagsTest() { - val tags:kotlin.collections.List = TODO() + val tags: kotlin.collections.List = TODO() val response: ResponseEntity> = api.findPetsByTags(tags) // TODO: test validations @@ -75,7 +75,7 @@ class PetApiTest { */ @Test fun getPetByIdTest() { - val petId:kotlin.Long = TODO() + val petId: kotlin.Long = TODO() val response: ResponseEntity = api.getPetById(petId) // TODO: test validations @@ -89,7 +89,7 @@ class PetApiTest { */ @Test fun updatePetTest() { - val body:Pet = TODO() + val body: Pet = TODO() val response: ResponseEntity = api.updatePet(body) // TODO: test validations @@ -103,9 +103,9 @@ class PetApiTest { */ @Test fun updatePetWithFormTest() { - val petId:kotlin.Long = TODO() - val name:kotlin.String? = TODO() - val status:kotlin.String? = TODO() + 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 @@ -119,12 +119,11 @@ class PetApiTest { */ @Test fun uploadFileTest() { - val petId:kotlin.Long = TODO() - val additionalMetadata:kotlin.String? = TODO() - val file:org.springframework.core.io.Resource? = TODO() + val petId: kotlin.Long = TODO() + val additionalMetadata: kotlin.String? = TODO() + val file: org.springframework.core.io.Resource? = TODO() val response: ResponseEntity = api.uploadFile(petId, additionalMetadata, file) // TODO: test validations } - } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/StoreApiTest.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/StoreApiTest.kt index fcb00e99e99..69e269b03ef 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/StoreApiTest.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/StoreApiTest.kt @@ -17,7 +17,7 @@ class StoreApiTest { */ @Test fun deleteOrderTest() { - val orderId:kotlin.String = TODO() + val orderId: kotlin.String = TODO() val response: ResponseEntity = api.deleteOrder(orderId) // TODO: test validations @@ -44,7 +44,7 @@ class StoreApiTest { */ @Test fun getOrderByIdTest() { - val orderId:kotlin.Long = TODO() + val orderId: kotlin.Long = TODO() val response: ResponseEntity = api.getOrderById(orderId) // TODO: test validations @@ -58,10 +58,9 @@ class StoreApiTest { */ @Test fun placeOrderTest() { - val body:Order = TODO() + val body: Order = TODO() val response: ResponseEntity = api.placeOrder(body) // TODO: test validations } - } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/UserApiTest.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/UserApiTest.kt index c3f07290cfe..eb20423da71 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/UserApiTest.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/test/kotlin/org/openapitools/api/UserApiTest.kt @@ -17,7 +17,7 @@ class UserApiTest { */ @Test fun createUserTest() { - val body:User = TODO() + val body: User = TODO() val response: ResponseEntity = api.createUser(body) // TODO: test validations @@ -31,7 +31,7 @@ class UserApiTest { */ @Test fun createUsersWithArrayInputTest() { - val body:kotlin.collections.List = TODO() + val body: kotlin.collections.List = TODO() val response: ResponseEntity = api.createUsersWithArrayInput(body) // TODO: test validations @@ -45,7 +45,7 @@ class UserApiTest { */ @Test fun createUsersWithListInputTest() { - val body:kotlin.collections.List = TODO() + val body: kotlin.collections.List = TODO() val response: ResponseEntity = api.createUsersWithListInput(body) // TODO: test validations @@ -59,7 +59,7 @@ class UserApiTest { */ @Test fun deleteUserTest() { - val username:kotlin.String = TODO() + val username: kotlin.String = TODO() val response: ResponseEntity = api.deleteUser(username) // TODO: test validations @@ -73,7 +73,7 @@ class UserApiTest { */ @Test fun getUserByNameTest() { - val username:kotlin.String = TODO() + val username: kotlin.String = TODO() val response: ResponseEntity = api.getUserByName(username) // TODO: test validations @@ -87,8 +87,8 @@ class UserApiTest { */ @Test fun loginUserTest() { - val username:kotlin.String = TODO() - val password:kotlin.String = TODO() + val username: kotlin.String = TODO() + val password: kotlin.String = TODO() val response: ResponseEntity = api.loginUser(username, password) // TODO: test validations @@ -115,11 +115,10 @@ class UserApiTest { */ @Test fun updateUserTest() { - val username:kotlin.String = TODO() - val body:User = TODO() + val username: kotlin.String = TODO() + val body: User = TODO() val response: ResponseEntity = api.updateUser(username, body) // TODO: test validations } - } diff --git a/samples/server/petstore/kotlin-springboot-reactive/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-reactive/.openapi-generator/FILES index fdc7a16af74..8a36d40b875 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/.openapi-generator/FILES +++ b/samples/server/petstore/kotlin-springboot-reactive/.openapi-generator/FILES @@ -3,6 +3,7 @@ build.gradle.kts 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 @@ -20,3 +21,4 @@ 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/build.gradle.kts b/samples/server/petstore/kotlin-springboot-reactive/build.gradle.kts index 2f35ba0681d..0d2b00423b1 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/build.gradle.kts +++ b/samples/server/petstore/kotlin-springboot-reactive/build.gradle.kts @@ -30,16 +30,21 @@ plugins { } dependencies { - val kotlinxCoroutinesVersion="1.2.0" + val kotlinxCoroutinesVersion = "1.2.0" compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") compile("org.jetbrains.kotlin:kotlin-reflect") compile("org.springframework.boot:spring-boot-starter-webflux") compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") compile("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion") - compile("io.swagger:swagger-annotations:1.5.21") + compile("org.springdoc:springdoc-openapi-webflux-ui:1.6.6") + + compile("com.google.code.findbugs:jsr305:3.0.2") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") compile("com.fasterxml.jackson.module:jackson-module-kotlin") + compile("jakarta.validation:jakarta.validation-api") + compile("jakarta.annotation:jakarta.annotation-api:1.3.5") testCompile("org.jetbrains.kotlin:kotlin-test-junit5") testCompile("org.springframework.boot:spring-boot-starter-test") { diff --git a/samples/server/petstore/kotlin-springboot-reactive/pom.xml b/samples/server/petstore/kotlin-springboot-reactive/pom.xml index 22b7fba7d4c..478b9ecd745 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/pom.xml +++ b/samples/server/petstore/kotlin-springboot-reactive/pom.xml @@ -6,10 +6,14 @@ openapi-spring 1.0.0 - UTF-8 - 1.3.30 1.2.0 - 1.3.5 + 1.6.6 + 3.0.2 + 1.3.5 + 1.3.31 + + 1.3.30 + UTF-8 org.springframework.boot @@ -93,16 +97,18 @@ ${kotlinx-coroutines.version} + - io.swagger - swagger-annotations - 1.5.21 + org.springdoc + springdoc-openapi-webflux-ui + ${springdoc-openapi.version} + com.google.code.findbugs jsr305 - 3.0.2 + ${findbugs-jsr305.version} com.fasterxml.jackson.dataformat @@ -128,13 +134,13 @@ jakarta.annotation jakarta.annotation-api - ${jakarta-annotation-version} + ${jakarta-annotation.version} provided org.jetbrains.kotlin kotlin-test-junit5 - 1.3.31 + ${kotlin-test-junit5.version} test diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/Application.kt index f2ee49d476b..2fe6de62479 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/Application.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/Application.kt @@ -1,9 +1,8 @@ package org.openapitools import org.springframework.boot.runApplication -import org.springframework.context.annotation.ComponentScan import org.springframework.boot.autoconfigure.SpringBootApplication - +import org.springframework.context.annotation.ComponentScan @SpringBootApplication @ComponentScan(basePackages = ["org.openapitools", "org.openapitools.api", "org.openapitools.model"]) diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/HomeController.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/HomeController.kt new file mode 100644 index 00000000000..78f8cce7d83 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive/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/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiController.kt index 8558f9b4e9e..a1519b16e4b 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -2,13 +2,11 @@ package org.openapitools.api import org.openapitools.model.ModelApiResponse import org.openapitools.model.Pet -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope +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 @@ -28,160 +26,154 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow import kotlin.collections.List import kotlin.collections.Map @RestController @Validated -@Api(value = "pet", description = "The pet API") @RequestMapping("\${api.base-path:/v2}") class PetApiController(@Autowired(required = true) val service: PetApiService) { - @ApiOperation( - value = "Add a new pet to the store", - nickname = "addPet", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + @Operation( + summary = "Add a new pet to the store", + operationId = "addPet", + description = "", + responses = [ + ApiResponse(responseCode = "405", description = "Invalid input") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) @RequestMapping( method = [RequestMethod.POST], value = ["/pet"], consumes = ["application/json", "application/xml"] ) - suspend fun addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet -): ResponseEntity { + suspend fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) } - @ApiOperation( - value = "Deletes a pet", - nickname = "deletePet", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid pet value")]) + @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(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: kotlin.String? -): ResponseEntity { + 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)) } - @ApiOperation( - value = "Finds Pets by status", - nickname = "findPetsByStatus", - notes = "Multiple status values can be provided with comma separated strings", - response = Pet::class, - responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid status value")]) + @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(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "400", description = "Invalid status value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) @RequestMapping( method = [RequestMethod.GET], value = ["/pet/findByStatus"], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List -): ResponseEntity> { + fun findPetsByStatus(@NotNull @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)) } - @ApiOperation( - value = "Finds Pets by tags", - nickname = "findPetsByTags", - notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", - response = Pet::class, - responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid tag value")]) + @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(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "400", description = "Invalid tag value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) @RequestMapping( method = [RequestMethod.GET], value = ["/pet/findByTags"], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List -): ResponseEntity> { + fun findPetsByTags(@NotNull @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)) } - @ApiOperation( - value = "Find pet by ID", - nickname = "getPetById", - notes = "Returns a single pet", - response = Pet::class, - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found")]) + @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(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: kotlin.Long -): ResponseEntity { + suspend fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Update an existing pet", - nickname = "updatePet", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found"),ApiResponse(code = 405, message = "Validation exception")]) + @Operation( + summary = "Update an existing pet", + operationId = "updatePet", + description = "", + responses = [ + 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"], consumes = ["application/json", "application/xml"] ) - suspend fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet -): ResponseEntity { + suspend fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) } - @ApiOperation( - value = "Updates a pet in the store with form data", - nickname = "updatePetWithForm", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + @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(@ApiParam(value = "ID of pet that needs to be updated", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "Updated name of the pet") @RequestParam(value="name", required=false) name: kotlin.String? -,@ApiParam(value = "Updated status of the pet") @RequestParam(value="status", required=false) status: kotlin.String? -): ResponseEntity { + suspend fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @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)) } - @ApiOperation( - value = "uploads an image", - nickname = "uploadFile", - notes = "", - response = ModelApiResponse::class, - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) + @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(@ApiParam(value = "ID of pet to update", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "Additional data to pass to server") @RequestParam(value="additionalMetadata", required=false) additionalMetadata: kotlin.String? -,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource? -): ResponseEntity { + suspend fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiService.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiService.kt index fa6c0b67ce5..4e368ce87c5 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiService.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiService.kt @@ -2,7 +2,7 @@ package org.openapitools.api import org.openapitools.model.ModelApiResponse import org.openapitools.model.Pet -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow interface PetApiService { diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt index 1013dd81f92..263716758a7 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt @@ -2,7 +2,7 @@ package org.openapitools.api import org.openapitools.model.ModelApiResponse import org.openapitools.model.Pet -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow import org.springframework.stereotype.Service @Service class PetApiServiceImpl : PetApiService { diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiController.kt index 2b187f5820b..9c90d7d38d9 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -1,13 +1,11 @@ package org.openapitools.api import org.openapitools.model.Order -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope +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 @@ -27,40 +25,39 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow import kotlin.collections.List import kotlin.collections.Map @RestController @Validated -@Api(value = "store", description = "The store API") @RequestMapping("\${api.base-path:/v2}") class StoreApiController(@Autowired(required = true) val service: StoreApiService) { - @ApiOperation( - value = "Delete purchase order by ID", - nickname = "deleteOrder", - notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors") - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @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(@ApiParam(value = "ID of the order that needs to be deleted", required=true) @PathVariable("orderId") orderId: kotlin.String -): ResponseEntity { + suspend fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } - @ApiOperation( - value = "Returns pet inventories by status", - nickname = "getInventory", - notes = "Returns a map of status codes to quantities", - response = kotlin.Int::class, - responseContainer = "Map", - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")]) + @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"], @@ -70,37 +67,38 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Find purchase order by ID", - nickname = "getOrderById", - notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", - response = Order::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @Operation( + summary = "Find purchase order by ID", + operationId = "getOrderById", + description = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated 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) @ApiParam(value = "ID of pet that needs to be fetched", required=true) @PathVariable("orderId") orderId: kotlin.Long -): ResponseEntity { + 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)) } - @ApiOperation( - value = "Place an order for a pet", - nickname = "placeOrder", - notes = "", - response = Order::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")]) + @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"] ) - suspend fun placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody body: Order -): ResponseEntity { + suspend fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order): ResponseEntity { return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) } } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiService.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiService.kt index 1bc1ce9dc71..aa755f1fe68 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiService.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiService.kt @@ -1,7 +1,7 @@ package org.openapitools.api import org.openapitools.model.Order -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow interface StoreApiService { diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt index 4220a2900c4..3cb2b7eb800 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt @@ -1,7 +1,7 @@ package org.openapitools.api import org.openapitools.model.Order -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow import org.springframework.stereotype.Service @Service class StoreApiServiceImpl : StoreApiService { diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiController.kt index 56cefa69667..afc90291b74 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -1,13 +1,11 @@ package org.openapitools.api import org.openapitools.model.User -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope +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 @@ -27,117 +25,118 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow import kotlin.collections.List import kotlin.collections.Map @RestController @Validated -@Api(value = "user", description = "The user API") @RequestMapping("\${api.base-path:/v2}") class UserApiController(@Autowired(required = true) val service: UserApiService) { - @ApiOperation( - value = "Create user", - nickname = "createUser", - notes = "This can only be done by the logged in user.") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @Operation( + summary = "Create user", + operationId = "createUser", + description = "This can only be done by the logged in user.", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) @RequestMapping( method = [RequestMethod.POST], value = ["/user"] ) - suspend fun createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody body: User -): ResponseEntity { + suspend fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody body: User): ResponseEntity { return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Creates list of users with given input array", - nickname = "createUsersWithArrayInput", - notes = "") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @Operation( + summary = "Creates list of users with given input array", + operationId = "createUsersWithArrayInput", + description = "", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) @RequestMapping( method = [RequestMethod.POST], value = ["/user/createWithArray"] ) - suspend fun createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: Flow -): ResponseEntity { + suspend fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: Flow): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Creates list of users with given input array", - nickname = "createUsersWithListInput", - notes = "") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @Operation( + summary = "Creates list of users with given input array", + operationId = "createUsersWithListInput", + description = "", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) @RequestMapping( method = [RequestMethod.POST], value = ["/user/createWithList"] ) - suspend fun createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: Flow -): ResponseEntity { + suspend fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: Flow): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Delete user", - nickname = "deleteUser", - notes = "This can only be done by the logged in user.") - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @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") ] + ) @RequestMapping( method = [RequestMethod.DELETE], value = ["/user/{username}"] ) - suspend fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true) @PathVariable("username") username: kotlin.String -): ResponseEntity { + suspend fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } - @ApiOperation( - value = "Get user by user name", - nickname = "getUserByName", - notes = "", - response = User::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = User::class),ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @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(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required=true) @PathVariable("username") username: kotlin.String -): ResponseEntity { + suspend fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Logs user into the system", - nickname = "loginUser", - notes = "", - response = kotlin.String::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")]) + @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 @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String -,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String -): ResponseEntity { + suspend fun loginUser(@NotNull @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Logs out current logged in user session", - nickname = "logoutUser", - notes = "") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @Operation( + summary = "Logs out current logged in user session", + operationId = "logoutUser", + description = "", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) @RequestMapping( method = [RequestMethod.GET], value = ["/user/logout"] @@ -146,19 +145,19 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Updated user", - nickname = "updateUser", - notes = "This can only be done by the logged in user.") - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid user supplied"),ApiResponse(code = 404, message = "User not found")]) + @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") ] + ) @RequestMapping( method = [RequestMethod.PUT], value = ["/user/{username}"] ) - suspend fun updateUser(@ApiParam(value = "name that need to be deleted", required=true) @PathVariable("username") username: kotlin.String -,@ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody body: User -): ResponseEntity { + 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 body: User): ResponseEntity { return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) } } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiService.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiService.kt index 90703434b3b..dee015d83a7 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiService.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiService.kt @@ -1,7 +1,7 @@ package org.openapitools.api import org.openapitools.model.User -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow interface UserApiService { diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt index 3316a4c4138..0e5c3fd4392 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt @@ -1,7 +1,7 @@ package org.openapitools.api import org.openapitools.model.User -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow import org.springframework.stereotype.Service @Service class UserApiServiceImpl : UserApiService { diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Category.kt index 66d8d45d466..f6eb292c2d3 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Category.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Category.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A category for a pet @@ -20,10 +20,10 @@ import io.swagger.annotations.ApiModelProperty */ data class Category( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("name") val name: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt index 6b3e10c5694..b8a5657e99d 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * Describes the result of uploading an image resource @@ -21,13 +21,13 @@ import io.swagger.annotations.ApiModelProperty */ data class ModelApiResponse( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("code") val code: kotlin.Int? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("type") val type: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("message") val message: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Order.kt index c81e062d3f9..4494ffa95bd 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Order.kt @@ -12,7 +12,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * An order for a pets from the pet store @@ -25,22 +25,22 @@ import io.swagger.annotations.ApiModelProperty */ data class Order( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("petId") val petId: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("quantity") val quantity: kotlin.Int? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, - @ApiModelProperty(example = "null", value = "Order Status") + @Schema(example = "null", description = "Order Status") @field:JsonProperty("status") val status: Order.Status? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("complete") val complete: kotlin.Boolean? = false ) { @@ -49,13 +49,10 @@ data class Order( * Values: placed,approved,delivered */ enum class Status(val value: kotlin.String) { - + @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - - @JsonProperty("delivered") delivered("delivered"); - + @JsonProperty("delivered") delivered("delivered") } } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Pet.kt index 42394bc5a10..cd37d16c501 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Pet.kt @@ -14,7 +14,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A pet for sale in the pet store @@ -27,24 +27,24 @@ import io.swagger.annotations.ApiModelProperty */ data class Pet( - @ApiModelProperty(example = "doggie", required = true, value = "") + @Schema(example = "doggie", required = true, description = "") @field:JsonProperty("name", required = true) val name: kotlin.String, - @ApiModelProperty(example = "null", required = true, value = "") + @Schema(example = "null", required = true, description = "") @field:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") val id: kotlin.Long? = null, @field:Valid - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("category") val category: Category? = null, @field:Valid - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("tags") val tags: kotlin.collections.List? = null, - @ApiModelProperty(example = "null", value = "pet status in the store") + @Schema(example = "null", description = "pet status in the store") @field:JsonProperty("status") val status: Pet.Status? = null ) { @@ -53,13 +53,10 @@ data class Pet( * Values: available,pending,sold */ enum class Status(val value: kotlin.String) { - + @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - - @JsonProperty("sold") sold("sold"); - + @JsonProperty("sold") sold("sold") } } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Tag.kt index 1d540aa1677..e6f18b5e01b 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Tag.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Tag.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A tag for a pet @@ -20,10 +20,10 @@ import io.swagger.annotations.ApiModelProperty */ data class Tag( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("name") val name: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/User.kt index 87e20405d96..0192450f9d0 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/User.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/User.kt @@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty +import io.swagger.v3.oas.annotations.media.Schema /** * A User who is purchasing from the pet store @@ -26,28 +26,28 @@ import io.swagger.annotations.ApiModelProperty */ data class User( - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("username") val username: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("firstName") val firstName: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("lastName") val lastName: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("email") val email: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("password") val password: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") + @Schema(example = "null", description = "") @field:JsonProperty("phone") val phone: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "User Status") + @Schema(example = "null", description = "User Status") @field:JsonProperty("userStatus") val userStatus: kotlin.Int? = null ) { diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/resources/openapi.yaml b/samples/server/petstore/kotlin-springboot-reactive/src/main/resources/openapi.yaml new file mode 100644 index 00000000000..847cd9d2767 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/resources/openapi.yaml @@ -0,0 +1,763 @@ +openapi: 3.0.1 +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 +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: + operationId: addPet + requestBody: + 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 + responses: + "405": + content: {} + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + x-codegen-request-body-name: body + put: + operationId: updatePet + requestBody: + 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 + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + "405": + content: {} + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + x-codegen-request-body-name: body + /pet/findByStatus: + get: + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - 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": + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - 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": + content: {} + description: Invalid tag value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Finds Pets by tags + tags: + - pet + /pet/{petId}: + delete: + operationId: deletePet + parameters: + - in: header + name: api_key + schema: + type: string + - description: Pet id to delete + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "400": + content: {} + 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 + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + tags: + - pet + post: + operationId: updatePetWithForm + parameters: + - description: ID of pet that needs to be updated + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + application/x-www-form-urlencoded: + schema: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + responses: + "405": + content: {} + 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: + operationId: uploadFile + parameters: + - description: ID of pet to update + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + multipart/form-data: + schema: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + 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: + operationId: placeOrder + requestBody: + content: + '*/*': + 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": + content: {} + description: Invalid Order + summary: Place an order for a pet + tags: + - store + x-codegen-request-body-name: body + /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 + in: path + name: orderId + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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 generated exceptions + operationId: getOrderById + parameters: + - description: ID of pet that needs to be fetched + in: path + name: orderId + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Create user + tags: + - user + x-codegen-request-body-name: body + /user/createWithArray: + post: + operationId: createUsersWithArrayInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + /user/createWithList: + post: + operationId: createUsersWithListInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + /user/login: + get: + operationId: loginUser + parameters: + - description: The user name for login + in: query + name: username + required: true + schema: + type: string + - description: The password for login in clear text + in: query + name: password + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + format: int32 + type: integer + X-Expires-After: + description: date in UTC when token expires + schema: + format: date-time + type: string + "400": + content: {} + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user + /user/logout: + get: + operationId: logoutUser + responses: + default: + content: {} + description: successful operation + 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 + in: path + name: username + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + description: User not found + summary: Delete user + tags: + - user + get: + operationId: getUserByName + parameters: + - description: The name that needs to be fetched. Use user1 for testing. + in: path + name: username + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + description: successful operation + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + 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 + in: path + name: username + required: true + schema: + type: string + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + responses: + "400": + content: {} + description: Invalid user supplied + "404": + content: {} + description: User not found + summary: Updated user + tags: + - user + x-codegen-request-body-name: body +components: + 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: + 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: + 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 + 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 +x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/PetApiTest.kt b/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/PetApiTest.kt index bbc9b118e24..695d25351cb 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/PetApiTest.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/PetApiTest.kt @@ -3,7 +3,7 @@ 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.flow.Flow import kotlinx.coroutines.test.runBlockingTest import org.springframework.http.ResponseEntity @@ -20,7 +20,7 @@ class PetApiTest { */ @Test fun addPetTest() = runBlockingTest { - val body:Pet = TODO() + val body: Pet = TODO() val response: ResponseEntity = api.addPet(body) // TODO: test validations @@ -34,8 +34,8 @@ class PetApiTest { */ @Test fun deletePetTest() = runBlockingTest { - val petId:kotlin.Long = TODO() - val apiKey:kotlin.String? = TODO() + val petId: kotlin.Long = TODO() + val apiKey: kotlin.String? = TODO() val response: ResponseEntity = api.deletePet(petId, apiKey) // TODO: test validations @@ -49,7 +49,7 @@ class PetApiTest { */ @Test fun findPetsByStatusTest() = runBlockingTest { - val status:kotlin.collections.List = TODO() + val status: kotlin.collections.List = TODO() val response: ResponseEntity> = api.findPetsByStatus(status) // TODO: test validations @@ -63,7 +63,7 @@ class PetApiTest { */ @Test fun findPetsByTagsTest() = runBlockingTest { - val tags:kotlin.collections.List = TODO() + val tags: kotlin.collections.List = TODO() val response: ResponseEntity> = api.findPetsByTags(tags) // TODO: test validations @@ -77,7 +77,7 @@ class PetApiTest { */ @Test fun getPetByIdTest() = runBlockingTest { - val petId:kotlin.Long = TODO() + val petId: kotlin.Long = TODO() val response: ResponseEntity = api.getPetById(petId) // TODO: test validations @@ -91,7 +91,7 @@ class PetApiTest { */ @Test fun updatePetTest() = runBlockingTest { - val body:Pet = TODO() + val body: Pet = TODO() val response: ResponseEntity = api.updatePet(body) // TODO: test validations @@ -105,9 +105,9 @@ class PetApiTest { */ @Test fun updatePetWithFormTest() = runBlockingTest { - val petId:kotlin.Long = TODO() - val name:kotlin.String? = TODO() - val status:kotlin.String? = TODO() + 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 @@ -121,12 +121,11 @@ class PetApiTest { */ @Test fun uploadFileTest() = runBlockingTest { - val petId:kotlin.Long = TODO() - val additionalMetadata:kotlin.String? = TODO() - val file:org.springframework.core.io.Resource? = TODO() + val petId: kotlin.Long = TODO() + val additionalMetadata: kotlin.String? = TODO() + val file: org.springframework.core.io.Resource? = TODO() val response: ResponseEntity = api.uploadFile(petId, additionalMetadata, file) // TODO: test validations } - } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/StoreApiTest.kt b/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/StoreApiTest.kt index 1db01446d86..b3802355702 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/StoreApiTest.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/StoreApiTest.kt @@ -2,7 +2,7 @@ package org.openapitools.api import org.openapitools.model.Order import org.junit.jupiter.api.Test -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.test.runBlockingTest import org.springframework.http.ResponseEntity @@ -19,7 +19,7 @@ class StoreApiTest { */ @Test fun deleteOrderTest() = runBlockingTest { - val orderId:kotlin.String = TODO() + val orderId: kotlin.String = TODO() val response: ResponseEntity = api.deleteOrder(orderId) // TODO: test validations @@ -46,7 +46,7 @@ class StoreApiTest { */ @Test fun getOrderByIdTest() = runBlockingTest { - val orderId:kotlin.Long = TODO() + val orderId: kotlin.Long = TODO() val response: ResponseEntity = api.getOrderById(orderId) // TODO: test validations @@ -60,10 +60,9 @@ class StoreApiTest { */ @Test fun placeOrderTest() = runBlockingTest { - val body:Order = TODO() + val body: Order = TODO() val response: ResponseEntity = api.placeOrder(body) // TODO: test validations } - } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/UserApiTest.kt b/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/UserApiTest.kt index 126e0700f79..1b5bcf6363b 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/UserApiTest.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/test/kotlin/org/openapitools/api/UserApiTest.kt @@ -2,7 +2,7 @@ package org.openapitools.api import org.openapitools.model.User import org.junit.jupiter.api.Test -import kotlinx.coroutines.flow.Flow; +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.test.runBlockingTest import org.springframework.http.ResponseEntity @@ -19,7 +19,7 @@ class UserApiTest { */ @Test fun createUserTest() = runBlockingTest { - val body:User = TODO() + val body: User = TODO() val response: ResponseEntity = api.createUser(body) // TODO: test validations @@ -33,7 +33,7 @@ class UserApiTest { */ @Test fun createUsersWithArrayInputTest() = runBlockingTest { - val body:kotlin.collections.List = TODO() + val body: kotlin.collections.List = TODO() val response: ResponseEntity = api.createUsersWithArrayInput(body) // TODO: test validations @@ -47,7 +47,7 @@ class UserApiTest { */ @Test fun createUsersWithListInputTest() = runBlockingTest { - val body:kotlin.collections.List = TODO() + val body: kotlin.collections.List = TODO() val response: ResponseEntity = api.createUsersWithListInput(body) // TODO: test validations @@ -61,7 +61,7 @@ class UserApiTest { */ @Test fun deleteUserTest() = runBlockingTest { - val username:kotlin.String = TODO() + val username: kotlin.String = TODO() val response: ResponseEntity = api.deleteUser(username) // TODO: test validations @@ -75,7 +75,7 @@ class UserApiTest { */ @Test fun getUserByNameTest() = runBlockingTest { - val username:kotlin.String = TODO() + val username: kotlin.String = TODO() val response: ResponseEntity = api.getUserByName(username) // TODO: test validations @@ -89,8 +89,8 @@ class UserApiTest { */ @Test fun loginUserTest() = runBlockingTest { - val username:kotlin.String = TODO() - val password:kotlin.String = TODO() + val username: kotlin.String = TODO() + val password: kotlin.String = TODO() val response: ResponseEntity = api.loginUser(username, password) // TODO: test validations @@ -117,11 +117,10 @@ class UserApiTest { */ @Test fun updateUserTest() = runBlockingTest { - val username:kotlin.String = TODO() - val body:User = TODO() + val username: kotlin.String = TODO() + val body: User = TODO() val response: ResponseEntity = api.updateUser(username, body) // TODO: test validations } - } diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/.openapi-generator-ignore b/samples/server/petstore/kotlin-springboot-source-swagger1/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/.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-source-swagger1/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-source-swagger1/.openapi-generator/FILES new file mode 100644 index 00000000000..b7ad76a5ca4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/.openapi-generator/FILES @@ -0,0 +1,26 @@ +README.md +build.gradle.kts +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/Exceptions.kt +src/main/kotlin/org/openapitools/api/PetApiController.kt +src/main/kotlin/org/openapitools/api/PetApiService.kt +src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/StoreApiController.kt +src/main/kotlin/org/openapitools/api/StoreApiService.kt +src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/UserApiController.kt +src/main/kotlin/org/openapitools/api/UserApiService.kt +src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt +src/main/kotlin/org/openapitools/model/Category.kt +src/main/kotlin/org/openapitools/model/ModelApiResponse.kt +src/main/kotlin/org/openapitools/model/Order.kt +src/main/kotlin/org/openapitools/model/Pet.kt +src/main/kotlin/org/openapitools/model/Tag.kt +src/main/kotlin/org/openapitools/model/User.kt +src/main/resources/application.yaml +src/main/resources/openapi.yaml +src/main/resources/static/swagger-ui.html diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/.openapi-generator/VERSION b/samples/server/petstore/kotlin-springboot-source-swagger1/.openapi-generator/VERSION new file mode 100644 index 00000000000..5f68295fc19 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/README.md b/samples/server/petstore/kotlin-springboot-source-swagger1/README.md new file mode 100644 index 00000000000..b6865a08113 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/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-source-swagger1/build.gradle.kts b/samples/server/petstore/kotlin-springboot-source-swagger1/build.gradle.kts new file mode 100644 index 00000000000..13c21c0fcf2 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/build.gradle.kts @@ -0,0 +1,58 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.0.M3") + } +} + +group = "org.openapitools" +version = "1.0.0" + +repositories { + mavenCentral() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +plugins { + val kotlinVersion = "1.3.30" + 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.2.0.M3" + id("io.spring.dependency-management") version "1.0.5.RELEASE" +} + +dependencies { + compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + compile("org.jetbrains.kotlin:kotlin-reflect") + compile("org.springframework.boot:spring-boot-starter-web") + compile("org.webjars:swagger-ui:4.8.1") + compile("org.webjars:webjars-locator-core") + compile("io.swagger:swagger-annotations:1.6.5") + + compile("com.google.code.findbugs:jsr305:3.0.2") + compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") + compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + compile("com.fasterxml.jackson.module:jackson-module-kotlin") + compile("jakarta.validation:jakarta.validation-api") + compile("jakarta.annotation:jakarta.annotation-api:1.3.5") + + testCompile("org.jetbrains.kotlin:kotlin-test-junit5") + testCompile("org.springframework.boot:spring-boot-starter-test") { + exclude(module = "junit") + } +} + +repositories { + maven { url = uri("https://repo1.maven.org/maven2") } + maven { url = uri("https://repo.spring.io/snapshot") } + maven { url = uri("https://repo.spring.io/milestone") } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/pom.xml b/samples/server/petstore/kotlin-springboot-source-swagger1/pom.xml new file mode 100644 index 00000000000..0a6f5452a69 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/pom.xml @@ -0,0 +1,176 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 4.8.1 + 1.6.5 + 3.0.2 + 1.3.5 + 1.3.31 + + 1.3.30 + UTF-8 + + + org.springframework.boot + spring-boot-starter-parent + 2.2.0.M3 + + + ${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-web + + + + + org.webjars + swagger-ui + ${swagger-ui.version} + + + org.webjars + webjars-locator-core + + + io.swagger + swagger-annotations + ${swagger-annotations.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 + + + + jakarta.validation + jakarta.validation-api + + + jakarta.annotation + jakarta.annotation-api + ${jakarta-annotation.version} + provided + + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin-test-junit5.version} + test + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/settings.gradle b/samples/server/petstore/kotlin-springboot-source-swagger1/settings.gradle new file mode 100644 index 00000000000..14844905cd4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/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-source-swagger1/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/Application.kt new file mode 100644 index 00000000000..2fe6de62479 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/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-source-swagger1/src/main/kotlin/org/openapitools/HomeController.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/HomeController.kt new file mode 100644 index 00000000000..fabc940cc83 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/HomeController.kt @@ -0,0 +1,46 @@ +package org.openapitools + +import org.springframework.context.annotation.Bean +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper +import org.springframework.beans.factory.annotation.Value +import org.springframework.core.io.Resource +import org.springframework.util.StreamUtils +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.GetMapping +import java.nio.charset.Charset + +/** + * Home redirection to OpenAPI api documentation + */ +@Controller +class HomeController { + private val apiDocsPath = "/openapi.json" + private val yamlMapper = YAMLMapper() + + @Value("classpath:/openapi.yaml") + private lateinit var openapi: Resource + + @Bean + fun openapiContent(): String { + return openapi.inputStream.use { + StreamUtils.copyToString(it, Charset.defaultCharset()) + } + } + + @GetMapping(value = ["/openapi.yaml"], produces = ["application/vnd.oai.openapi"]) + @ResponseBody + fun openapiYaml(): String = openapiContent() + + @GetMapping(value = ["/openapi.json"], produces = ["application/json"]) + @ResponseBody + fun openapiJson(): Any = yamlMapper.readValue(openapiContent(), Any::class.java) + + @GetMapping(value = ["/swagger-config.yaml"], produces = ["text/plain"]) + @ResponseBody + fun swaggerConfig(): String = "url: $apiDocsPath\n" + + @RequestMapping("/") + fun index(): String = "redirect:swagger-ui.html" +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 00000000000..88e892d0f49 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,19 @@ +package org.openapitools.api + +import org.springframework.web.context.request.NativeWebRequest + +import javax.servlet.http.HttpServletResponse +import java.io.IOException + +object ApiUtil { + fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { + try { + val res = req.getNativeResponse(HttpServletResponse::class.java) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) + } catch (e: IOException) { + throw RuntimeException(e) + } + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/Exceptions.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/Exceptions.kt new file mode 100644 index 00000000000..44190af7a01 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/Exceptions.kt @@ -0,0 +1,29 @@ +package org.openapitools.api + +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.bind.annotation.ExceptionHandler +import javax.servlet.http.HttpServletResponse +import javax.validation.ConstraintViolationException + +// TODO Extend ApiException for custom exception handling, e.g. the below NotFound exception +sealed class ApiException(msg: String, val code: Int) : Exception(msg) + +class NotFoundException(msg: String, code: Int = HttpStatus.NOT_FOUND.value()) : ApiException(msg, code) + + +@ControllerAdvice +class DefaultExceptionHandler { + + @ExceptionHandler(value = [ApiException::class]) + fun onApiException(ex: ApiException, response: HttpServletResponse): Unit = + response.sendError(ex.code, ex.message) + + @ExceptionHandler(value = [NotImplementedError::class]) + fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.NOT_IMPLEMENTED.value()) + + @ExceptionHandler(value = [ConstraintViolationException::class]) + fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message }) +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiController.kt new file mode 100644 index 00000000000..75079add0cb --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -0,0 +1,181 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import io.swagger.annotations.ApiResponse +import io.swagger.annotations.ApiResponses +import io.swagger.annotations.Authorization +import io.swagger.annotations.AuthorizationScope +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 kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@Api(value = "pet", description = "The pet API") +@RequestMapping("\${api.base-path:/v2}") +class PetApiController(@Autowired(required = true) val service: PetApiService) { + + + @ApiOperation( + value = "Add a new pet to the store", + nickname = "addPet", + notes = "", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 405, message = "Invalid input")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/pet"], + consumes = ["application/json", "application/xml"] + ) + fun addPet(@ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) + } + + + @ApiOperation( + value = "Deletes a pet", + nickname = "deletePet", + notes = "", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 400, message = "Invalid pet value")]) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/pet/{petId}"] + ) + fun deletePet(@ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "") @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) + } + + + @ApiOperation( + value = "Finds Pets by status", + nickname = "findPetsByStatus", + notes = "Multiple status values can be provided with comma separated strings", + response = Pet::class, + responseContainer = "List", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid status value")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/pet/findByStatus"], + produces = ["application/xml", "application/json"] + ) + fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Finds Pets by tags", + nickname = "findPetsByTags", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + response = Pet::class, + responseContainer = "List", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid tag value")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/pet/findByTags"], + produces = ["application/xml", "application/json"] + ) + fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Find pet by ID", + nickname = "getPetById", + notes = "Returns a single pet", + response = Pet::class, + authorizations = [Authorization(value = "api_key")]) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/pet/{petId}"], + produces = ["application/xml", "application/json"] + ) + fun getPetById(@ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Update an existing pet", + nickname = "updatePet", + notes = "", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found"),ApiResponse(code = 405, message = "Validation exception")]) + @RequestMapping( + method = [RequestMethod.PUT], + value = ["/pet"], + consumes = ["application/json", "application/xml"] + ) + fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) + } + + + @ApiOperation( + value = "Updates a pet in the store with form data", + nickname = "updatePetWithForm", + notes = "", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 405, message = "Invalid input")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/pet/{petId}"], + consumes = ["application/x-www-form-urlencoded"] + ) + fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Updated name of the pet") @RequestParam(value = "name", required = false) name: kotlin.String? ,@ApiParam(value = "Updated status of the pet") @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) + } + + + @ApiOperation( + value = "uploads an image", + nickname = "uploadFile", + notes = "", + response = ModelApiResponse::class, + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/pet/{petId}/uploadImage"], + produces = ["application/json"], + consumes = ["multipart/form-data"] + ) + fun uploadFile(@ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Additional data to pass to server") @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?): ResponseEntity { + return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiService.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiService.kt new file mode 100644 index 00000000000..ee0e3bef83c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiService.kt @@ -0,0 +1,94 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet + +interface PetApiService { + + /** + * POST /pet : Add a new pet to the store + * + * @param body Pet object that needs to be added to the store (required) + * @return Invalid input (status code 405) + * @see PetApi#addPet + */ + fun addPet(body: Pet): Unit + + /** + * DELETE /pet/{petId} : Deletes a pet + * + * @param petId Pet id to delete (required) + * @param apiKey (optional) + * @return Invalid pet value (status code 400) + * @see PetApi#deletePet + */ + fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit + + /** + * GET /pet/findByStatus : Finds Pets by status + * Multiple status values can be provided with comma separated strings + * + * @param status Status values that need to be considered for filter (required) + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + * @see PetApi#findPetsByStatus + */ + fun findPetsByStatus(status: kotlin.collections.List): List + + /** + * GET /pet/findByTags : Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * + * @param tags Tags to filter by (required) + * @return successful operation (status code 200) + * or Invalid tag value (status code 400) + * @deprecated + * @see PetApi#findPetsByTags + */ + fun findPetsByTags(tags: kotlin.collections.List): List + + /** + * GET /pet/{petId} : Find pet by ID + * Returns a single pet + * + * @param petId ID of pet to return (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * @see PetApi#getPetById + */ + fun getPetById(petId: kotlin.Long): Pet + + /** + * PUT /pet : Update an existing pet + * + * @param body Pet object that needs to be added to the store (required) + * @return Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * or Validation exception (status code 405) + * @see PetApi#updatePet + */ + fun updatePet(body: Pet): Unit + + /** + * POST /pet/{petId} : Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated (required) + * @param name Updated name of the pet (optional) + * @param status Updated status of the pet (optional) + * @return Invalid input (status code 405) + * @see PetApi#updatePetWithForm + */ + fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit + + /** + * POST /pet/{petId}/uploadImage : uploads an image + * + * @param petId ID of pet to update (required) + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return successful operation (status code 200) + * @see PetApi#uploadFile + */ + fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt new file mode 100644 index 00000000000..452e4e400b7 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt @@ -0,0 +1,40 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.springframework.stereotype.Service +@Service +class PetApiServiceImpl : PetApiService { + + override fun addPet(body: Pet): Unit { + TODO("Implement me") + } + + override fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun findPetsByStatus(status: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun findPetsByTags(tags: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun getPetById(petId: kotlin.Long): Pet { + TODO("Implement me") + } + + override fun updatePet(body: Pet): Unit { + TODO("Implement me") + } + + override fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiController.kt new file mode 100644 index 00000000000..c3e90f46fd5 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -0,0 +1,106 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import io.swagger.annotations.ApiResponse +import io.swagger.annotations.ApiResponses +import io.swagger.annotations.Authorization +import io.swagger.annotations.AuthorizationScope +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 kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@Api(value = "store", description = "The store API") +@RequestMapping("\${api.base-path:/v2}") +class StoreApiController(@Autowired(required = true) val service: StoreApiService) { + + + @ApiOperation( + value = "Delete purchase order by ID", + nickname = "deleteOrder", + notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors") + @ApiResponses( + value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/store/order/{orderId}"] + ) + fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) + } + + + @ApiOperation( + value = "Returns pet inventories by status", + nickname = "getInventory", + notes = "Returns a map of status codes to quantities", + response = kotlin.Int::class, + responseContainer = "Map", + authorizations = [Authorization(value = "api_key")]) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/store/inventory"], + produces = ["application/json"] + ) + fun getInventory(): ResponseEntity> { + return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Find purchase order by ID", + nickname = "getOrderById", + notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", + response = Order::class) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/store/order/{orderId}"], + produces = ["application/xml", "application/json"] + ) + fun getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Place an order for a pet", + nickname = "placeOrder", + notes = "", + response = Order::class) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/store/order"], + produces = ["application/xml", "application/json"] + ) + fun placeOrder(@ApiParam(value = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order): ResponseEntity { + return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiService.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiService.kt new file mode 100644 index 00000000000..6de3e6cc1de --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiService.kt @@ -0,0 +1,48 @@ +package org.openapitools.api + +import org.openapitools.model.Order + +interface StoreApiService { + + /** + * DELETE /store/order/{orderId} : Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * + * @param orderId ID of the order that needs to be deleted (required) + * @return Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#deleteOrder + */ + fun deleteOrder(orderId: kotlin.String): Unit + + /** + * GET /store/inventory : Returns pet inventories by status + * Returns a map of status codes to quantities + * + * @return successful operation (status code 200) + * @see StoreApi#getInventory + */ + fun getInventory(): Map + + /** + * GET /store/order/{orderId} : Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * + * @param orderId ID of pet that needs to be fetched (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#getOrderById + */ + fun getOrderById(orderId: kotlin.Long): Order + + /** + * POST /store/order : Place an order for a pet + * + * @param body order placed for purchasing the pet (required) + * @return successful operation (status code 200) + * or Invalid Order (status code 400) + * @see StoreApi#placeOrder + */ + fun placeOrder(body: Order): Order +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt new file mode 100644 index 00000000000..7e733e28dc5 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt @@ -0,0 +1,23 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.springframework.stereotype.Service +@Service +class StoreApiServiceImpl : StoreApiService { + + override fun deleteOrder(orderId: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getInventory(): Map { + TODO("Implement me") + } + + override fun getOrderById(orderId: kotlin.Long): Order { + TODO("Implement me") + } + + override fun placeOrder(body: Order): Order { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiController.kt new file mode 100644 index 00000000000..5e7076f405c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -0,0 +1,162 @@ +package org.openapitools.api + +import org.openapitools.model.User +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import io.swagger.annotations.ApiResponse +import io.swagger.annotations.ApiResponses +import io.swagger.annotations.Authorization +import io.swagger.annotations.AuthorizationScope +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 kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@Api(value = "user", description = "The user API") +@RequestMapping("\${api.base-path:/v2}") +class UserApiController(@Autowired(required = true) val service: UserApiService) { + + + @ApiOperation( + value = "Create user", + nickname = "createUser", + notes = "This can only be done by the logged in user.") + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user"] + ) + fun createUser(@ApiParam(value = "Created user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Creates list of users with given input array", + nickname = "createUsersWithArrayInput", + notes = "") + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user/createWithArray"] + ) + fun createUsersWithArrayInput(@ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Creates list of users with given input array", + nickname = "createUsersWithListInput", + notes = "") + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user/createWithList"] + ) + fun createUsersWithListInput(@ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Delete user", + nickname = "deleteUser", + notes = "This can only be done by the logged in user.") + @ApiResponses( + value = [ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/user/{username}"] + ) + fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) + } + + + @ApiOperation( + value = "Get user by user name", + nickname = "getUserByName", + notes = "", + response = User::class) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = User::class),ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/user/{username}"], + produces = ["application/xml", "application/json"] + ) + fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Logs user into the system", + nickname = "loginUser", + notes = "", + response = kotlin.String::class) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/user/login"], + produces = ["application/xml", "application/json"] + ) + fun loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Logs out current logged in user session", + nickname = "logoutUser", + notes = "") + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/user/logout"] + ) + fun logoutUser(): ResponseEntity { + return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Updated user", + nickname = "updateUser", + notes = "This can only be done by the logged in user.") + @ApiResponses( + value = [ApiResponse(code = 400, message = "Invalid user supplied"),ApiResponse(code = 404, message = "User not found")]) + @RequestMapping( + method = [RequestMethod.PUT], + value = ["/user/{username}"] + ) + fun updateUser(@ApiParam(value = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@ApiParam(value = "Updated user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiService.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiService.kt new file mode 100644 index 00000000000..a1bcf6be237 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiService.kt @@ -0,0 +1,87 @@ +package org.openapitools.api + +import org.openapitools.model.User + +interface UserApiService { + + /** + * POST /user : Create user + * This can only be done by the logged in user. + * + * @param body Created user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUser + */ + fun createUser(body: User): Unit + + /** + * POST /user/createWithArray : Creates list of users with given input array + * + * @param body List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithArrayInput + */ + fun createUsersWithArrayInput(body: kotlin.collections.List): Unit + + /** + * POST /user/createWithList : Creates list of users with given input array + * + * @param body List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithListInput + */ + fun createUsersWithListInput(body: kotlin.collections.List): Unit + + /** + * DELETE /user/{username} : Delete user + * This can only be done by the logged in user. + * + * @param username The name that needs to be deleted (required) + * @return Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#deleteUser + */ + fun deleteUser(username: kotlin.String): Unit + + /** + * GET /user/{username} : Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. (required) + * @return successful operation (status code 200) + * or Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#getUserByName + */ + fun getUserByName(username: kotlin.String): User + + /** + * GET /user/login : Logs user into the system + * + * @param username The user name for login (required) + * @param password The password for login in clear text (required) + * @return successful operation (status code 200) + * or Invalid username/password supplied (status code 400) + * @see UserApi#loginUser + */ + fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String + + /** + * GET /user/logout : Logs out current logged in user session + * + * @return successful operation (status code 200) + * @see UserApi#logoutUser + */ + fun logoutUser(): Unit + + /** + * PUT /user/{username} : Updated user + * This can only be done by the logged in user. + * + * @param username name that need to be deleted (required) + * @param body Updated user object (required) + * @return Invalid user supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#updateUser + */ + fun updateUser(username: kotlin.String, body: User): Unit +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt new file mode 100644 index 00000000000..ebd82222015 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt @@ -0,0 +1,39 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.springframework.stereotype.Service +@Service +class UserApiServiceImpl : UserApiService { + + override fun createUser(body: User): Unit { + TODO("Implement me") + } + + override fun createUsersWithArrayInput(body: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun createUsersWithListInput(body: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun deleteUser(username: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getUserByName(username: kotlin.String): User { + TODO("Implement me") + } + + override fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String { + TODO("Implement me") + } + + override fun logoutUser(): Unit { + TODO("Implement me") + } + + override fun updateUser(username: kotlin.String, body: User): Unit { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Category.kt new file mode 100644 index 00000000000..66d8d45d466 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Category.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.annotations.ApiModelProperty + +/** + * A category for a pet + * @param id + * @param name + */ +data class Category( + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("name") val name: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt new file mode 100644 index 00000000000..6b3e10c5694 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/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.annotations.ApiModelProperty + +/** + * Describes the result of uploading an image resource + * @param code + * @param type + * @param message + */ +data class ModelApiResponse( + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("code") val code: kotlin.Int? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("type") val type: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("message") val message: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Order.kt new file mode 100644 index 00000000000..fb52543d7ed --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Order.kt @@ -0,0 +1,59 @@ +package org.openapitools.model + +import java.util.Objects +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.annotations.ApiModelProperty + +/** + * 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( + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("petId") val petId: kotlin.Long? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("quantity") val quantity: kotlin.Int? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, + + @ApiModelProperty(example = "null", value = "Order Status") + @field:JsonProperty("status") val status: Order.Status? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("complete") val complete: kotlin.Boolean? = false +) { + + /** + * Order Status + * Values: placed,approved,delivered + */ + enum class Status(val value: kotlin.String) { + + @JsonProperty("placed") placed("placed"), + @JsonProperty("approved") approved("approved"), + @JsonProperty("delivered") delivered("delivered") + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Pet.kt new file mode 100644 index 00000000000..7e07af537d7 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Pet.kt @@ -0,0 +1,63 @@ +package org.openapitools.model + +import java.util.Objects +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.annotations.ApiModelProperty + +/** + * 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( + + @ApiModelProperty(example = "doggie", required = true, value = "") + @field:JsonProperty("name", required = true) val name: kotlin.String, + + @ApiModelProperty(example = "null", required = true, value = "") + @field:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @field:Valid + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("category") val category: Category? = null, + + @field:Valid + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("tags") val tags: kotlin.collections.List? = null, + + @ApiModelProperty(example = "null", value = "pet status in the store") + @field:JsonProperty("status") val status: Pet.Status? = null +) { + + /** + * pet status in the store + * Values: available,pending,sold + */ + enum class Status(val value: kotlin.String) { + + @JsonProperty("available") available("available"), + @JsonProperty("pending") pending("pending"), + @JsonProperty("sold") sold("sold") + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Tag.kt new file mode 100644 index 00000000000..1d540aa1677 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/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.annotations.ApiModelProperty + +/** + * A tag for a pet + * @param id + * @param name + */ +data class Tag( + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("name") val name: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/User.kt new file mode 100644 index 00000000000..87e20405d96 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/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.annotations.ApiModelProperty + +/** + * 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( + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("username") val username: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("firstName") val firstName: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("lastName") val lastName: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("email") val email: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("password") val password: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("phone") val phone: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "User Status") + @field:JsonProperty("userStatus") val userStatus: kotlin.Int? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/resources/application.yaml b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/resources/application.yaml new file mode 100644 index 00000000000..8e2ebcde976 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/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-source-swagger1/src/main/resources/openapi.yaml b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/resources/openapi.yaml new file mode 100644 index 00000000000..847cd9d2767 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/resources/openapi.yaml @@ -0,0 +1,763 @@ +openapi: 3.0.1 +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 +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: + operationId: addPet + requestBody: + 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 + responses: + "405": + content: {} + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + x-codegen-request-body-name: body + put: + operationId: updatePet + requestBody: + 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 + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + "405": + content: {} + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + x-codegen-request-body-name: body + /pet/findByStatus: + get: + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - 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": + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - 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": + content: {} + description: Invalid tag value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Finds Pets by tags + tags: + - pet + /pet/{petId}: + delete: + operationId: deletePet + parameters: + - in: header + name: api_key + schema: + type: string + - description: Pet id to delete + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "400": + content: {} + 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 + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + tags: + - pet + post: + operationId: updatePetWithForm + parameters: + - description: ID of pet that needs to be updated + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + application/x-www-form-urlencoded: + schema: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + responses: + "405": + content: {} + 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: + operationId: uploadFile + parameters: + - description: ID of pet to update + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + multipart/form-data: + schema: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + 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: + operationId: placeOrder + requestBody: + content: + '*/*': + 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": + content: {} + description: Invalid Order + summary: Place an order for a pet + tags: + - store + x-codegen-request-body-name: body + /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 + in: path + name: orderId + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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 generated exceptions + operationId: getOrderById + parameters: + - description: ID of pet that needs to be fetched + in: path + name: orderId + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Create user + tags: + - user + x-codegen-request-body-name: body + /user/createWithArray: + post: + operationId: createUsersWithArrayInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + /user/createWithList: + post: + operationId: createUsersWithListInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + /user/login: + get: + operationId: loginUser + parameters: + - description: The user name for login + in: query + name: username + required: true + schema: + type: string + - description: The password for login in clear text + in: query + name: password + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + format: int32 + type: integer + X-Expires-After: + description: date in UTC when token expires + schema: + format: date-time + type: string + "400": + content: {} + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user + /user/logout: + get: + operationId: logoutUser + responses: + default: + content: {} + description: successful operation + 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 + in: path + name: username + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + description: User not found + summary: Delete user + tags: + - user + get: + operationId: getUserByName + parameters: + - description: The name that needs to be fetched. Use user1 for testing. + in: path + name: username + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + description: successful operation + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + 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 + in: path + name: username + required: true + schema: + type: string + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + responses: + "400": + content: {} + description: Invalid user supplied + "404": + content: {} + description: User not found + summary: Updated user + tags: + - user + x-codegen-request-body-name: body +components: + 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: + 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: + 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 + 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 +x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/resources/static/swagger-ui.html b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/resources/static/swagger-ui.html new file mode 100644 index 00000000000..f85b6654f67 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/resources/static/swagger-ui.html @@ -0,0 +1,60 @@ + + + + + + Swagger UI + + + + + + + +
+ + + + + + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/test/kotlin/org/openapitools/api/PetApiTest.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/test/kotlin/org/openapitools/api/PetApiTest.kt new file mode 100644 index 00000000000..6625bcb8d5c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/test/kotlin/org/openapitools/api/PetApiTest.kt @@ -0,0 +1,129 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class PetApiTest { + + private val service: PetApiService = PetApiServiceImpl() + private val api: PetApiController = PetApiController(service) + + /** + * To test PetApiController.addPet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun addPetTest() { + val body: Pet = TODO() + val response: ResponseEntity = api.addPet(body) + + // TODO: test validations + } + + /** + * To test PetApiController.deletePet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deletePetTest() { + val petId: kotlin.Long = TODO() + val apiKey: kotlin.String? = TODO() + val response: ResponseEntity = api.deletePet(petId, apiKey) + + // TODO: test validations + } + + /** + * To test PetApiController.findPetsByStatus + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun findPetsByStatusTest() { + val status: kotlin.collections.List = TODO() + val response: ResponseEntity> = api.findPetsByStatus(status) + + // TODO: test validations + } + + /** + * To test PetApiController.findPetsByTags + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun findPetsByTagsTest() { + val tags: kotlin.collections.List = TODO() + val response: ResponseEntity> = api.findPetsByTags(tags) + + // TODO: test validations + } + + /** + * To test PetApiController.getPetById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getPetByIdTest() { + val petId: kotlin.Long = TODO() + val response: ResponseEntity = api.getPetById(petId) + + // TODO: test validations + } + + /** + * To test PetApiController.updatePet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updatePetTest() { + val body: Pet = TODO() + val response: ResponseEntity = api.updatePet(body) + + // TODO: test validations + } + + /** + * To test PetApiController.updatePetWithForm + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updatePetWithFormTest() { + val petId: kotlin.Long = TODO() + val name: kotlin.String? = TODO() + val status: kotlin.String? = TODO() + val response: ResponseEntity = api.updatePetWithForm(petId, name, status) + + // TODO: test validations + } + + /** + * To test PetApiController.uploadFile + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun uploadFileTest() { + val petId: kotlin.Long = TODO() + val additionalMetadata: kotlin.String? = TODO() + val file: org.springframework.core.io.Resource? = TODO() + val response: ResponseEntity = api.uploadFile(petId, additionalMetadata, file) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/test/kotlin/org/openapitools/api/StoreApiTest.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/test/kotlin/org/openapitools/api/StoreApiTest.kt new file mode 100644 index 00000000000..69e269b03ef --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/test/kotlin/org/openapitools/api/StoreApiTest.kt @@ -0,0 +1,66 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class StoreApiTest { + + private val service: StoreApiService = StoreApiServiceImpl() + private val api: StoreApiController = StoreApiController(service) + + /** + * To test StoreApiController.deleteOrder + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deleteOrderTest() { + val orderId: kotlin.String = TODO() + val response: ResponseEntity = api.deleteOrder(orderId) + + // TODO: test validations + } + + /** + * To test StoreApiController.getInventory + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getInventoryTest() { + val response: ResponseEntity> = api.getInventory() + + // TODO: test validations + } + + /** + * To test StoreApiController.getOrderById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getOrderByIdTest() { + val orderId: kotlin.Long = TODO() + val response: ResponseEntity = api.getOrderById(orderId) + + // TODO: test validations + } + + /** + * To test StoreApiController.placeOrder + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun placeOrderTest() { + val body: Order = TODO() + val response: ResponseEntity = api.placeOrder(body) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/test/kotlin/org/openapitools/api/UserApiTest.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/test/kotlin/org/openapitools/api/UserApiTest.kt new file mode 100644 index 00000000000..eb20423da71 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/test/kotlin/org/openapitools/api/UserApiTest.kt @@ -0,0 +1,124 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class UserApiTest { + + private val service: UserApiService = UserApiServiceImpl() + private val api: UserApiController = UserApiController(service) + + /** + * To test UserApiController.createUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUserTest() { + val body: User = TODO() + val response: ResponseEntity = api.createUser(body) + + // TODO: test validations + } + + /** + * To test UserApiController.createUsersWithArrayInput + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUsersWithArrayInputTest() { + val body: kotlin.collections.List = TODO() + val response: ResponseEntity = api.createUsersWithArrayInput(body) + + // TODO: test validations + } + + /** + * To test UserApiController.createUsersWithListInput + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUsersWithListInputTest() { + val body: kotlin.collections.List = TODO() + val response: ResponseEntity = api.createUsersWithListInput(body) + + // TODO: test validations + } + + /** + * To test UserApiController.deleteUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deleteUserTest() { + val username: kotlin.String = TODO() + val response: ResponseEntity = api.deleteUser(username) + + // TODO: test validations + } + + /** + * To test UserApiController.getUserByName + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getUserByNameTest() { + val username: kotlin.String = TODO() + val response: ResponseEntity = api.getUserByName(username) + + // TODO: test validations + } + + /** + * To test UserApiController.loginUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun loginUserTest() { + val username: kotlin.String = TODO() + val password: kotlin.String = TODO() + val response: ResponseEntity = api.loginUser(username, password) + + // TODO: test validations + } + + /** + * To test UserApiController.logoutUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun logoutUserTest() { + val response: ResponseEntity = api.logoutUser() + + // TODO: test validations + } + + /** + * To test UserApiController.updateUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updateUserTest() { + val username: kotlin.String = TODO() + val body: User = TODO() + val response: ResponseEntity = api.updateUser(username, body) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/.openapi-generator-ignore b/samples/server/petstore/kotlin-springboot-source-swagger2/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/.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-source-swagger2/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-source-swagger2/.openapi-generator/FILES new file mode 100644 index 00000000000..b7ad76a5ca4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/.openapi-generator/FILES @@ -0,0 +1,26 @@ +README.md +build.gradle.kts +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/Exceptions.kt +src/main/kotlin/org/openapitools/api/PetApiController.kt +src/main/kotlin/org/openapitools/api/PetApiService.kt +src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/StoreApiController.kt +src/main/kotlin/org/openapitools/api/StoreApiService.kt +src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/UserApiController.kt +src/main/kotlin/org/openapitools/api/UserApiService.kt +src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt +src/main/kotlin/org/openapitools/model/Category.kt +src/main/kotlin/org/openapitools/model/ModelApiResponse.kt +src/main/kotlin/org/openapitools/model/Order.kt +src/main/kotlin/org/openapitools/model/Pet.kt +src/main/kotlin/org/openapitools/model/Tag.kt +src/main/kotlin/org/openapitools/model/User.kt +src/main/resources/application.yaml +src/main/resources/openapi.yaml +src/main/resources/static/swagger-ui.html diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/.openapi-generator/VERSION b/samples/server/petstore/kotlin-springboot-source-swagger2/.openapi-generator/VERSION new file mode 100644 index 00000000000..5f68295fc19 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/README.md b/samples/server/petstore/kotlin-springboot-source-swagger2/README.md new file mode 100644 index 00000000000..b6865a08113 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/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-source-swagger2/build.gradle.kts b/samples/server/petstore/kotlin-springboot-source-swagger2/build.gradle.kts new file mode 100644 index 00000000000..0fcbdc0d67e --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/build.gradle.kts @@ -0,0 +1,58 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.0.M3") + } +} + +group = "org.openapitools" +version = "1.0.0" + +repositories { + mavenCentral() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +plugins { + val kotlinVersion = "1.3.30" + 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.2.0.M3" + id("io.spring.dependency-management") version "1.0.5.RELEASE" +} + +dependencies { + compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + compile("org.jetbrains.kotlin:kotlin-reflect") + compile("org.springframework.boot:spring-boot-starter-web") + compile("org.webjars:swagger-ui:4.8.1") + compile("org.webjars:webjars-locator-core") + compile("io.swagger.core.v3:swagger-annotations:2.1.13") + + compile("com.google.code.findbugs:jsr305:3.0.2") + compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") + compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + compile("com.fasterxml.jackson.module:jackson-module-kotlin") + compile("jakarta.validation:jakarta.validation-api") + compile("jakarta.annotation:jakarta.annotation-api:1.3.5") + + testCompile("org.jetbrains.kotlin:kotlin-test-junit5") + testCompile("org.springframework.boot:spring-boot-starter-test") { + exclude(module = "junit") + } +} + +repositories { + maven { url = uri("https://repo1.maven.org/maven2") } + maven { url = uri("https://repo.spring.io/snapshot") } + maven { url = uri("https://repo.spring.io/milestone") } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/pom.xml b/samples/server/petstore/kotlin-springboot-source-swagger2/pom.xml new file mode 100644 index 00000000000..c947ec6e043 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/pom.xml @@ -0,0 +1,176 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 4.8.1 + 2.1.13 + 3.0.2 + 1.3.5 + 1.3.31 + + 1.3.30 + UTF-8 + + + org.springframework.boot + spring-boot-starter-parent + 2.2.0.M3 + + + ${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-web + + + + + org.webjars + swagger-ui + ${swagger-ui.version} + + + org.webjars + webjars-locator-core + + + io.swagger.core.v3 + swagger-annotations + ${swagger-annotations.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 + + + + jakarta.validation + jakarta.validation-api + + + jakarta.annotation + jakarta.annotation-api + ${jakarta-annotation.version} + provided + + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin-test-junit5.version} + test + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/settings.gradle b/samples/server/petstore/kotlin-springboot-source-swagger2/settings.gradle new file mode 100644 index 00000000000..14844905cd4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/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-source-swagger2/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/Application.kt new file mode 100644 index 00000000000..2fe6de62479 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/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-source-swagger2/src/main/kotlin/org/openapitools/HomeController.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/HomeController.kt new file mode 100644 index 00000000000..fabc940cc83 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/HomeController.kt @@ -0,0 +1,46 @@ +package org.openapitools + +import org.springframework.context.annotation.Bean +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import com.fasterxml.jackson.dataformat.yaml.YAMLMapper +import org.springframework.beans.factory.annotation.Value +import org.springframework.core.io.Resource +import org.springframework.util.StreamUtils +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.GetMapping +import java.nio.charset.Charset + +/** + * Home redirection to OpenAPI api documentation + */ +@Controller +class HomeController { + private val apiDocsPath = "/openapi.json" + private val yamlMapper = YAMLMapper() + + @Value("classpath:/openapi.yaml") + private lateinit var openapi: Resource + + @Bean + fun openapiContent(): String { + return openapi.inputStream.use { + StreamUtils.copyToString(it, Charset.defaultCharset()) + } + } + + @GetMapping(value = ["/openapi.yaml"], produces = ["application/vnd.oai.openapi"]) + @ResponseBody + fun openapiYaml(): String = openapiContent() + + @GetMapping(value = ["/openapi.json"], produces = ["application/json"]) + @ResponseBody + fun openapiJson(): Any = yamlMapper.readValue(openapiContent(), Any::class.java) + + @GetMapping(value = ["/swagger-config.yaml"], produces = ["text/plain"]) + @ResponseBody + fun swaggerConfig(): String = "url: $apiDocsPath\n" + + @RequestMapping("/") + fun index(): String = "redirect:swagger-ui.html" +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 00000000000..88e892d0f49 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,19 @@ +package org.openapitools.api + +import org.springframework.web.context.request.NativeWebRequest + +import javax.servlet.http.HttpServletResponse +import java.io.IOException + +object ApiUtil { + fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { + try { + val res = req.getNativeResponse(HttpServletResponse::class.java) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) + } catch (e: IOException) { + throw RuntimeException(e) + } + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/Exceptions.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/Exceptions.kt new file mode 100644 index 00000000000..44190af7a01 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/Exceptions.kt @@ -0,0 +1,29 @@ +package org.openapitools.api + +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.bind.annotation.ExceptionHandler +import javax.servlet.http.HttpServletResponse +import javax.validation.ConstraintViolationException + +// TODO Extend ApiException for custom exception handling, e.g. the below NotFound exception +sealed class ApiException(msg: String, val code: Int) : Exception(msg) + +class NotFoundException(msg: String, code: Int = HttpStatus.NOT_FOUND.value()) : ApiException(msg, code) + + +@ControllerAdvice +class DefaultExceptionHandler { + + @ExceptionHandler(value = [ApiException::class]) + fun onApiException(ex: ApiException, response: HttpServletResponse): Unit = + response.sendError(ex.code, ex.message) + + @ExceptionHandler(value = [NotImplementedError::class]) + fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.NOT_IMPLEMENTED.value()) + + @ExceptionHandler(value = [ConstraintViolationException::class]) + fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message }) +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiController.kt new file mode 100644 index 00000000000..0213ba5ba3f --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -0,0 +1,178 @@ +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 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 = "405", description = "Invalid input") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/pet"], + consumes = ["application/json", "application/xml"] + ) + fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) + } + + @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}"] + ) + 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(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "400", description = "Invalid status value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "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(schema = Schema(implementation = Pet::class))]), + ApiResponse(responseCode = "400", description = "Invalid tag value") ], + security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "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"] + ) + 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 = "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"], + consumes = ["application/json", "application/xml"] + ) + fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) + } + + @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"] + ) + 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"] + ) + 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 detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?): ResponseEntity { + return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiService.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiService.kt new file mode 100644 index 00000000000..ee0e3bef83c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiService.kt @@ -0,0 +1,94 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet + +interface PetApiService { + + /** + * POST /pet : Add a new pet to the store + * + * @param body Pet object that needs to be added to the store (required) + * @return Invalid input (status code 405) + * @see PetApi#addPet + */ + fun addPet(body: Pet): Unit + + /** + * DELETE /pet/{petId} : Deletes a pet + * + * @param petId Pet id to delete (required) + * @param apiKey (optional) + * @return Invalid pet value (status code 400) + * @see PetApi#deletePet + */ + fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit + + /** + * GET /pet/findByStatus : Finds Pets by status + * Multiple status values can be provided with comma separated strings + * + * @param status Status values that need to be considered for filter (required) + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + * @see PetApi#findPetsByStatus + */ + fun findPetsByStatus(status: kotlin.collections.List): List + + /** + * GET /pet/findByTags : Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * + * @param tags Tags to filter by (required) + * @return successful operation (status code 200) + * or Invalid tag value (status code 400) + * @deprecated + * @see PetApi#findPetsByTags + */ + fun findPetsByTags(tags: kotlin.collections.List): List + + /** + * GET /pet/{petId} : Find pet by ID + * Returns a single pet + * + * @param petId ID of pet to return (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * @see PetApi#getPetById + */ + fun getPetById(petId: kotlin.Long): Pet + + /** + * PUT /pet : Update an existing pet + * + * @param body Pet object that needs to be added to the store (required) + * @return Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * or Validation exception (status code 405) + * @see PetApi#updatePet + */ + fun updatePet(body: Pet): Unit + + /** + * POST /pet/{petId} : Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated (required) + * @param name Updated name of the pet (optional) + * @param status Updated status of the pet (optional) + * @return Invalid input (status code 405) + * @see PetApi#updatePetWithForm + */ + fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit + + /** + * POST /pet/{petId}/uploadImage : uploads an image + * + * @param petId ID of pet to update (required) + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return successful operation (status code 200) + * @see PetApi#uploadFile + */ + fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt new file mode 100644 index 00000000000..452e4e400b7 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt @@ -0,0 +1,40 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.springframework.stereotype.Service +@Service +class PetApiServiceImpl : PetApiService { + + override fun addPet(body: Pet): Unit { + TODO("Implement me") + } + + override fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun findPetsByStatus(status: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun findPetsByTags(tags: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun getPetById(petId: kotlin.Long): Pet { + TODO("Implement me") + } + + override fun updatePet(body: Pet): Unit { + TODO("Implement me") + } + + override fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiController.kt new file mode 100644 index 00000000000..4106e3ed94f --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -0,0 +1,103 @@ +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 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}"] + ) + 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"] + ) + 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 generated 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"] + ) + 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"] + ) + fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order): ResponseEntity { + return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiService.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiService.kt new file mode 100644 index 00000000000..6de3e6cc1de --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiService.kt @@ -0,0 +1,48 @@ +package org.openapitools.api + +import org.openapitools.model.Order + +interface StoreApiService { + + /** + * DELETE /store/order/{orderId} : Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * + * @param orderId ID of the order that needs to be deleted (required) + * @return Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#deleteOrder + */ + fun deleteOrder(orderId: kotlin.String): Unit + + /** + * GET /store/inventory : Returns pet inventories by status + * Returns a map of status codes to quantities + * + * @return successful operation (status code 200) + * @see StoreApi#getInventory + */ + fun getInventory(): Map + + /** + * GET /store/order/{orderId} : Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * + * @param orderId ID of pet that needs to be fetched (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#getOrderById + */ + fun getOrderById(orderId: kotlin.Long): Order + + /** + * POST /store/order : Place an order for a pet + * + * @param body order placed for purchasing the pet (required) + * @return successful operation (status code 200) + * or Invalid Order (status code 400) + * @see StoreApi#placeOrder + */ + fun placeOrder(body: Order): Order +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt new file mode 100644 index 00000000000..7e733e28dc5 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt @@ -0,0 +1,23 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.springframework.stereotype.Service +@Service +class StoreApiServiceImpl : StoreApiService { + + override fun deleteOrder(orderId: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getInventory(): Map { + TODO("Implement me") + } + + override fun getOrderById(orderId: kotlin.Long): Order { + TODO("Implement me") + } + + override fun placeOrder(body: Order): Order { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiController.kt new file mode 100644 index 00000000000..ad2a558493b --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -0,0 +1,162 @@ +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 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") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user"] + ) + fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Creates list of users with given input array", + operationId = "createUsersWithArrayInput", + description = "", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user/createWithArray"] + ) + fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Creates list of users with given input array", + operationId = "createUsersWithListInput", + description = "", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user/createWithList"] + ) + fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) + } + + @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") ] + ) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/user/{username}"] + ) + 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"] + ) + 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"] + ) + fun loginUser(@NotNull @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) + } + + @Operation( + summary = "Logs out current logged in user session", + operationId = "logoutUser", + description = "", + responses = [ + ApiResponse(responseCode = "200", description = "successful operation") ] + ) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/user/logout"] + ) + 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") ] + ) + @RequestMapping( + method = [RequestMethod.PUT], + value = ["/user/{username}"] + ) + fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiService.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiService.kt new file mode 100644 index 00000000000..a1bcf6be237 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiService.kt @@ -0,0 +1,87 @@ +package org.openapitools.api + +import org.openapitools.model.User + +interface UserApiService { + + /** + * POST /user : Create user + * This can only be done by the logged in user. + * + * @param body Created user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUser + */ + fun createUser(body: User): Unit + + /** + * POST /user/createWithArray : Creates list of users with given input array + * + * @param body List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithArrayInput + */ + fun createUsersWithArrayInput(body: kotlin.collections.List): Unit + + /** + * POST /user/createWithList : Creates list of users with given input array + * + * @param body List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithListInput + */ + fun createUsersWithListInput(body: kotlin.collections.List): Unit + + /** + * DELETE /user/{username} : Delete user + * This can only be done by the logged in user. + * + * @param username The name that needs to be deleted (required) + * @return Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#deleteUser + */ + fun deleteUser(username: kotlin.String): Unit + + /** + * GET /user/{username} : Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. (required) + * @return successful operation (status code 200) + * or Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#getUserByName + */ + fun getUserByName(username: kotlin.String): User + + /** + * GET /user/login : Logs user into the system + * + * @param username The user name for login (required) + * @param password The password for login in clear text (required) + * @return successful operation (status code 200) + * or Invalid username/password supplied (status code 400) + * @see UserApi#loginUser + */ + fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String + + /** + * GET /user/logout : Logs out current logged in user session + * + * @return successful operation (status code 200) + * @see UserApi#logoutUser + */ + fun logoutUser(): Unit + + /** + * PUT /user/{username} : Updated user + * This can only be done by the logged in user. + * + * @param username name that need to be deleted (required) + * @param body Updated user object (required) + * @return Invalid user supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#updateUser + */ + fun updateUser(username: kotlin.String, body: User): Unit +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt new file mode 100644 index 00000000000..ebd82222015 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt @@ -0,0 +1,39 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.springframework.stereotype.Service +@Service +class UserApiServiceImpl : UserApiService { + + override fun createUser(body: User): Unit { + TODO("Implement me") + } + + override fun createUsersWithArrayInput(body: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun createUsersWithListInput(body: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun deleteUser(username: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getUserByName(username: kotlin.String): User { + TODO("Implement me") + } + + override fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String { + TODO("Implement me") + } + + override fun logoutUser(): Unit { + TODO("Implement me") + } + + override fun updateUser(username: kotlin.String, body: User): Unit { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Category.kt new file mode 100644 index 00000000000..f6eb292c2d3 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Category.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 category for a pet + * @param id + * @param name + */ +data class Category( + + @Schema(example = "null", description = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("name") val name: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt new file mode 100644 index 00000000000..b8a5657e99d --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/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 = "") + @field:JsonProperty("code") val code: kotlin.Int? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("type") val type: kotlin.String? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("message") val message: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Order.kt new file mode 100644 index 00000000000..4494ffa95bd --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Order.kt @@ -0,0 +1,59 @@ +package org.openapitools.model + +import java.util.Objects +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 = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("petId") val petId: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("quantity") val quantity: kotlin.Int? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, + + @Schema(example = "null", description = "Order Status") + @field:JsonProperty("status") val status: Order.Status? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("complete") val complete: kotlin.Boolean? = false +) { + + /** + * Order Status + * Values: placed,approved,delivered + */ + enum class Status(val value: kotlin.String) { + + @JsonProperty("placed") placed("placed"), + @JsonProperty("approved") approved("approved"), + @JsonProperty("delivered") delivered("delivered") + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Pet.kt new file mode 100644 index 00000000000..cd37d16c501 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Pet.kt @@ -0,0 +1,63 @@ +package org.openapitools.model + +import java.util.Objects +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 = "") + @field:JsonProperty("name", required = true) val name: kotlin.String, + + @Schema(example = "null", required = true, description = "") + @field:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, + + @Schema(example = "null", description = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @field:Valid + @Schema(example = "null", description = "") + @field:JsonProperty("category") val category: Category? = null, + + @field:Valid + @Schema(example = "null", description = "") + @field:JsonProperty("tags") val tags: kotlin.collections.List? = null, + + @Schema(example = "null", description = "pet status in the store") + @field:JsonProperty("status") val status: Pet.Status? = null +) { + + /** + * pet status in the store + * Values: available,pending,sold + */ + enum class Status(val value: kotlin.String) { + + @JsonProperty("available") available("available"), + @JsonProperty("pending") pending("pending"), + @JsonProperty("sold") sold("sold") + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Tag.kt new file mode 100644 index 00000000000..e6f18b5e01b --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/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 = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("name") val name: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/User.kt new file mode 100644 index 00000000000..0192450f9d0 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/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 = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("username") val username: kotlin.String? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("firstName") val firstName: kotlin.String? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("lastName") val lastName: kotlin.String? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("email") val email: kotlin.String? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("password") val password: kotlin.String? = null, + + @Schema(example = "null", description = "") + @field:JsonProperty("phone") val phone: kotlin.String? = null, + + @Schema(example = "null", description = "User Status") + @field:JsonProperty("userStatus") val userStatus: kotlin.Int? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/resources/application.yaml b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/resources/application.yaml new file mode 100644 index 00000000000..8e2ebcde976 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/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-source-swagger2/src/main/resources/openapi.yaml b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/resources/openapi.yaml new file mode 100644 index 00000000000..847cd9d2767 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/resources/openapi.yaml @@ -0,0 +1,763 @@ +openapi: 3.0.1 +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 +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: + operationId: addPet + requestBody: + 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 + responses: + "405": + content: {} + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + x-codegen-request-body-name: body + put: + operationId: updatePet + requestBody: + 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 + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + "405": + content: {} + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + x-codegen-request-body-name: body + /pet/findByStatus: + get: + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - 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": + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - 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": + content: {} + description: Invalid tag value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Finds Pets by tags + tags: + - pet + /pet/{petId}: + delete: + operationId: deletePet + parameters: + - in: header + name: api_key + schema: + type: string + - description: Pet id to delete + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "400": + content: {} + 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 + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + tags: + - pet + post: + operationId: updatePetWithForm + parameters: + - description: ID of pet that needs to be updated + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + application/x-www-form-urlencoded: + schema: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + responses: + "405": + content: {} + 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: + operationId: uploadFile + parameters: + - description: ID of pet to update + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + multipart/form-data: + schema: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + 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: + operationId: placeOrder + requestBody: + content: + '*/*': + 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": + content: {} + description: Invalid Order + summary: Place an order for a pet + tags: + - store + x-codegen-request-body-name: body + /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 + in: path + name: orderId + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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 generated exceptions + operationId: getOrderById + parameters: + - description: ID of pet that needs to be fetched + in: path + name: orderId + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Create user + tags: + - user + x-codegen-request-body-name: body + /user/createWithArray: + post: + operationId: createUsersWithArrayInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + /user/createWithList: + post: + operationId: createUsersWithListInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + /user/login: + get: + operationId: loginUser + parameters: + - description: The user name for login + in: query + name: username + required: true + schema: + type: string + - description: The password for login in clear text + in: query + name: password + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + format: int32 + type: integer + X-Expires-After: + description: date in UTC when token expires + schema: + format: date-time + type: string + "400": + content: {} + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user + /user/logout: + get: + operationId: logoutUser + responses: + default: + content: {} + description: successful operation + 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 + in: path + name: username + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + description: User not found + summary: Delete user + tags: + - user + get: + operationId: getUserByName + parameters: + - description: The name that needs to be fetched. Use user1 for testing. + in: path + name: username + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + description: successful operation + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + 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 + in: path + name: username + required: true + schema: + type: string + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + responses: + "400": + content: {} + description: Invalid user supplied + "404": + content: {} + description: User not found + summary: Updated user + tags: + - user + x-codegen-request-body-name: body +components: + 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: + 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: + 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 + 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 +x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/resources/static/swagger-ui.html b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/resources/static/swagger-ui.html new file mode 100644 index 00000000000..f85b6654f67 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/resources/static/swagger-ui.html @@ -0,0 +1,60 @@ + + + + + + Swagger UI + + + + + + + +
+ + + + + + diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/test/kotlin/org/openapitools/api/PetApiTest.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/test/kotlin/org/openapitools/api/PetApiTest.kt new file mode 100644 index 00000000000..6625bcb8d5c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/test/kotlin/org/openapitools/api/PetApiTest.kt @@ -0,0 +1,129 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class PetApiTest { + + private val service: PetApiService = PetApiServiceImpl() + private val api: PetApiController = PetApiController(service) + + /** + * To test PetApiController.addPet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun addPetTest() { + val body: Pet = TODO() + val response: ResponseEntity = api.addPet(body) + + // TODO: test validations + } + + /** + * To test PetApiController.deletePet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deletePetTest() { + val petId: kotlin.Long = TODO() + val apiKey: kotlin.String? = TODO() + val response: ResponseEntity = api.deletePet(petId, apiKey) + + // TODO: test validations + } + + /** + * To test PetApiController.findPetsByStatus + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun findPetsByStatusTest() { + val status: kotlin.collections.List = TODO() + val response: ResponseEntity> = api.findPetsByStatus(status) + + // TODO: test validations + } + + /** + * To test PetApiController.findPetsByTags + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun findPetsByTagsTest() { + val tags: kotlin.collections.List = TODO() + val response: ResponseEntity> = api.findPetsByTags(tags) + + // TODO: test validations + } + + /** + * To test PetApiController.getPetById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getPetByIdTest() { + val petId: kotlin.Long = TODO() + val response: ResponseEntity = api.getPetById(petId) + + // TODO: test validations + } + + /** + * To test PetApiController.updatePet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updatePetTest() { + val body: Pet = TODO() + val response: ResponseEntity = api.updatePet(body) + + // TODO: test validations + } + + /** + * To test PetApiController.updatePetWithForm + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updatePetWithFormTest() { + val petId: kotlin.Long = TODO() + val name: kotlin.String? = TODO() + val status: kotlin.String? = TODO() + val response: ResponseEntity = api.updatePetWithForm(petId, name, status) + + // TODO: test validations + } + + /** + * To test PetApiController.uploadFile + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun uploadFileTest() { + val petId: kotlin.Long = TODO() + val additionalMetadata: kotlin.String? = TODO() + val file: org.springframework.core.io.Resource? = TODO() + val response: ResponseEntity = api.uploadFile(petId, additionalMetadata, file) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/test/kotlin/org/openapitools/api/StoreApiTest.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/test/kotlin/org/openapitools/api/StoreApiTest.kt new file mode 100644 index 00000000000..69e269b03ef --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/test/kotlin/org/openapitools/api/StoreApiTest.kt @@ -0,0 +1,66 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class StoreApiTest { + + private val service: StoreApiService = StoreApiServiceImpl() + private val api: StoreApiController = StoreApiController(service) + + /** + * To test StoreApiController.deleteOrder + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deleteOrderTest() { + val orderId: kotlin.String = TODO() + val response: ResponseEntity = api.deleteOrder(orderId) + + // TODO: test validations + } + + /** + * To test StoreApiController.getInventory + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getInventoryTest() { + val response: ResponseEntity> = api.getInventory() + + // TODO: test validations + } + + /** + * To test StoreApiController.getOrderById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getOrderByIdTest() { + val orderId: kotlin.Long = TODO() + val response: ResponseEntity = api.getOrderById(orderId) + + // TODO: test validations + } + + /** + * To test StoreApiController.placeOrder + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun placeOrderTest() { + val body: Order = TODO() + val response: ResponseEntity = api.placeOrder(body) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/test/kotlin/org/openapitools/api/UserApiTest.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/test/kotlin/org/openapitools/api/UserApiTest.kt new file mode 100644 index 00000000000..eb20423da71 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/test/kotlin/org/openapitools/api/UserApiTest.kt @@ -0,0 +1,124 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class UserApiTest { + + private val service: UserApiService = UserApiServiceImpl() + private val api: UserApiController = UserApiController(service) + + /** + * To test UserApiController.createUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUserTest() { + val body: User = TODO() + val response: ResponseEntity = api.createUser(body) + + // TODO: test validations + } + + /** + * To test UserApiController.createUsersWithArrayInput + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUsersWithArrayInputTest() { + val body: kotlin.collections.List = TODO() + val response: ResponseEntity = api.createUsersWithArrayInput(body) + + // TODO: test validations + } + + /** + * To test UserApiController.createUsersWithListInput + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUsersWithListInputTest() { + val body: kotlin.collections.List = TODO() + val response: ResponseEntity = api.createUsersWithListInput(body) + + // TODO: test validations + } + + /** + * To test UserApiController.deleteUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deleteUserTest() { + val username: kotlin.String = TODO() + val response: ResponseEntity = api.deleteUser(username) + + // TODO: test validations + } + + /** + * To test UserApiController.getUserByName + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getUserByNameTest() { + val username: kotlin.String = TODO() + val response: ResponseEntity = api.getUserByName(username) + + // TODO: test validations + } + + /** + * To test UserApiController.loginUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun loginUserTest() { + val username: kotlin.String = TODO() + val password: kotlin.String = TODO() + val response: ResponseEntity = api.loginUser(username, password) + + // TODO: test validations + } + + /** + * To test UserApiController.logoutUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun logoutUserTest() { + val response: ResponseEntity = api.logoutUser() + + // TODO: test validations + } + + /** + * To test UserApiController.updateUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updateUserTest() { + val username: kotlin.String = TODO() + val body: User = TODO() + val response: ResponseEntity = api.updateUser(username, body) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/.openapi-generator-ignore b/samples/server/petstore/kotlin-springboot-springfox/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/.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-springfox/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-springfox/.openapi-generator/FILES new file mode 100644 index 00000000000..22e30ab6345 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/.openapi-generator/FILES @@ -0,0 +1,27 @@ +README.md +build.gradle.kts +pom.xml +settings.gradle +src/main/kotlin/org/openapitools/Application.kt +src/main/kotlin/org/openapitools/HomeController.kt +src/main/kotlin/org/openapitools/SpringFoxConfiguration.kt +src/main/kotlin/org/openapitools/api/ApiUtil.kt +src/main/kotlin/org/openapitools/api/Exceptions.kt +src/main/kotlin/org/openapitools/api/PetApiController.kt +src/main/kotlin/org/openapitools/api/PetApiService.kt +src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/StoreApiController.kt +src/main/kotlin/org/openapitools/api/StoreApiService.kt +src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt +src/main/kotlin/org/openapitools/api/UserApiController.kt +src/main/kotlin/org/openapitools/api/UserApiService.kt +src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt +src/main/kotlin/org/openapitools/model/Category.kt +src/main/kotlin/org/openapitools/model/ModelApiResponse.kt +src/main/kotlin/org/openapitools/model/Order.kt +src/main/kotlin/org/openapitools/model/Pet.kt +src/main/kotlin/org/openapitools/model/Tag.kt +src/main/kotlin/org/openapitools/model/User.kt +src/main/resources/application.yaml +src/main/resources/openapi.yaml +src/main/resources/static/swagger-ui.html diff --git a/samples/server/petstore/kotlin-springboot-springfox/.openapi-generator/VERSION b/samples/server/petstore/kotlin-springboot-springfox/.openapi-generator/VERSION new file mode 100644 index 00000000000..5f68295fc19 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/kotlin-springboot-springfox/README.md b/samples/server/petstore/kotlin-springboot-springfox/README.md new file mode 100644 index 00000000000..b6865a08113 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/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-springfox/build.gradle.kts b/samples/server/petstore/kotlin-springboot-springfox/build.gradle.kts new file mode 100644 index 00000000000..7fb016df3e9 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/build.gradle.kts @@ -0,0 +1,58 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.0.M3") + } +} + +group = "org.openapitools" +version = "1.0.0" + +repositories { + mavenCentral() +} + +tasks.withType { + kotlinOptions.jvmTarget = "1.8" +} + +plugins { + val kotlinVersion = "1.3.30" + 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.2.0.M3" + id("io.spring.dependency-management") version "1.0.5.RELEASE" +} + +dependencies { + compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + compile("org.jetbrains.kotlin:kotlin-reflect") + compile("org.springframework.boot:spring-boot-starter-web") + compile("io.springfox:springfox-swagger2:2.9.2") + compile("org.webjars:swagger-ui:4.8.1") + compile("org.webjars:webjars-locator-core") + + compile("com.google.code.findbugs:jsr305:3.0.2") + compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") + compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + compile("com.fasterxml.jackson.module:jackson-module-kotlin") + compile("jakarta.validation:jakarta.validation-api") + compile("jakarta.annotation:jakarta.annotation-api:1.3.5") + + testCompile("org.jetbrains.kotlin:kotlin-test-junit5") + testCompile("org.springframework.boot:spring-boot-starter-test") { + exclude(module = "junit") + } +} + +repositories { + maven { url = uri("https://repo1.maven.org/maven2") } + maven { url = uri("https://repo.spring.io/snapshot") } + maven { url = uri("https://repo.spring.io/milestone") } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/pom.xml b/samples/server/petstore/kotlin-springboot-springfox/pom.xml new file mode 100644 index 00000000000..68ab20f49d6 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/pom.xml @@ -0,0 +1,177 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 2.9.2 + 4.8.1 + 3.0.2 + 1.3.5 + 1.3.31 + + 1.3.30 + UTF-8 + + + org.springframework.boot + spring-boot-starter-parent + 2.2.0.M3 + + + ${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-web + + + + + + io.springfox + springfox-swagger2 + ${springfox-swagger2.version} + + + org.webjars + swagger-ui + ${swagger-ui.version} + + + org.webjars + webjars-locator-core + + + + + com.google.code.findbugs + jsr305 + ${findbugs-jsr305.version} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + jakarta.validation + jakarta.validation-api + + + jakarta.annotation + jakarta.annotation-api + ${jakarta-annotation.version} + provided + + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin-test-junit5.version} + test + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + diff --git a/samples/server/petstore/kotlin-springboot-springfox/settings.gradle b/samples/server/petstore/kotlin-springboot-springfox/settings.gradle new file mode 100644 index 00000000000..14844905cd4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/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-springfox/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/Application.kt new file mode 100644 index 00000000000..2fe6de62479 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/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-springfox/src/main/kotlin/org/openapitools/HomeController.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/HomeController.kt new file mode 100644 index 00000000000..66c00124366 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/HomeController.kt @@ -0,0 +1,22 @@ +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 + +/** + * Home redirection to OpenAPI api documentation + */ +@Controller +class HomeController { + private val apiDocsPath = "/v2/api-docs" + + @GetMapping(value = ["/swagger-config.yaml"], produces = ["text/plain"]) + @ResponseBody + fun swaggerConfig(): String = "url: $apiDocsPath\n" + + @RequestMapping("/") + fun index(): String = "redirect:swagger-ui.html" +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/SpringFoxConfiguration.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/SpringFoxConfiguration.kt new file mode 100644 index 00000000000..eace83681c9 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/SpringFoxConfiguration.kt @@ -0,0 +1,63 @@ +package org.openapitools + +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.web.util.UriComponentsBuilder +import springfox.documentation.builders.ApiInfoBuilder +import springfox.documentation.builders.RequestHandlerSelectors +import springfox.documentation.service.ApiInfo +import springfox.documentation.service.Contact +import springfox.documentation.spi.DocumentationType +import springfox.documentation.spring.web.paths.Paths +import springfox.documentation.spring.web.paths.RelativePathProvider +import springfox.documentation.spring.web.plugins.Docket +import springfox.documentation.swagger2.annotations.EnableSwagger2 +import javax.servlet.ServletContext + +@javax.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"]) +@Configuration +@EnableSwagger2 +class SpringFoxConfiguration { + + fun apiInfo(): ApiInfo { + return ApiInfoBuilder() + .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("Apache-2.0") + .licenseUrl("https://www.apache.org/licenses/LICENSE-2.0.html") + .termsOfServiceUrl("") + .version("1.0.0") + .contact(Contact("", "", "")) + .build() + } + + @Bean + fun customImplementation(servletContext: ServletContext, @Value("\${openapi.openAPIPetstore.base-path:/v2}") basePath: String): Docket { + return Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.basePackage("org.openapitools.api")) + .build() + .pathProvider(BasePathAwareRelativePathProvider(servletContext, basePath)) + .directModelSubstitute(java.time.LocalDate::class.java, java.sql.Date::class.java) + .directModelSubstitute(java.time.OffsetDateTime::class.java, java.util.Date::class.java) + .apiInfo(apiInfo()) + } + + class BasePathAwareRelativePathProvider(servletContext: ServletContext, private val basePath: String) : + RelativePathProvider(servletContext) { + + override fun applicationPath(): String { + return Paths.removeAdjacentForwardSlashes( + UriComponentsBuilder.fromPath(super.applicationPath()).path(basePath).build().toString() + ) + } + + override fun getOperationPath(operationPath: String): String { + val uriComponentsBuilder = UriComponentsBuilder.fromPath("/") + return Paths.removeAdjacentForwardSlashes( + uriComponentsBuilder.path(operationPath.replaceFirst("^$basePath", "")).build().toString() + ) + } + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 00000000000..88e892d0f49 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,19 @@ +package org.openapitools.api + +import org.springframework.web.context.request.NativeWebRequest + +import javax.servlet.http.HttpServletResponse +import java.io.IOException + +object ApiUtil { + fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { + try { + val res = req.getNativeResponse(HttpServletResponse::class.java) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) + } catch (e: IOException) { + throw RuntimeException(e) + } + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/Exceptions.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/Exceptions.kt new file mode 100644 index 00000000000..44190af7a01 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/Exceptions.kt @@ -0,0 +1,29 @@ +package org.openapitools.api + +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.bind.annotation.ExceptionHandler +import javax.servlet.http.HttpServletResponse +import javax.validation.ConstraintViolationException + +// TODO Extend ApiException for custom exception handling, e.g. the below NotFound exception +sealed class ApiException(msg: String, val code: Int) : Exception(msg) + +class NotFoundException(msg: String, code: Int = HttpStatus.NOT_FOUND.value()) : ApiException(msg, code) + + +@ControllerAdvice +class DefaultExceptionHandler { + + @ExceptionHandler(value = [ApiException::class]) + fun onApiException(ex: ApiException, response: HttpServletResponse): Unit = + response.sendError(ex.code, ex.message) + + @ExceptionHandler(value = [NotImplementedError::class]) + fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.NOT_IMPLEMENTED.value()) + + @ExceptionHandler(value = [ConstraintViolationException::class]) + fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message }) +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiController.kt new file mode 100644 index 00000000000..75079add0cb --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -0,0 +1,181 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import io.swagger.annotations.ApiResponse +import io.swagger.annotations.ApiResponses +import io.swagger.annotations.Authorization +import io.swagger.annotations.AuthorizationScope +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 kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@Api(value = "pet", description = "The pet API") +@RequestMapping("\${api.base-path:/v2}") +class PetApiController(@Autowired(required = true) val service: PetApiService) { + + + @ApiOperation( + value = "Add a new pet to the store", + nickname = "addPet", + notes = "", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 405, message = "Invalid input")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/pet"], + consumes = ["application/json", "application/xml"] + ) + fun addPet(@ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) + } + + + @ApiOperation( + value = "Deletes a pet", + nickname = "deletePet", + notes = "", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 400, message = "Invalid pet value")]) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/pet/{petId}"] + ) + fun deletePet(@ApiParam(value = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "") @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { + return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) + } + + + @ApiOperation( + value = "Finds Pets by status", + nickname = "findPetsByStatus", + notes = "Multiple status values can be provided with comma separated strings", + response = Pet::class, + responseContainer = "List", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid status value")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/pet/findByStatus"], + produces = ["application/xml", "application/json"] + ) + fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { + return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Finds Pets by tags", + nickname = "findPetsByTags", + notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + response = Pet::class, + responseContainer = "List", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid tag value")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/pet/findByTags"], + produces = ["application/xml", "application/json"] + ) + fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { + return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Find pet by ID", + nickname = "getPetById", + notes = "Returns a single pet", + response = Pet::class, + authorizations = [Authorization(value = "api_key")]) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/pet/{petId}"], + produces = ["application/xml", "application/json"] + ) + fun getPetById(@ApiParam(value = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity { + return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Update an existing pet", + nickname = "updatePet", + notes = "", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found"),ApiResponse(code = 405, message = "Validation exception")]) + @RequestMapping( + method = [RequestMethod.PUT], + value = ["/pet"], + consumes = ["application/json", "application/xml"] + ) + fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet): ResponseEntity { + return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) + } + + + @ApiOperation( + value = "Updates a pet in the store with form data", + nickname = "updatePetWithForm", + notes = "", + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 405, message = "Invalid input")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/pet/{petId}"], + consumes = ["application/x-www-form-urlencoded"] + ) + fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Updated name of the pet") @RequestParam(value = "name", required = false) name: kotlin.String? ,@ApiParam(value = "Updated status of the pet") @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { + return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) + } + + + @ApiOperation( + value = "uploads an image", + nickname = "uploadFile", + notes = "", + response = ModelApiResponse::class, + authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/pet/{petId}/uploadImage"], + produces = ["application/json"], + consumes = ["multipart/form-data"] + ) + fun uploadFile(@ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Additional data to pass to server") @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?): ResponseEntity { + return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiService.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiService.kt new file mode 100644 index 00000000000..ee0e3bef83c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiService.kt @@ -0,0 +1,94 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet + +interface PetApiService { + + /** + * POST /pet : Add a new pet to the store + * + * @param body Pet object that needs to be added to the store (required) + * @return Invalid input (status code 405) + * @see PetApi#addPet + */ + fun addPet(body: Pet): Unit + + /** + * DELETE /pet/{petId} : Deletes a pet + * + * @param petId Pet id to delete (required) + * @param apiKey (optional) + * @return Invalid pet value (status code 400) + * @see PetApi#deletePet + */ + fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit + + /** + * GET /pet/findByStatus : Finds Pets by status + * Multiple status values can be provided with comma separated strings + * + * @param status Status values that need to be considered for filter (required) + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + * @see PetApi#findPetsByStatus + */ + fun findPetsByStatus(status: kotlin.collections.List): List + + /** + * GET /pet/findByTags : Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * + * @param tags Tags to filter by (required) + * @return successful operation (status code 200) + * or Invalid tag value (status code 400) + * @deprecated + * @see PetApi#findPetsByTags + */ + fun findPetsByTags(tags: kotlin.collections.List): List + + /** + * GET /pet/{petId} : Find pet by ID + * Returns a single pet + * + * @param petId ID of pet to return (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * @see PetApi#getPetById + */ + fun getPetById(petId: kotlin.Long): Pet + + /** + * PUT /pet : Update an existing pet + * + * @param body Pet object that needs to be added to the store (required) + * @return Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * or Validation exception (status code 405) + * @see PetApi#updatePet + */ + fun updatePet(body: Pet): Unit + + /** + * POST /pet/{petId} : Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated (required) + * @param name Updated name of the pet (optional) + * @param status Updated status of the pet (optional) + * @return Invalid input (status code 405) + * @see PetApi#updatePetWithForm + */ + fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit + + /** + * POST /pet/{petId}/uploadImage : uploads an image + * + * @param petId ID of pet to update (required) + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return successful operation (status code 200) + * @see PetApi#uploadFile + */ + fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt new file mode 100644 index 00000000000..452e4e400b7 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt @@ -0,0 +1,40 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.springframework.stereotype.Service +@Service +class PetApiServiceImpl : PetApiService { + + override fun addPet(body: Pet): Unit { + TODO("Implement me") + } + + override fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun findPetsByStatus(status: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun findPetsByTags(tags: kotlin.collections.List): List { + TODO("Implement me") + } + + override fun getPetById(petId: kotlin.Long): Pet { + TODO("Implement me") + } + + override fun updatePet(body: Pet): Unit { + TODO("Implement me") + } + + override fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit { + TODO("Implement me") + } + + override fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiController.kt new file mode 100644 index 00000000000..c3e90f46fd5 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -0,0 +1,106 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import io.swagger.annotations.ApiResponse +import io.swagger.annotations.ApiResponses +import io.swagger.annotations.Authorization +import io.swagger.annotations.AuthorizationScope +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 kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@Api(value = "store", description = "The store API") +@RequestMapping("\${api.base-path:/v2}") +class StoreApiController(@Autowired(required = true) val service: StoreApiService) { + + + @ApiOperation( + value = "Delete purchase order by ID", + nickname = "deleteOrder", + notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors") + @ApiResponses( + value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/store/order/{orderId}"] + ) + fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { + return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) + } + + + @ApiOperation( + value = "Returns pet inventories by status", + nickname = "getInventory", + notes = "Returns a map of status codes to quantities", + response = kotlin.Int::class, + responseContainer = "Map", + authorizations = [Authorization(value = "api_key")]) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/store/inventory"], + produces = ["application/json"] + ) + fun getInventory(): ResponseEntity> { + return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Find purchase order by ID", + nickname = "getOrderById", + notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", + response = Order::class) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/store/order/{orderId}"], + produces = ["application/xml", "application/json"] + ) + fun getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { + return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Place an order for a pet", + nickname = "placeOrder", + notes = "", + response = Order::class) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/store/order"], + produces = ["application/xml", "application/json"] + ) + fun placeOrder(@ApiParam(value = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order): ResponseEntity { + return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiService.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiService.kt new file mode 100644 index 00000000000..6de3e6cc1de --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiService.kt @@ -0,0 +1,48 @@ +package org.openapitools.api + +import org.openapitools.model.Order + +interface StoreApiService { + + /** + * DELETE /store/order/{orderId} : Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * + * @param orderId ID of the order that needs to be deleted (required) + * @return Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#deleteOrder + */ + fun deleteOrder(orderId: kotlin.String): Unit + + /** + * GET /store/inventory : Returns pet inventories by status + * Returns a map of status codes to quantities + * + * @return successful operation (status code 200) + * @see StoreApi#getInventory + */ + fun getInventory(): Map + + /** + * GET /store/order/{orderId} : Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * + * @param orderId ID of pet that needs to be fetched (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Order not found (status code 404) + * @see StoreApi#getOrderById + */ + fun getOrderById(orderId: kotlin.Long): Order + + /** + * POST /store/order : Place an order for a pet + * + * @param body order placed for purchasing the pet (required) + * @return successful operation (status code 200) + * or Invalid Order (status code 400) + * @see StoreApi#placeOrder + */ + fun placeOrder(body: Order): Order +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt new file mode 100644 index 00000000000..7e733e28dc5 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt @@ -0,0 +1,23 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.springframework.stereotype.Service +@Service +class StoreApiServiceImpl : StoreApiService { + + override fun deleteOrder(orderId: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getInventory(): Map { + TODO("Implement me") + } + + override fun getOrderById(orderId: kotlin.Long): Order { + TODO("Implement me") + } + + override fun placeOrder(body: Order): Order { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiController.kt new file mode 100644 index 00000000000..5e7076f405c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -0,0 +1,162 @@ +package org.openapitools.api + +import org.openapitools.model.User +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import io.swagger.annotations.ApiResponse +import io.swagger.annotations.ApiResponses +import io.swagger.annotations.Authorization +import io.swagger.annotations.AuthorizationScope +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 kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@Api(value = "user", description = "The user API") +@RequestMapping("\${api.base-path:/v2}") +class UserApiController(@Autowired(required = true) val service: UserApiService) { + + + @ApiOperation( + value = "Create user", + nickname = "createUser", + notes = "This can only be done by the logged in user.") + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user"] + ) + fun createUser(@ApiParam(value = "Created user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Creates list of users with given input array", + nickname = "createUsersWithArrayInput", + notes = "") + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user/createWithArray"] + ) + fun createUsersWithArrayInput(@ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Creates list of users with given input array", + nickname = "createUsersWithListInput", + notes = "") + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( + method = [RequestMethod.POST], + value = ["/user/createWithList"] + ) + fun createUsersWithListInput(@ApiParam(value = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { + return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Delete user", + nickname = "deleteUser", + notes = "This can only be done by the logged in user.") + @ApiResponses( + value = [ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @RequestMapping( + method = [RequestMethod.DELETE], + value = ["/user/{username}"] + ) + fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) + } + + + @ApiOperation( + value = "Get user by user name", + nickname = "getUserByName", + notes = "", + response = User::class) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = User::class),ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/user/{username}"], + produces = ["application/xml", "application/json"] + ) + fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity { + return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Logs user into the system", + nickname = "loginUser", + notes = "", + response = kotlin.String::class) + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/user/login"], + produces = ["application/xml", "application/json"] + ) + fun loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { + return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Logs out current logged in user session", + nickname = "logoutUser", + notes = "") + @ApiResponses( + value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( + method = [RequestMethod.GET], + value = ["/user/logout"] + ) + fun logoutUser(): ResponseEntity { + return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) + } + + + @ApiOperation( + value = "Updated user", + nickname = "updateUser", + notes = "This can only be done by the logged in user.") + @ApiResponses( + value = [ApiResponse(code = 400, message = "Invalid user supplied"),ApiResponse(code = 404, message = "User not found")]) + @RequestMapping( + method = [RequestMethod.PUT], + value = ["/user/{username}"] + ) + fun updateUser(@ApiParam(value = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@ApiParam(value = "Updated user object", required = true) @Valid @RequestBody body: User): ResponseEntity { + return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiService.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiService.kt new file mode 100644 index 00000000000..a1bcf6be237 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiService.kt @@ -0,0 +1,87 @@ +package org.openapitools.api + +import org.openapitools.model.User + +interface UserApiService { + + /** + * POST /user : Create user + * This can only be done by the logged in user. + * + * @param body Created user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUser + */ + fun createUser(body: User): Unit + + /** + * POST /user/createWithArray : Creates list of users with given input array + * + * @param body List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithArrayInput + */ + fun createUsersWithArrayInput(body: kotlin.collections.List): Unit + + /** + * POST /user/createWithList : Creates list of users with given input array + * + * @param body List of user object (required) + * @return successful operation (status code 200) + * @see UserApi#createUsersWithListInput + */ + fun createUsersWithListInput(body: kotlin.collections.List): Unit + + /** + * DELETE /user/{username} : Delete user + * This can only be done by the logged in user. + * + * @param username The name that needs to be deleted (required) + * @return Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#deleteUser + */ + fun deleteUser(username: kotlin.String): Unit + + /** + * GET /user/{username} : Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. (required) + * @return successful operation (status code 200) + * or Invalid username supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#getUserByName + */ + fun getUserByName(username: kotlin.String): User + + /** + * GET /user/login : Logs user into the system + * + * @param username The user name for login (required) + * @param password The password for login in clear text (required) + * @return successful operation (status code 200) + * or Invalid username/password supplied (status code 400) + * @see UserApi#loginUser + */ + fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String + + /** + * GET /user/logout : Logs out current logged in user session + * + * @return successful operation (status code 200) + * @see UserApi#logoutUser + */ + fun logoutUser(): Unit + + /** + * PUT /user/{username} : Updated user + * This can only be done by the logged in user. + * + * @param username name that need to be deleted (required) + * @param body Updated user object (required) + * @return Invalid user supplied (status code 400) + * or User not found (status code 404) + * @see UserApi#updateUser + */ + fun updateUser(username: kotlin.String, body: User): Unit +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt new file mode 100644 index 00000000000..ebd82222015 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt @@ -0,0 +1,39 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.springframework.stereotype.Service +@Service +class UserApiServiceImpl : UserApiService { + + override fun createUser(body: User): Unit { + TODO("Implement me") + } + + override fun createUsersWithArrayInput(body: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun createUsersWithListInput(body: kotlin.collections.List): Unit { + TODO("Implement me") + } + + override fun deleteUser(username: kotlin.String): Unit { + TODO("Implement me") + } + + override fun getUserByName(username: kotlin.String): User { + TODO("Implement me") + } + + override fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String { + TODO("Implement me") + } + + override fun logoutUser(): Unit { + TODO("Implement me") + } + + override fun updateUser(username: kotlin.String, body: User): Unit { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Category.kt new file mode 100644 index 00000000000..66d8d45d466 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Category.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.annotations.ApiModelProperty + +/** + * A category for a pet + * @param id + * @param name + */ +data class Category( + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("name") val name: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt new file mode 100644 index 00000000000..6b3e10c5694 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/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.annotations.ApiModelProperty + +/** + * Describes the result of uploading an image resource + * @param code + * @param type + * @param message + */ +data class ModelApiResponse( + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("code") val code: kotlin.Int? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("type") val type: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("message") val message: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Order.kt new file mode 100644 index 00000000000..fb52543d7ed --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Order.kt @@ -0,0 +1,59 @@ +package org.openapitools.model + +import java.util.Objects +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.annotations.ApiModelProperty + +/** + * 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( + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("petId") val petId: kotlin.Long? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("quantity") val quantity: kotlin.Int? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, + + @ApiModelProperty(example = "null", value = "Order Status") + @field:JsonProperty("status") val status: Order.Status? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("complete") val complete: kotlin.Boolean? = false +) { + + /** + * Order Status + * Values: placed,approved,delivered + */ + enum class Status(val value: kotlin.String) { + + @JsonProperty("placed") placed("placed"), + @JsonProperty("approved") approved("approved"), + @JsonProperty("delivered") delivered("delivered") + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Pet.kt new file mode 100644 index 00000000000..7e07af537d7 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Pet.kt @@ -0,0 +1,63 @@ +package org.openapitools.model + +import java.util.Objects +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.annotations.ApiModelProperty + +/** + * 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( + + @ApiModelProperty(example = "doggie", required = true, value = "") + @field:JsonProperty("name", required = true) val name: kotlin.String, + + @ApiModelProperty(example = "null", required = true, value = "") + @field:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @field:Valid + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("category") val category: Category? = null, + + @field:Valid + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("tags") val tags: kotlin.collections.List? = null, + + @ApiModelProperty(example = "null", value = "pet status in the store") + @field:JsonProperty("status") val status: Pet.Status? = null +) { + + /** + * pet status in the store + * Values: available,pending,sold + */ + enum class Status(val value: kotlin.String) { + + @JsonProperty("available") available("available"), + @JsonProperty("pending") pending("pending"), + @JsonProperty("sold") sold("sold") + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Tag.kt new file mode 100644 index 00000000000..1d540aa1677 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/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.annotations.ApiModelProperty + +/** + * A tag for a pet + * @param id + * @param name + */ +data class Tag( + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("name") val name: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/User.kt new file mode 100644 index 00000000000..87e20405d96 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/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.annotations.ApiModelProperty + +/** + * 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( + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("id") val id: kotlin.Long? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("username") val username: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("firstName") val firstName: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("lastName") val lastName: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("email") val email: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("password") val password: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "") + @field:JsonProperty("phone") val phone: kotlin.String? = null, + + @ApiModelProperty(example = "null", value = "User Status") + @field:JsonProperty("userStatus") val userStatus: kotlin.Int? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/resources/application.yaml b/samples/server/petstore/kotlin-springboot-springfox/src/main/resources/application.yaml new file mode 100644 index 00000000000..8e2ebcde976 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/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-springfox/src/main/resources/openapi.yaml b/samples/server/petstore/kotlin-springboot-springfox/src/main/resources/openapi.yaml new file mode 100644 index 00000000000..847cd9d2767 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/resources/openapi.yaml @@ -0,0 +1,763 @@ +openapi: 3.0.1 +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 +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: + operationId: addPet + requestBody: + 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 + responses: + "405": + content: {} + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + x-codegen-request-body-name: body + put: + operationId: updatePet + requestBody: + 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 + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + "405": + content: {} + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + x-codegen-request-body-name: body + /pet/findByStatus: + get: + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - 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": + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - 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": + content: {} + description: Invalid tag value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Finds Pets by tags + tags: + - pet + /pet/{petId}: + delete: + operationId: deletePet + parameters: + - in: header + name: api_key + schema: + type: string + - description: Pet id to delete + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "400": + content: {} + 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 + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + tags: + - pet + post: + operationId: updatePetWithForm + parameters: + - description: ID of pet that needs to be updated + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + application/x-www-form-urlencoded: + schema: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + responses: + "405": + content: {} + 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: + operationId: uploadFile + parameters: + - description: ID of pet to update + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + multipart/form-data: + schema: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + 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: + operationId: placeOrder + requestBody: + content: + '*/*': + 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": + content: {} + description: Invalid Order + summary: Place an order for a pet + tags: + - store + x-codegen-request-body-name: body + /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 + in: path + name: orderId + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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 generated exceptions + operationId: getOrderById + parameters: + - description: ID of pet that needs to be fetched + in: path + name: orderId + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Create user + tags: + - user + x-codegen-request-body-name: body + /user/createWithArray: + post: + operationId: createUsersWithArrayInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + /user/createWithList: + post: + operationId: createUsersWithListInput + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + /user/login: + get: + operationId: loginUser + parameters: + - description: The user name for login + in: query + name: username + required: true + schema: + type: string + - description: The password for login in clear text + in: query + name: password + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + format: int32 + type: integer + X-Expires-After: + description: date in UTC when token expires + schema: + format: date-time + type: string + "400": + content: {} + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user + /user/logout: + get: + operationId: logoutUser + responses: + default: + content: {} + description: successful operation + 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 + in: path + name: username + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + description: User not found + summary: Delete user + tags: + - user + get: + operationId: getUserByName + parameters: + - description: The name that needs to be fetched. Use user1 for testing. + in: path + name: username + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + description: successful operation + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + 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 + in: path + name: username + required: true + schema: + type: string + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + responses: + "400": + content: {} + description: Invalid user supplied + "404": + content: {} + description: User not found + summary: Updated user + tags: + - user + x-codegen-request-body-name: body +components: + 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: + 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: + 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 + 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 +x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/resources/static/swagger-ui.html b/samples/server/petstore/kotlin-springboot-springfox/src/main/resources/static/swagger-ui.html new file mode 100644 index 00000000000..f85b6654f67 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/resources/static/swagger-ui.html @@ -0,0 +1,60 @@ + + + + + + Swagger UI + + + + + + + +
+ + + + + + diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/test/kotlin/org/openapitools/api/PetApiTest.kt b/samples/server/petstore/kotlin-springboot-springfox/src/test/kotlin/org/openapitools/api/PetApiTest.kt new file mode 100644 index 00000000000..6625bcb8d5c --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/test/kotlin/org/openapitools/api/PetApiTest.kt @@ -0,0 +1,129 @@ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class PetApiTest { + + private val service: PetApiService = PetApiServiceImpl() + private val api: PetApiController = PetApiController(service) + + /** + * To test PetApiController.addPet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun addPetTest() { + val body: Pet = TODO() + val response: ResponseEntity = api.addPet(body) + + // TODO: test validations + } + + /** + * To test PetApiController.deletePet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deletePetTest() { + val petId: kotlin.Long = TODO() + val apiKey: kotlin.String? = TODO() + val response: ResponseEntity = api.deletePet(petId, apiKey) + + // TODO: test validations + } + + /** + * To test PetApiController.findPetsByStatus + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun findPetsByStatusTest() { + val status: kotlin.collections.List = TODO() + val response: ResponseEntity> = api.findPetsByStatus(status) + + // TODO: test validations + } + + /** + * To test PetApiController.findPetsByTags + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun findPetsByTagsTest() { + val tags: kotlin.collections.List = TODO() + val response: ResponseEntity> = api.findPetsByTags(tags) + + // TODO: test validations + } + + /** + * To test PetApiController.getPetById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getPetByIdTest() { + val petId: kotlin.Long = TODO() + val response: ResponseEntity = api.getPetById(petId) + + // TODO: test validations + } + + /** + * To test PetApiController.updatePet + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updatePetTest() { + val body: Pet = TODO() + val response: ResponseEntity = api.updatePet(body) + + // TODO: test validations + } + + /** + * To test PetApiController.updatePetWithForm + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updatePetWithFormTest() { + val petId: kotlin.Long = TODO() + val name: kotlin.String? = TODO() + val status: kotlin.String? = TODO() + val response: ResponseEntity = api.updatePetWithForm(petId, name, status) + + // TODO: test validations + } + + /** + * To test PetApiController.uploadFile + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun uploadFileTest() { + val petId: kotlin.Long = TODO() + val additionalMetadata: kotlin.String? = TODO() + val file: org.springframework.core.io.Resource? = TODO() + val response: ResponseEntity = api.uploadFile(petId, additionalMetadata, file) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/test/kotlin/org/openapitools/api/StoreApiTest.kt b/samples/server/petstore/kotlin-springboot-springfox/src/test/kotlin/org/openapitools/api/StoreApiTest.kt new file mode 100644 index 00000000000..69e269b03ef --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/test/kotlin/org/openapitools/api/StoreApiTest.kt @@ -0,0 +1,66 @@ +package org.openapitools.api + +import org.openapitools.model.Order +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class StoreApiTest { + + private val service: StoreApiService = StoreApiServiceImpl() + private val api: StoreApiController = StoreApiController(service) + + /** + * To test StoreApiController.deleteOrder + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deleteOrderTest() { + val orderId: kotlin.String = TODO() + val response: ResponseEntity = api.deleteOrder(orderId) + + // TODO: test validations + } + + /** + * To test StoreApiController.getInventory + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getInventoryTest() { + val response: ResponseEntity> = api.getInventory() + + // TODO: test validations + } + + /** + * To test StoreApiController.getOrderById + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getOrderByIdTest() { + val orderId: kotlin.Long = TODO() + val response: ResponseEntity = api.getOrderById(orderId) + + // TODO: test validations + } + + /** + * To test StoreApiController.placeOrder + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun placeOrderTest() { + val body: Order = TODO() + val response: ResponseEntity = api.placeOrder(body) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/test/kotlin/org/openapitools/api/UserApiTest.kt b/samples/server/petstore/kotlin-springboot-springfox/src/test/kotlin/org/openapitools/api/UserApiTest.kt new file mode 100644 index 00000000000..eb20423da71 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-springfox/src/test/kotlin/org/openapitools/api/UserApiTest.kt @@ -0,0 +1,124 @@ +package org.openapitools.api + +import org.openapitools.model.User +import org.junit.jupiter.api.Test +import org.springframework.http.ResponseEntity + +class UserApiTest { + + private val service: UserApiService = UserApiServiceImpl() + private val api: UserApiController = UserApiController(service) + + /** + * To test UserApiController.createUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUserTest() { + val body: User = TODO() + val response: ResponseEntity = api.createUser(body) + + // TODO: test validations + } + + /** + * To test UserApiController.createUsersWithArrayInput + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUsersWithArrayInputTest() { + val body: kotlin.collections.List = TODO() + val response: ResponseEntity = api.createUsersWithArrayInput(body) + + // TODO: test validations + } + + /** + * To test UserApiController.createUsersWithListInput + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun createUsersWithListInputTest() { + val body: kotlin.collections.List = TODO() + val response: ResponseEntity = api.createUsersWithListInput(body) + + // TODO: test validations + } + + /** + * To test UserApiController.deleteUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun deleteUserTest() { + val username: kotlin.String = TODO() + val response: ResponseEntity = api.deleteUser(username) + + // TODO: test validations + } + + /** + * To test UserApiController.getUserByName + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun getUserByNameTest() { + val username: kotlin.String = TODO() + val response: ResponseEntity = api.getUserByName(username) + + // TODO: test validations + } + + /** + * To test UserApiController.loginUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun loginUserTest() { + val username: kotlin.String = TODO() + val password: kotlin.String = TODO() + val response: ResponseEntity = api.loginUser(username, password) + + // TODO: test validations + } + + /** + * To test UserApiController.logoutUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun logoutUserTest() { + val response: ResponseEntity = api.logoutUser() + + // TODO: test validations + } + + /** + * To test UserApiController.updateUser + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun updateUserTest() { + val username: kotlin.String = TODO() + val body: User = TODO() + val response: ResponseEntity = api.updateUser(username, body) + + // TODO: test validations + } +} diff --git a/samples/server/petstore/kotlin-springboot/build.gradle.kts b/samples/server/petstore/kotlin-springboot/build.gradle.kts index ea7f93398da..527863fa2de 100644 --- a/samples/server/petstore/kotlin-springboot/build.gradle.kts +++ b/samples/server/petstore/kotlin-springboot/build.gradle.kts @@ -30,14 +30,17 @@ plugins { } dependencies { - val kotlinxCoroutinesVersion="1.2.0" compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") compile("org.jetbrains.kotlin:kotlin-reflect") compile("org.springframework.boot:spring-boot-starter-web") - compile("io.swagger:swagger-annotations:1.5.21") + + compile("com.google.code.findbugs:jsr305:3.0.2") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") compile("com.fasterxml.jackson.module:jackson-module-kotlin") + compile("jakarta.validation:jakarta.validation-api") + compile("jakarta.annotation:jakarta.annotation-api:1.3.5") testCompile("org.jetbrains.kotlin:kotlin-test-junit5") testCompile("org.springframework.boot:spring-boot-starter-test") { diff --git a/samples/server/petstore/kotlin-springboot/pom.xml b/samples/server/petstore/kotlin-springboot/pom.xml index 4d5fc7828f6..ba30e7b432b 100644 --- a/samples/server/petstore/kotlin-springboot/pom.xml +++ b/samples/server/petstore/kotlin-springboot/pom.xml @@ -6,10 +6,12 @@ openapi-spring 1.0.0 - UTF-8 + 3.0.2 + 1.3.5 + 1.3.31 + 1.3.30 - 1.2.0 - 1.3.5 + UTF-8 org.springframework.boot @@ -83,16 +85,13 @@ spring-boot-starter-web
- - io.swagger - swagger-annotations - 1.5.21 - + + com.google.code.findbugs jsr305 - 3.0.2 + ${findbugs-jsr305.version} com.fasterxml.jackson.dataformat @@ -118,13 +117,13 @@ jakarta.annotation jakarta.annotation-api - ${jakarta-annotation-version} + ${jakarta-annotation.version} provided org.jetbrains.kotlin kotlin-test-junit5 - 1.3.31 + ${kotlin-test-junit5.version} test diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/Application.kt index f2ee49d476b..2fe6de62479 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/Application.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/Application.kt @@ -1,9 +1,8 @@ package org.openapitools import org.springframework.boot.runApplication -import org.springframework.context.annotation.ComponentScan import org.springframework.boot.autoconfigure.SpringBootApplication - +import org.springframework.context.annotation.ComponentScan @SpringBootApplication @ComponentScan(basePackages = ["org.openapitools", "org.openapitools.api", "org.openapitools.model"]) diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiController.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiController.kt index e9ad5c44589..91872a031f2 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiController.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiController.kt @@ -2,13 +2,6 @@ package org.openapitools.api import org.openapitools.model.ModelApiResponse import org.openapitools.model.Pet -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity @@ -33,154 +26,86 @@ import kotlin.collections.Map @RestController @Validated -@Api(value = "pet", description = "The pet API") @RequestMapping("\${api.base-path:/v2}") class PetApiController(@Autowired(required = true) val service: PetApiService) { - @ApiOperation( - value = "Add a new pet to the store", - nickname = "addPet", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + @RequestMapping( method = [RequestMethod.POST], value = ["/pet"], consumes = ["application/json", "application/xml"] ) - fun addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet -): ResponseEntity { + fun addPet( @Valid @RequestBody body: Pet): ResponseEntity { return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405)) } - @ApiOperation( - value = "Deletes a pet", - nickname = "deletePet", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid pet value")]) + @RequestMapping( method = [RequestMethod.DELETE], value = ["/pet/{petId}"] ) - fun deletePet(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: kotlin.String? -): ResponseEntity { + fun deletePet( @PathVariable("petId") petId: kotlin.Long, @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) } - @ApiOperation( - value = "Finds Pets by status", - nickname = "findPetsByStatus", - notes = "Multiple status values can be provided with comma separated strings", - response = Pet::class, - responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid status value")]) + @RequestMapping( method = [RequestMethod.GET], value = ["/pet/findByStatus"], produces = ["application/xml", "application/json"] ) - fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List -): ResponseEntity> { + fun findPetsByStatus(@NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Finds Pets by tags", - nickname = "findPetsByTags", - notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", - response = Pet::class, - responseContainer = "List", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid tag value")]) + @RequestMapping( method = [RequestMethod.GET], value = ["/pet/findByTags"], produces = ["application/xml", "application/json"] ) - fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List -): ResponseEntity> { + fun findPetsByTags(@NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Find pet by ID", - nickname = "getPetById", - notes = "Returns a single pet", - response = Pet::class, - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found")]) + @RequestMapping( method = [RequestMethod.GET], value = ["/pet/{petId}"], produces = ["application/xml", "application/json"] ) - fun getPetById(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: kotlin.Long -): ResponseEntity { + fun getPetById( @PathVariable("petId") petId: kotlin.Long): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Update an existing pet", - nickname = "updatePet", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found"),ApiResponse(code = 405, message = "Validation exception")]) + @RequestMapping( method = [RequestMethod.PUT], value = ["/pet"], consumes = ["application/json", "application/xml"] ) - fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet -): ResponseEntity { + fun updatePet( @Valid @RequestBody body: Pet): ResponseEntity { return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400)) } - @ApiOperation( - value = "Updates a pet in the store with form data", - nickname = "updatePetWithForm", - notes = "", - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 405, message = "Invalid input")]) + @RequestMapping( method = [RequestMethod.POST], value = ["/pet/{petId}"], consumes = ["application/x-www-form-urlencoded"] ) - fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "Updated name of the pet") @RequestParam(value="name", required=false) name: kotlin.String? -,@ApiParam(value = "Updated status of the pet") @RequestParam(value="status", required=false) status: kotlin.String? -): ResponseEntity { + fun updatePetWithForm( @PathVariable("petId") petId: kotlin.Long, @RequestParam(value = "name", required = false) name: kotlin.String? , @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) } - @ApiOperation( - value = "uploads an image", - nickname = "uploadFile", - notes = "", - response = ModelApiResponse::class, - authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) + @RequestMapping( method = [RequestMethod.POST], value = ["/pet/{petId}/uploadImage"], produces = ["application/json"], consumes = ["multipart/form-data"] ) - fun uploadFile(@ApiParam(value = "ID of pet to update", required=true) @PathVariable("petId") petId: kotlin.Long -,@ApiParam(value = "Additional data to pass to server") @RequestParam(value="additionalMetadata", required=false) additionalMetadata: kotlin.String? -,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource? -): ResponseEntity { + fun uploadFile( @PathVariable("petId") petId: kotlin.Long, @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? , @Valid @RequestPart("file") file: org.springframework.core.io.Resource?): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) } } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApiController.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApiController.kt index 31f54ce0246..6cbb8279976 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApiController.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApiController.kt @@ -1,13 +1,6 @@ package org.openapitools.api import org.openapitools.model.Order -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity @@ -32,34 +25,19 @@ import kotlin.collections.Map @RestController @Validated -@Api(value = "store", description = "The store API") @RequestMapping("\${api.base-path:/v2}") class StoreApiController(@Autowired(required = true) val service: StoreApiService) { - @ApiOperation( - value = "Delete purchase order by ID", - nickname = "deleteOrder", - notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors") - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @RequestMapping( method = [RequestMethod.DELETE], value = ["/store/order/{orderId}"] ) - fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required=true) @PathVariable("orderId") orderId: kotlin.String -): ResponseEntity { + fun deleteOrder( @PathVariable("orderId") orderId: kotlin.String): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400)) } - @ApiOperation( - value = "Returns pet inventories by status", - nickname = "getInventory", - notes = "Returns a map of status codes to quantities", - response = kotlin.Int::class, - responseContainer = "Map", - authorizations = [Authorization(value = "api_key")]) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")]) + @RequestMapping( method = [RequestMethod.GET], value = ["/store/inventory"], @@ -69,37 +47,23 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Find purchase order by ID", - nickname = "getOrderById", - notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", - response = Order::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) + @RequestMapping( method = [RequestMethod.GET], value = ["/store/order/{orderId}"], produces = ["application/xml", "application/json"] ) - fun getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required=true) @PathVariable("orderId") orderId: kotlin.Long -): ResponseEntity { + fun getOrderById(@Min(1L) @Max(5L) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Place an order for a pet", - nickname = "placeOrder", - notes = "", - response = Order::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")]) + @RequestMapping( method = [RequestMethod.POST], value = ["/store/order"], produces = ["application/xml", "application/json"] ) - fun placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody body: Order -): ResponseEntity { + fun placeOrder( @Valid @RequestBody body: Order): ResponseEntity { return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200)) } } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApiController.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApiController.kt index 92050c6e481..daf5c943c2e 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApiController.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApiController.kt @@ -1,13 +1,6 @@ package org.openapitools.api import org.openapitools.model.User -import io.swagger.annotations.Api -import io.swagger.annotations.ApiOperation -import io.swagger.annotations.ApiParam -import io.swagger.annotations.ApiResponse -import io.swagger.annotations.ApiResponses -import io.swagger.annotations.Authorization -import io.swagger.annotations.AuthorizationScope import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity @@ -32,111 +25,66 @@ import kotlin.collections.Map @RestController @Validated -@Api(value = "user", description = "The user API") @RequestMapping("\${api.base-path:/v2}") class UserApiController(@Autowired(required = true) val service: UserApiService) { - @ApiOperation( - value = "Create user", - nickname = "createUser", - notes = "This can only be done by the logged in user.") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( method = [RequestMethod.POST], value = ["/user"] ) - fun createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody body: User -): ResponseEntity { + fun createUser( @Valid @RequestBody body: User): ResponseEntity { return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Creates list of users with given input array", - nickname = "createUsersWithArrayInput", - notes = "") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( method = [RequestMethod.POST], value = ["/user/createWithArray"] ) - fun createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: kotlin.collections.List -): ResponseEntity { + fun createUsersWithArrayInput( @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Creates list of users with given input array", - nickname = "createUsersWithListInput", - notes = "") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( method = [RequestMethod.POST], value = ["/user/createWithList"] ) - fun createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: kotlin.collections.List -): ResponseEntity { + fun createUsersWithListInput( @Valid @RequestBody body: kotlin.collections.List): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Delete user", - nickname = "deleteUser", - notes = "This can only be done by the logged in user.") - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @RequestMapping( method = [RequestMethod.DELETE], value = ["/user/{username}"] ) - fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true) @PathVariable("username") username: kotlin.String -): ResponseEntity { + fun deleteUser( @PathVariable("username") username: kotlin.String): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400)) } - @ApiOperation( - value = "Get user by user name", - nickname = "getUserByName", - notes = "", - response = User::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = User::class),ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) + @RequestMapping( method = [RequestMethod.GET], value = ["/user/{username}"], produces = ["application/xml", "application/json"] ) - fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required=true) @PathVariable("username") username: kotlin.String -): ResponseEntity { + fun getUserByName( @PathVariable("username") username: kotlin.String): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Logs user into the system", - nickname = "loginUser", - notes = "", - response = kotlin.String::class) - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")]) + @RequestMapping( method = [RequestMethod.GET], value = ["/user/login"], produces = ["application/xml", "application/json"] ) - fun loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String -,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String -): ResponseEntity { + fun loginUser(@NotNull @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Logs out current logged in user session", - nickname = "logoutUser", - notes = "") - @ApiResponses( - value = [ApiResponse(code = 200, message = "successful operation")]) + @RequestMapping( method = [RequestMethod.GET], value = ["/user/logout"] @@ -145,19 +93,12 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200)) } - @ApiOperation( - value = "Updated user", - nickname = "updateUser", - notes = "This can only be done by the logged in user.") - @ApiResponses( - value = [ApiResponse(code = 400, message = "Invalid user supplied"),ApiResponse(code = 404, message = "User not found")]) + @RequestMapping( method = [RequestMethod.PUT], value = ["/user/{username}"] ) - fun updateUser(@ApiParam(value = "name that need to be deleted", required=true) @PathVariable("username") username: kotlin.String -,@ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody body: User -): ResponseEntity { + fun updateUser( @PathVariable("username") username: kotlin.String, @Valid @RequestBody body: User): ResponseEntity { return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400)) } } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Category.kt index 66d8d45d466..1ed259de7f4 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Category.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Category.kt @@ -11,7 +11,6 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty /** * A category for a pet @@ -20,10 +19,8 @@ import io.swagger.annotations.ApiModelProperty */ data class Category( - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("name") val name: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt index 6b3e10c5694..a0d27987071 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt @@ -11,7 +11,6 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty /** * Describes the result of uploading an image resource @@ -21,13 +20,10 @@ import io.swagger.annotations.ApiModelProperty */ data class ModelApiResponse( - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("code") val code: kotlin.Int? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("type") val type: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("message") val message: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt index c81e062d3f9..6f0fe53d072 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt @@ -12,7 +12,6 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty /** * An order for a pets from the pet store @@ -25,22 +24,16 @@ import io.swagger.annotations.ApiModelProperty */ data class Order( - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("petId") val petId: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("quantity") val quantity: kotlin.Int? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, - @ApiModelProperty(example = "null", value = "Order Status") @field:JsonProperty("status") val status: Order.Status? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("complete") val complete: kotlin.Boolean? = false ) { @@ -49,13 +42,10 @@ data class Order( * Values: placed,approved,delivered */ enum class Status(val value: kotlin.String) { - + @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - - @JsonProperty("delivered") delivered("delivered"); - + @JsonProperty("delivered") delivered("delivered") } } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Pet.kt index 42394bc5a10..db781b4eba1 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Pet.kt @@ -14,7 +14,6 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty /** * A pet for sale in the pet store @@ -27,24 +26,18 @@ import io.swagger.annotations.ApiModelProperty */ data class Pet( - @ApiModelProperty(example = "doggie", required = true, value = "") @field:JsonProperty("name", required = true) val name: kotlin.String, - @ApiModelProperty(example = "null", required = true, value = "") @field:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("id") val id: kotlin.Long? = null, @field:Valid - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("category") val category: Category? = null, @field:Valid - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("tags") val tags: kotlin.collections.List? = null, - @ApiModelProperty(example = "null", value = "pet status in the store") @field:JsonProperty("status") val status: Pet.Status? = null ) { @@ -53,13 +46,10 @@ data class Pet( * Values: available,pending,sold */ enum class Status(val value: kotlin.String) { - + @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - - @JsonProperty("sold") sold("sold"); - + @JsonProperty("sold") sold("sold") } } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Tag.kt index 1d540aa1677..412f02034f0 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Tag.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Tag.kt @@ -11,7 +11,6 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty /** * A tag for a pet @@ -20,10 +19,8 @@ import io.swagger.annotations.ApiModelProperty */ data class Tag( - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("name") val name: kotlin.String? = null ) { diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/User.kt index 87e20405d96..dcdcc4a285e 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/User.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/User.kt @@ -11,7 +11,6 @@ import javax.validation.constraints.NotNull import javax.validation.constraints.Pattern import javax.validation.constraints.Size import javax.validation.Valid -import io.swagger.annotations.ApiModelProperty /** * A User who is purchasing from the pet store @@ -26,28 +25,20 @@ import io.swagger.annotations.ApiModelProperty */ data class User( - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("id") val id: kotlin.Long? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("username") val username: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("firstName") val firstName: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("lastName") val lastName: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("email") val email: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("password") val password: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "") @field:JsonProperty("phone") val phone: kotlin.String? = null, - @ApiModelProperty(example = "null", value = "User Status") @field:JsonProperty("userStatus") val userStatus: kotlin.Int? = null ) { diff --git a/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/PetApiTest.kt b/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/PetApiTest.kt index 0d3ccd3989f..6625bcb8d5c 100644 --- a/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/PetApiTest.kt +++ b/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/PetApiTest.kt @@ -18,7 +18,7 @@ class PetApiTest { */ @Test fun addPetTest() { - val body:Pet = TODO() + val body: Pet = TODO() val response: ResponseEntity = api.addPet(body) // TODO: test validations @@ -32,8 +32,8 @@ class PetApiTest { */ @Test fun deletePetTest() { - val petId:kotlin.Long = TODO() - val apiKey:kotlin.String? = TODO() + val petId: kotlin.Long = TODO() + val apiKey: kotlin.String? = TODO() val response: ResponseEntity = api.deletePet(petId, apiKey) // TODO: test validations @@ -47,7 +47,7 @@ class PetApiTest { */ @Test fun findPetsByStatusTest() { - val status:kotlin.collections.List = TODO() + val status: kotlin.collections.List = TODO() val response: ResponseEntity> = api.findPetsByStatus(status) // TODO: test validations @@ -61,7 +61,7 @@ class PetApiTest { */ @Test fun findPetsByTagsTest() { - val tags:kotlin.collections.List = TODO() + val tags: kotlin.collections.List = TODO() val response: ResponseEntity> = api.findPetsByTags(tags) // TODO: test validations @@ -75,7 +75,7 @@ class PetApiTest { */ @Test fun getPetByIdTest() { - val petId:kotlin.Long = TODO() + val petId: kotlin.Long = TODO() val response: ResponseEntity = api.getPetById(petId) // TODO: test validations @@ -89,7 +89,7 @@ class PetApiTest { */ @Test fun updatePetTest() { - val body:Pet = TODO() + val body: Pet = TODO() val response: ResponseEntity = api.updatePet(body) // TODO: test validations @@ -103,9 +103,9 @@ class PetApiTest { */ @Test fun updatePetWithFormTest() { - val petId:kotlin.Long = TODO() - val name:kotlin.String? = TODO() - val status:kotlin.String? = TODO() + 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 @@ -119,12 +119,11 @@ class PetApiTest { */ @Test fun uploadFileTest() { - val petId:kotlin.Long = TODO() - val additionalMetadata:kotlin.String? = TODO() - val file:org.springframework.core.io.Resource? = TODO() + val petId: kotlin.Long = TODO() + val additionalMetadata: kotlin.String? = TODO() + val file: org.springframework.core.io.Resource? = TODO() val response: ResponseEntity = api.uploadFile(petId, additionalMetadata, file) // TODO: test validations } - } diff --git a/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/StoreApiTest.kt b/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/StoreApiTest.kt index fcb00e99e99..69e269b03ef 100644 --- a/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/StoreApiTest.kt +++ b/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/StoreApiTest.kt @@ -17,7 +17,7 @@ class StoreApiTest { */ @Test fun deleteOrderTest() { - val orderId:kotlin.String = TODO() + val orderId: kotlin.String = TODO() val response: ResponseEntity = api.deleteOrder(orderId) // TODO: test validations @@ -44,7 +44,7 @@ class StoreApiTest { */ @Test fun getOrderByIdTest() { - val orderId:kotlin.Long = TODO() + val orderId: kotlin.Long = TODO() val response: ResponseEntity = api.getOrderById(orderId) // TODO: test validations @@ -58,10 +58,9 @@ class StoreApiTest { */ @Test fun placeOrderTest() { - val body:Order = TODO() + val body: Order = TODO() val response: ResponseEntity = api.placeOrder(body) // TODO: test validations } - } diff --git a/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/UserApiTest.kt b/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/UserApiTest.kt index c3f07290cfe..eb20423da71 100644 --- a/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/UserApiTest.kt +++ b/samples/server/petstore/kotlin-springboot/src/test/kotlin/org/openapitools/api/UserApiTest.kt @@ -17,7 +17,7 @@ class UserApiTest { */ @Test fun createUserTest() { - val body:User = TODO() + val body: User = TODO() val response: ResponseEntity = api.createUser(body) // TODO: test validations @@ -31,7 +31,7 @@ class UserApiTest { */ @Test fun createUsersWithArrayInputTest() { - val body:kotlin.collections.List = TODO() + val body: kotlin.collections.List = TODO() val response: ResponseEntity = api.createUsersWithArrayInput(body) // TODO: test validations @@ -45,7 +45,7 @@ class UserApiTest { */ @Test fun createUsersWithListInputTest() { - val body:kotlin.collections.List = TODO() + val body: kotlin.collections.List = TODO() val response: ResponseEntity = api.createUsersWithListInput(body) // TODO: test validations @@ -59,7 +59,7 @@ class UserApiTest { */ @Test fun deleteUserTest() { - val username:kotlin.String = TODO() + val username: kotlin.String = TODO() val response: ResponseEntity = api.deleteUser(username) // TODO: test validations @@ -73,7 +73,7 @@ class UserApiTest { */ @Test fun getUserByNameTest() { - val username:kotlin.String = TODO() + val username: kotlin.String = TODO() val response: ResponseEntity = api.getUserByName(username) // TODO: test validations @@ -87,8 +87,8 @@ class UserApiTest { */ @Test fun loginUserTest() { - val username:kotlin.String = TODO() - val password:kotlin.String = TODO() + val username: kotlin.String = TODO() + val password: kotlin.String = TODO() val response: ResponseEntity = api.loginUser(username, password) // TODO: test validations @@ -115,11 +115,10 @@ class UserApiTest { */ @Test fun updateUserTest() { - val username:kotlin.String = TODO() - val body:User = TODO() + val username: kotlin.String = TODO() + val body: User = TODO() val response: ResponseEntity = api.updateUser(username, body) // TODO: test validations } - }