diff --git a/bin/configs/kotlin-spring-sealed-interfaces.yaml b/bin/configs/kotlin-spring-sealed-interfaces.yaml new file mode 100644 index 000000000000..c8d7123f65fb --- /dev/null +++ b/bin/configs/kotlin-spring-sealed-interfaces.yaml @@ -0,0 +1,11 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-spring-sealed-interfaces +inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + useSealedResponseInterfaces: true + interfaceOnly: true + dateLibrary: java8 + useSpringBoot3: true + reactive: false + documentationProvider: none diff --git a/docs/generators/kotlin-spring.md b/docs/generators/kotlin-spring.md index e03dfd102929..a169cb0b7e83 100644 --- a/docs/generators/kotlin-spring.md +++ b/docs/generators/kotlin-spring.md @@ -59,6 +59,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useFeignClientUrl|Whether to generate Feign client with url parameter.| |true| |useFlowForArrayReturnType|Whether to use Flow for array/collection return types when reactive is enabled. If false, will use List instead.| |true| |useResponseEntity|Whether (when false) to return actual type (e.g. List<Fruit>) and handle non-happy path responses via exceptions flow or (when true) return entire ResponseEntity (e.g. ResponseEntity<List<Fruit>>). If disabled, method are annotated using a @ResponseStatus annotation, which has the status of the first response declared in the Api definition| |true| +|useSealedResponseInterfaces|Generate sealed interfaces for endpoint responses that all possible response types implement. Allows controllers to return any valid response type in a type-safe manner (e.g., sealed interface CreateUserResponse implemented by User, ConflictResponse, ErrorResponse)| |false| |useSpringBoot3|Generate code and provide dependencies for use with Spring Boot ≥ 3 (use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |false| |useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true| |useTags|Whether to use tags for creating interface and controller class names| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java index 55abde3ad6c5..1640062d607b 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 @@ -97,6 +97,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen public static final String USE_REQUEST_MAPPING_ON_CONTROLLER = "useRequestMappingOnController"; public static final String USE_REQUEST_MAPPING_ON_INTERFACE = "useRequestMappingOnInterface"; public static final String AUTO_X_SPRING_PAGINATED = "autoXSpringPaginated"; + public static final String USE_SEALED_RESPONSE_INTERFACES = "useSealedResponseInterfaces"; @Getter public enum DeclarativeInterfaceReactiveMode { @@ -161,6 +162,7 @@ public String getDescription() { @Setter private DeclarativeInterfaceReactiveMode declarativeInterfaceReactiveMode = DeclarativeInterfaceReactiveMode.coroutines; @Setter private boolean useResponseEntity = true; @Setter private boolean autoXSpringPaginated = false; + @Setter private boolean useSealedResponseInterfaces = false; @Getter @Setter protected boolean useSpringBoot3 = false; @@ -168,6 +170,11 @@ public String getDescription() { private DocumentationProvider documentationProvider; private AnnotationLibrary annotationLibrary; + // Map to track which models implement which sealed response interfaces + private Map> modelToSealedInterfaces = new HashMap<>(); + private Map sealedInterfaceToOperationId = new HashMap<>(); + private boolean sealedInterfacesFileWritten = false; + public KotlinSpringServerCodegen() { super(); @@ -250,6 +257,9 @@ public KotlinSpringServerCodegen() { addSwitch(USE_RESPONSE_ENTITY, "Whether (when false) to return actual type (e.g. List) and handle non-happy path responses via exceptions flow or (when true) return entire ResponseEntity (e.g. ResponseEntity>). If disabled, method are annotated using a @ResponseStatus annotation, which has the status of the first response declared in the Api definition", useResponseEntity); + addSwitch(USE_SEALED_RESPONSE_INTERFACES, + "Generate sealed interfaces for endpoint responses that all possible response types implement. Allows controllers to return any valid response type in a type-safe manner (e.g., sealed interface CreateUserResponse implemented by User, ConflictResponse, ErrorResponse)", + useSealedResponseInterfaces); addOption(X_KOTLIN_IMPLEMENTS_SKIP, "A list of fully qualified interfaces that should NOT be implemented despite their presence in vendor extension `x-kotlin-implements`. Example: yaml `xKotlinImplementsSkip: [com.some.pack.WithPhotoUrls]` skips implementing the interface in any schema", "empty list"); addOption(X_KOTLIN_IMPLEMENTS_FIELDS_SKIP, "A list of fields per schema name that should NOT be created with `override` keyword despite their presence in vendor extension `x-kotlin-implements-fields` for the schema. Example: yaml `xKotlinImplementsFieldsSkip: Pet: [photoUrls]` skips `override` for `photoUrls` in schema `Pet`", "empty map"); addOption(SCHEMA_IMPLEMENTS, "A map of single interface or a list of interfaces per schema name that should be implemented (serves similar purpose as `x-kotlin-implements`, but is fully decoupled from the api spec). Example: yaml `schemaImplements: {Pet: com.some.pack.WithId, Category: [com.some.pack.CategoryInterface], Dog: [com.some.pack.Canine, com.some.pack.OtherInterface]}` implements interfaces in schemas `Pet` (interface `com.some.pack.WithId`), `Category` (interface `com.some.pack.CategoryInterface`), `Dog`(interfaces `com.some.pack.Canine`, `com.some.pack.OtherInterface`)", "empty map"); @@ -496,6 +506,12 @@ public void processOpts() { this.setUseResponseEntity(Boolean.parseBoolean(additionalProperties.get(USE_RESPONSE_ENTITY).toString())); } writePropertyBack(USE_RESPONSE_ENTITY, useResponseEntity); + + if(additionalProperties.containsKey(USE_SEALED_RESPONSE_INTERFACES)) { + this.setUseSealedResponseInterfaces(Boolean.parseBoolean(additionalProperties.get(USE_SEALED_RESPONSE_INTERFACES).toString())); + } + writePropertyBack(USE_SEALED_RESPONSE_INTERFACES, useSealedResponseInterfaces); + additionalProperties.put("springHttpStatus", new SpringHttpStatusLambda()); // Set basePackage from invokerPackage @@ -1024,6 +1040,34 @@ public void preprocessOpenAPI(OpenAPI openAPI) { this.additionalProperties.put(SERVER_PORT, URLPathUtils.getPort(url, 8080)); } + // Build modelToSealedInterfaces map early, before models are processed + // Note: We check additionalProperties here because processOpts() hasn't been called yet + boolean shouldUseSealedInterfaces = additionalProperties.containsKey(USE_SEALED_RESPONSE_INTERFACES) + && Boolean.parseBoolean(additionalProperties.get(USE_SEALED_RESPONSE_INTERFACES).toString()); + if (shouldUseSealedInterfaces && openAPI.getPaths() != null) { + openAPI.getPaths().forEach((pathName, pathItem) -> { + pathItem.readOperations().forEach(operation -> { + if (operation.getOperationId() != null && operation.getResponses() != null) { + String sealedInterfaceName = camelize(operation.getOperationId()) + "Response"; + sealedInterfaceToOperationId.put(sealedInterfaceName, operation.getOperationId()); + + operation.getResponses().forEach((statusCode, response) -> { + if (response.getContent() != null) { + response.getContent().forEach((mediaType, content) -> { + if (content.getSchema() != null && content.getSchema().get$ref() != null) { + String ref = content.getSchema().get$ref(); + String modelName = ModelUtils.getSimpleRef(ref); + modelToSealedInterfaces.computeIfAbsent(modelName, k -> new ArrayList<>()) + .add(sealedInterfaceName); + } + }); + } + }); + } + }); + }); + } + // TODO: Handle tags } @@ -1079,6 +1123,53 @@ public ModelsMap postProcessModelsEnum(ModelsMap objs) { imports.add(itemJsonProperty); }); + // Add sealed interface implementations to models if enabled + // Note: We check additionalProperties here because processOpts() may not have been called yet + boolean shouldUseSealedInterfaces = additionalProperties.containsKey(USE_SEALED_RESPONSE_INTERFACES) + && Boolean.parseBoolean(additionalProperties.get(USE_SEALED_RESPONSE_INTERFACES).toString()); + if (shouldUseSealedInterfaces) { + objs.getModels().stream() + .map(ModelMap::getModel) + .forEach(cm -> { + String modelName = cm.classname; + if (modelToSealedInterfaces.containsKey(modelName)) { + List sealedInterfaces = modelToSealedInterfaces.get(modelName); + cm.vendorExtensions.put("x-implements-sealed-interfaces", sealedInterfaces); + + // Add imports for each sealed interface + for (String sealedInterface : sealedInterfaces) { + String importStatement = modelPackage + "." + sealedInterface; + cm.imports.add(sealedInterface); + Map item = new HashMap<>(); + item.put("import", importStatement); + imports.add(item); + } + } + }); + + // Write sealed interfaces file once + if (!sealedInterfacesFileWritten && !sealedInterfaceToOperationId.isEmpty()) { + List> sealedInterfacesList = new ArrayList<>(); + sealedInterfaceToOperationId.forEach((sealedInterfaceName, operationId) -> { + Map sealedInterface = new HashMap<>(); + sealedInterface.put("name", sealedInterfaceName); + sealedInterface.put("operationId", operationId); + sealedInterfacesList.add(sealedInterface); + }); + + Map sealedInterfacesData = new HashMap<>(); + sealedInterfacesData.put("package", modelPackage); + sealedInterfacesData.put("sealedInterfaces", sealedInterfacesList); + + additionalProperties.put("sealedInterfacesData", sealedInterfacesData); + supportingFiles.add(new SupportingFile("sealedResponseInterfaces.mustache", + (sourceFolder + File.separator + modelPackage).replace(".", File.separator), + "SealedResponseInterfaces.kt")); + + sealedInterfacesFileWritten = true; + } + } + return objs; } @@ -1147,10 +1238,54 @@ public void setReturnContainer(final String returnContainer) { operation.returnContainer = returnContainer; } }); + + // Generate sealed response interface metadata if enabled + if (useSealedResponseInterfaces && responses != null && !responses.isEmpty()) { + // Generate sealed interface name from operation ID + String sealedInterfaceName = camelize(operation.operationId) + "Response"; + operation.vendorExtensions.put("x-sealed-response-interface", sealedInterfaceName); + + // Collect all unique response base types (models) + List responseTypes = responses.stream() + .map(r -> r.baseType) + .filter(baseType -> baseType != null && !baseType.isEmpty()) + .distinct() + .collect(Collectors.toList()); + + operation.vendorExtensions.put("x-sealed-response-types", responseTypes); + + // Track which models should implement this sealed interface + for (String responseType : responseTypes) { + modelToSealedInterfaces.computeIfAbsent(responseType, k -> new ArrayList<>()) + .add(sealedInterfaceName); + } + } + // if(implicitHeaders){ // removeHeadersFromAllParams(operation.allParams); // } }); + + // Add imports for sealed interfaces if feature is enabled + if (useSealedResponseInterfaces) { + Set sealedInterfacesToImport = new HashSet<>(); + ops.forEach(operation -> { + if (operation.vendorExtensions.containsKey("x-sealed-response-interface")) { + String sealedInterfaceName = (String) operation.vendorExtensions.get("x-sealed-response-interface"); + operation.imports.add(sealedInterfaceName); + sealedInterfacesToImport.add(sealedInterfaceName); + } + }); + + // Add import statements to the operations imports map + List> imports = objs.getImports(); + for (String sealedInterfaceName : sealedInterfacesToImport) { + String importStatement = modelPackage + "." + sealedInterfaceName; + Map item = new HashMap<>(); + item.put("import", importStatement); + imports.add(item); + } + } } return objs; @@ -1159,6 +1294,12 @@ public void setReturnContainer(final String returnContainer) { @Override public Map postProcessSupportingFileData(Map objs) { generateYAMLSpecFile(objs); + + // Add sealed interfaces data if available + if (additionalProperties.containsKey("sealedInterfacesData")) { + objs.putAll((Map) additionalProperties.get("sealedInterfacesData")); + } + return objs; } 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 3b130aadbc58..a9807edb0ae0 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache @@ -116,7 +116,7 @@ interface {{classname}} { {{/hasParams}}{{#swagger1AnnotationLibrary}}@ApiParam(hidden = true) {{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true) {{/swagger2AnnotationLibrary}}{{#reactive}}exchange: org.springframework.web.server.ServerWebExchange{{/reactive}}{{^reactive}}request: {{javaxPackage}}.servlet.http.HttpServletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{/hasParams}}{{#swagger1AnnotationLibrary}}@ApiParam(hidden = true) {{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true) {{/swagger2AnnotationLibrary}}pageable: Pageable{{/vendorExtensions.x-spring-paginated}}{{#hasParams}} - {{/hasParams}}): {{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{>returnTypes}}{{#useResponseEntity}}>{{/useResponseEntity}}{{^skipDefaultApiInterface}} { + {{/hasParams}}): {{#useResponseEntity}}ResponseEntity<{{/useResponseEntity}}{{#useSealedResponseInterfaces}}{{#vendorExtensions.x-sealed-response-interface}}{{vendorExtensions.x-sealed-response-interface}}{{/vendorExtensions.x-sealed-response-interface}}{{/useSealedResponseInterfaces}}{{^useSealedResponseInterfaces}}{{>returnTypes}}{{/useSealedResponseInterfaces}}{{#useResponseEntity}}>{{/useResponseEntity}}{{^skipDefaultApiInterface}} { {{^isDelegate}} return {{>returnValue}} {{/isDelegate}} 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 43a446bdfed4..4fadc4b89ccb 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache @@ -20,12 +20,17 @@ ){{/discriminator}}{{! no newline }}{{#parent}} : {{{.}}}{{#isMap}}(){{/isMap}}{{! no newline }}{{#vendorExtensions.x-kotlin-implements}}, {{{.}}}{{/vendorExtensions.x-kotlin-implements}}{{! <- serializableModel is also handled via x-kotlin-implements + }}{{#vendorExtensions.x-implements-sealed-interfaces}}{{#.}}, {{{.}}}{{/.}}{{/vendorExtensions.x-implements-sealed-interfaces}}{{! <- add sealed interface implementations }}{{/parent}}{{! no newline }}{{^parent}}{{! no newline }}{{#vendorExtensions.x-kotlin-implements}}{{! no newline }}{{#-first}} : {{{.}}}{{/-first}}{{! no newline }}{{^-first}}, {{{.}}}{{/-first}}{{! no newline }}{{/vendorExtensions.x-kotlin-implements}}{{! no newline + }}{{#vendorExtensions.x-implements-sealed-interfaces}}{{! no newline + }}{{#-first}}{{^vendorExtensions.x-kotlin-implements}} : {{{.}}}{{/vendorExtensions.x-kotlin-implements}}{{#vendorExtensions.x-kotlin-implements}}, {{{.}}}{{/vendorExtensions.x-kotlin-implements}}{{/-first}}{{! no newline + }}{{^-first}}, {{{.}}}{{/-first}}{{! no newline + }}{{/vendorExtensions.x-implements-sealed-interfaces}}{{! no newline }}{{/parent}} { {{#discriminator}} {{#requiredVars}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/sealedResponseInterfaces.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/sealedResponseInterfaces.mustache new file mode 100644 index 000000000000..e857be89e63d --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/sealedResponseInterfaces.mustache @@ -0,0 +1,9 @@ +package {{package}} + +{{#sealedInterfaces}} +/** + * Sealed interface for all possible responses from {{operationId}} + */ +sealed interface {{name}} + +{{/sealedInterfaces}} 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 353c5141c910..1fb322883ac0 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 @@ -4462,6 +4462,102 @@ public void autoXSpringPaginatedNoParamsDoesNotDetect() throws Exception { Assert.assertFalse(methodSignature.contains("pageable: Pageable"), "findPetsNoParams should NOT have pageable when there are no pagination params"); } + + @Test + public void testSealedResponseInterfaces() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + String outputPath = output.getAbsolutePath().replace('\\', '/'); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/kotlin/sealed-response-interfaces.yaml", null, new ParseOptions()).getOpenAPI(); + + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "org.openapitools.model"); + codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "org.openapitools.api"); + codegen.additionalProperties().put(USE_SEALED_RESPONSE_INTERFACES, "true"); + codegen.additionalProperties().put(INTERFACE_ONLY, "true"); + + ClientOptInput input = new ClientOptInput(); + input.openAPI(openAPI); + input.config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + generator.opts(input).generate(); + + // Verify sealed interfaces are declared in the model package + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/SealedResponseInterfaces.kt"), + "sealed interface CreateUserResponse", + "sealed interface GetUserResponse"); + + // Verify API file imports the sealed interfaces + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/UsersApi.kt"), + "import org.openapitools.model.CreateUserResponse", + "import org.openapitools.model.GetUserResponse"); + + // Verify API methods use sealed interfaces as return types + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/UsersApi.kt"), + "fun createUser(", + "): ResponseEntity", + "fun getUser(", + "): ResponseEntity"); + + // Verify User model implements both sealed interfaces + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/User.kt"), + "data class User(", + ": CreateUserResponse, GetUserResponse"); + + // Verify ConflictResponse implements CreateUserResponse + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/ConflictResponse.kt"), + "data class ConflictResponse(", + ": CreateUserResponse"); + + // Verify ErrorResponse implements both sealed interfaces + assertFileContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/ErrorResponse.kt"), + "data class ErrorResponse(", + ": CreateUserResponse, GetUserResponse"); + } + + @Test + public void testSealedResponseInterfacesDisabled() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + String outputPath = output.getAbsolutePath().replace('\\', '/'); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/kotlin/sealed-response-interfaces.yaml", null, new ParseOptions()).getOpenAPI(); + + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "org.openapitools.model"); + codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "org.openapitools.api"); + codegen.additionalProperties().put(USE_SEALED_RESPONSE_INTERFACES, "false"); + codegen.additionalProperties().put(INTERFACE_ONLY, "true"); + + ClientOptInput input = new ClientOptInput(); + input.openAPI(openAPI); + input.config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + generator.opts(input).generate(); + + // Verify sealed interfaces file is NOT generated when feature is disabled + File sealedInterfacesFile = new File(outputPath + "/src/main/kotlin/org/openapitools/model/SealedResponseInterfaces.kt"); + Assert.assertFalse(sealedInterfacesFile.exists(), "SealedResponseInterfaces.kt should not exist when feature is disabled"); + + // Verify models do NOT implement sealed interfaces when disabled + assertFileNotContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/User.kt"), + ": CreateUserResponse", + ": GetUserResponse"); + + assertFileNotContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/ConflictResponse.kt"), + ": CreateUserResponse"); + + assertFileNotContains(Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/ErrorResponse.kt"), + ": CreateUserResponse", + ": GetUserResponse"); + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/kotlin/sealed-response-interfaces.yaml b/modules/openapi-generator/src/test/resources/3_0/kotlin/sealed-response-interfaces.yaml new file mode 100644 index 000000000000..b69081609086 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/kotlin/sealed-response-interfaces.yaml @@ -0,0 +1,100 @@ +openapi: 3.0.3 +info: + title: Sealed Response Interfaces Test API + version: 1.0.0 +paths: + /users: + post: + operationId: createUser + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/CreateUserRequest' + responses: + '200': + description: User created successfully + content: + application/json: + schema: + $ref: '#/components/schemas/User' + '409': + description: Conflict - User already exists + content: + application/json: + schema: + $ref: '#/components/schemas/ConflictResponse' + '400': + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' + /users/{userId}: + get: + operationId: getUser + parameters: + - name: userId + in: path + required: true + schema: + type: string + responses: + '200': + description: User found + content: + application/json: + schema: + $ref: '#/components/schemas/User' + '404': + description: User not found + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' +components: + schemas: + User: + type: object + required: + - id + - email + properties: + id: + type: string + email: + type: string + format: email + name: + type: string + CreateUserRequest: + type: object + required: + - email + properties: + email: + type: string + format: email + name: + type: string + ConflictResponse: + type: object + required: + - reason + - message + properties: + reason: + type: string + message: + type: string + ErrorResponse: + type: object + required: + - code + - message + properties: + code: + type: string + message: + type: string diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/.openapi-generator-ignore b/samples/server/petstore/kotlin-spring-sealed-interfaces/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/.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-spring-sealed-interfaces/.openapi-generator/FILES b/samples/server/petstore/kotlin-spring-sealed-interfaces/.openapi-generator/FILES new file mode 100644 index 000000000000..69f10dea4315 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/.openapi-generator/FILES @@ -0,0 +1,20 @@ +.openapi-generator-ignore +README.md +build.gradle.kts +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +pom.xml +settings.gradle +src/main/kotlin/org/openapitools/api/ApiUtil.kt +src/main/kotlin/org/openapitools/api/PetApi.kt +src/main/kotlin/org/openapitools/api/StoreApi.kt +src/main/kotlin/org/openapitools/api/UserApi.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/SealedResponseInterfaces.kt +src/main/kotlin/org/openapitools/model/Tag.kt +src/main/kotlin/org/openapitools/model/User.kt diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/.openapi-generator/VERSION b/samples/server/petstore/kotlin-spring-sealed-interfaces/.openapi-generator/VERSION new file mode 100644 index 000000000000..0610c66bc14f --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.21.0-SNAPSHOT diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/README.md b/samples/server/petstore/kotlin-spring-sealed-interfaces/README.md new file mode 100644 index 000000000000..b6865a081135 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/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-spring-sealed-interfaces/build.gradle.kts b/samples/server/petstore/kotlin-spring-sealed-interfaces/build.gradle.kts new file mode 100644 index 000000000000..559b1f327bec --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/build.gradle.kts @@ -0,0 +1,47 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +group = "org.openapitools" +version = "1.0.0" +java.sourceCompatibility = JavaVersion.VERSION_17 + +repositories { + mavenCentral() + maven { url = uri("https://repo.spring.io/milestone") } +} + +tasks.withType { + kotlinOptions.jvmTarget = "17" +} + +tasks.bootJar { + enabled = false +} + +plugins { + val kotlinVersion = "1.9.25" + id("org.jetbrains.kotlin.jvm") version kotlinVersion + id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion + id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion + id("org.springframework.boot") version "3.0.2" + id("io.spring.dependency-management") version "1.0.14.RELEASE" +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.springframework.boot:spring-boot-starter-web") + + implementation("com.google.code.findbugs:jsr305:3.0.2") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + implementation("org.springframework.data:spring-data-commons") + implementation("jakarta.validation:jakarta.validation-api") + implementation("jakarta.annotation:jakarta.annotation-api:2.1.0") + + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") + testImplementation("org.springframework.boot:spring-boot-starter-test") { + exclude(module = "junit") + } +} diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/gradle/wrapper/gradle-wrapper.jar b/samples/server/petstore/kotlin-spring-sealed-interfaces/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..e6441136f3d4 Binary files /dev/null and b/samples/server/petstore/kotlin-spring-sealed-interfaces/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-spring-sealed-interfaces/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..80187ac30432 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/gradlew b/samples/server/petstore/kotlin-spring-sealed-interfaces/gradlew new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while +APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path +[ -h "$app_path" ] +do +ls=$( ls -ld "$app_path" ) +link=${ls#*' -> '} +case $link in #( +/*) app_path=$link ;; #( +*) app_path=$APP_HOME$link ;; +esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { +echo "$*" +} >&2 + +die () { +echo +echo "$*" +echo +exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( +CYGWIN* ) cygwin=true ;; #( +Darwin* ) darwin=true ;; #( +MSYS* | MINGW* ) msys=true ;; #( +NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then +if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +# IBM's JDK on AIX uses strange locations for the executables +JAVACMD=$JAVA_HOME/jre/sh/java +else +JAVACMD=$JAVA_HOME/bin/java +fi +if [ ! -x "$JAVACMD" ] ; then +die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +else +JAVACMD=java +if ! command -v java >/dev/null 2>&1 +then +die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then +case $MAX_FD in #( +max*) +# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +MAX_FD=$( ulimit -H -n ) || +warn "Could not query maximum file descriptor limit" +esac +case $MAX_FD in #( +'' | soft) :;; #( +*) +# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +ulimit -n "$MAX_FD" || +warn "Could not set maximum file descriptor limit to $MAX_FD" +esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then +APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) +CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + +JAVACMD=$( cygpath --unix "$JAVACMD" ) + +# Now convert the arguments - kludge to limit ourselves to /bin/sh +for arg do +if +case $arg in #( +-*) false ;; # don't mess with options #( +/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath +[ -e "$t" ] ;; #( +*) false ;; +esac +then +arg=$( cygpath --path --ignore --mixed "$arg" ) +fi +# Roll the args list around exactly as many times as the number of +# args, so each arg winds up back in the position where it started, but +# possibly modified. +# +# NB: a `for` loop captures its iteration list before it begins, so +# changing the positional parameters here affects neither the number of +# iterations, nor the values presented in `arg`. +shift # remove old arg +set -- "$@" "$arg" # push replacement arg +done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ +"-Dorg.gradle.appname=$APP_BASE_NAME" \ +-classpath "$CLASSPATH" \ +org.gradle.wrapper.GradleWrapperMain \ +"$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then +die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( +printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | +xargs -n1 | +sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | +tr '\n' ' ' +)" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/gradlew.bat b/samples/server/petstore/kotlin-spring-sealed-interfaces/gradlew.bat new file mode 100644 index 000000000000..25da30dbdeee --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/pom.xml b/samples/server/petstore/kotlin-spring-sealed-interfaces/pom.xml new file mode 100644 index 000000000000..67af2523dcb8 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/pom.xml @@ -0,0 +1,148 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 3.0.2 + 2.1.0 + 1.7.10 + + 1.7.10 + UTF-8 + + + org.springframework.boot + spring-boot-starter-parent + 3.1.3 + + + + repository.spring.milestone + Spring Milestone Repository + https://repo.spring.io/milestone + + + + + spring-milestones + https://repo.spring.io/milestone + + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + spring + + 17 + + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.data + spring-data-commons + + + + + + + com.google.code.findbugs + jsr305 + ${findbugs-jsr305.version} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + jakarta.validation + jakarta.validation-api + + + jakarta.annotation + jakarta.annotation-api + ${jakarta-annotation.version} + provided + + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin-test-junit5.version} + test + + + diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/settings.gradle b/samples/server/petstore/kotlin-spring-sealed-interfaces/settings.gradle new file mode 100644 index 000000000000..14844905cd40 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/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-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 000000000000..03344e13b474 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,19 @@ +package org.openapitools.api + +import org.springframework.web.context.request.NativeWebRequest + +import jakarta.servlet.http.HttpServletResponse +import java.io.IOException + +object ApiUtil { + fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { + try { + val res = req.getNativeResponse(HttpServletResponse::class.java) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) + } catch (e: IOException) { + throw RuntimeException(e) + } + } +} diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/PetApi.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/PetApi.kt new file mode 100644 index 000000000000..7bd5a63285ca --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/PetApi.kt @@ -0,0 +1,166 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.21.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.api + +import org.openapitools.model.ModelApiResponse +import org.openapitools.model.Pet +import org.openapitools.model.DeletePetResponse +import org.openapitools.model.UpdatePetWithFormResponse +import org.openapitools.model.UpdatePetResponse +import org.openapitools.model.AddPetResponse +import org.openapitools.model.FindPetsByTagsResponse +import org.openapitools.model.GetPetByIdResponse +import org.openapitools.model.UploadFileResponse +import org.openapitools.model.FindPetsByStatusResponse +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface PetApi { + + + @RequestMapping( + method = [RequestMethod.POST], + // "/pet" + value = [PATH_ADD_PET], + produces = ["application/xml", "application/json"], + consumes = ["application/json", "application/xml"] + ) + fun addPet( + @Valid @RequestBody pet: Pet + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.DELETE], + // "/pet/{petId}" + value = [PATH_DELETE_PET] + ) + fun deletePet( + @PathVariable("petId") petId: kotlin.Long, + @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.GET], + // "/pet/findByStatus" + value = [PATH_FIND_PETS_BY_STATUS], + produces = ["application/xml", "application/json"] + ) + fun findPetsByStatus( + @NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.GET], + // "/pet/findByTags" + value = [PATH_FIND_PETS_BY_TAGS], + produces = ["application/xml", "application/json"] + ) + fun findPetsByTags( + @NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.GET], + // "/pet/{petId}" + value = [PATH_GET_PET_BY_ID], + produces = ["application/xml", "application/json"] + ) + fun getPetById( + @PathVariable("petId") petId: kotlin.Long + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.PUT], + // "/pet" + value = [PATH_UPDATE_PET], + produces = ["application/xml", "application/json"], + consumes = ["application/json", "application/xml"] + ) + fun updatePet( + @Valid @RequestBody pet: Pet + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.POST], + // "/pet/{petId}" + value = [PATH_UPDATE_PET_WITH_FORM], + consumes = ["application/x-www-form-urlencoded"] + ) + fun updatePetWithForm( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, + @Valid @RequestParam(value = "status", required = false) status: kotlin.String? + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.POST], + // "/pet/{petId}/uploadImage" + value = [PATH_UPLOAD_FILE], + produces = ["application/json"], + consumes = ["multipart/form-data"] + ) + fun uploadFile( + @PathVariable("petId") petId: kotlin.Long, + @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, + @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_ADD_PET: String = "/pet" + const val PATH_DELETE_PET: String = "/pet/{petId}" + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" + const val PATH_UPDATE_PET: String = "/pet" + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" + } +} diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/StoreApi.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/StoreApi.kt new file mode 100644 index 000000000000..6dc98531b5d2 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/StoreApi.kt @@ -0,0 +1,96 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.21.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.api + +import org.openapitools.model.Order +import org.openapitools.model.DeleteOrderResponse +import org.openapitools.model.GetOrderByIdResponse +import org.openapitools.model.GetInventoryResponse +import org.openapitools.model.PlaceOrderResponse +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface StoreApi { + + + @RequestMapping( + method = [RequestMethod.DELETE], + // "/store/order/{orderId}" + value = [PATH_DELETE_ORDER] + ) + fun deleteOrder( + @PathVariable("orderId") orderId: kotlin.String + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.GET], + // "/store/inventory" + value = [PATH_GET_INVENTORY], + produces = ["application/json"] + ) + fun getInventory(): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.GET], + // "/store/order/{orderId}" + value = [PATH_GET_ORDER_BY_ID], + produces = ["application/xml", "application/json"] + ) + fun getOrderById( + @Min(value=1L) @Max(value=5L) @PathVariable("orderId") orderId: kotlin.Long + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.POST], + // "/store/order" + value = [PATH_PLACE_ORDER], + produces = ["application/xml", "application/json"], + consumes = ["application/json"] + ) + fun placeOrder( + @Valid @RequestBody order: Order + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_DELETE_ORDER: String = "/store/order/{orderId}" + const val PATH_GET_INVENTORY: String = "/store/inventory" + const val PATH_GET_ORDER_BY_ID: String = "/store/order/{orderId}" + const val PATH_PLACE_ORDER: String = "/store/order" + } +} diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/UserApi.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/UserApi.kt new file mode 100644 index 000000000000..46acfc349c4c --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/api/UserApi.kt @@ -0,0 +1,156 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.21.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.api + +import org.openapitools.model.User +import org.openapitools.model.GetUserByNameResponse +import org.openapitools.model.LoginUserResponse +import org.openapitools.model.LogoutUserResponse +import org.openapitools.model.CreateUsersWithArrayInputResponse +import org.openapitools.model.CreateUsersWithListInputResponse +import org.openapitools.model.CreateUserResponse +import org.openapitools.model.UpdateUserResponse +import org.openapitools.model.DeleteUserResponse +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface UserApi { + + + @RequestMapping( + method = [RequestMethod.POST], + // "/user" + value = [PATH_CREATE_USER], + consumes = ["application/json"] + ) + fun createUser( + @Valid @RequestBody user: User + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.POST], + // "/user/createWithArray" + value = [PATH_CREATE_USERS_WITH_ARRAY_INPUT], + consumes = ["application/json"] + ) + fun createUsersWithArrayInput( + @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.POST], + // "/user/createWithList" + value = [PATH_CREATE_USERS_WITH_LIST_INPUT], + consumes = ["application/json"] + ) + fun createUsersWithListInput( + @Valid @RequestBody user: kotlin.collections.List + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.DELETE], + // "/user/{username}" + value = [PATH_DELETE_USER] + ) + fun deleteUser( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.GET], + // "/user/{username}" + value = [PATH_GET_USER_BY_NAME], + produces = ["application/xml", "application/json"] + ) + fun getUserByName( + @PathVariable("username") username: kotlin.String + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.GET], + // "/user/login" + value = [PATH_LOGIN_USER], + produces = ["application/xml", "application/json"] + ) + fun loginUser( + @NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Valid @RequestParam(value = "username", required = true) username: kotlin.String, + @NotNull @Valid @RequestParam(value = "password", required = true) password: kotlin.String + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.GET], + // "/user/logout" + value = [PATH_LOGOUT_USER] + ) + fun logoutUser(): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + + @RequestMapping( + method = [RequestMethod.PUT], + // "/user/{username}" + value = [PATH_UPDATE_USER], + consumes = ["application/json"] + ) + fun updateUser( + @PathVariable("username") username: kotlin.String, + @Valid @RequestBody user: User + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_CREATE_USER: String = "/user" + const val PATH_CREATE_USERS_WITH_ARRAY_INPUT: String = "/user/createWithArray" + const val PATH_CREATE_USERS_WITH_LIST_INPUT: String = "/user/createWithList" + const val PATH_DELETE_USER: String = "/user/{username}" + const val PATH_GET_USER_BY_NAME: String = "/user/{username}" + const val PATH_LOGIN_USER: String = "/user/login" + const val PATH_LOGOUT_USER: String = "/user/logout" + const val PATH_UPDATE_USER: String = "/user/{username}" + } +} diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Category.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Category.kt new file mode 100644 index 000000000000..3cc63c511b1b --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Category.kt @@ -0,0 +1,29 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * A category for a pet + * @param id + * @param name + */ +data class Category( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") + @get:JsonProperty("name") val name: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt new file mode 100644 index 000000000000..0abe67b0e8b1 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/ModelApiResponse.kt @@ -0,0 +1,31 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * Describes the result of uploading an image resource + * @param code + * @param type + * @param message + */ +data class ModelApiResponse( + + @get:JsonProperty("code") val code: kotlin.Int? = null, + + @get:JsonProperty("type") val type: kotlin.String? = null, + + @get:JsonProperty("message") val message: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Order.kt new file mode 100644 index 000000000000..32b058da9896 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Order.kt @@ -0,0 +1,66 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +import org.openapitools.model.PlaceOrderResponse +import org.openapitools.model.PlaceOrderResponse +import org.openapitools.model.GetOrderByIdResponse +import org.openapitools.model.GetOrderByIdResponse +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * An order for a pets from the pet store + * @param id + * @param petId + * @param quantity + * @param shipDate + * @param status Order Status + * @param complete + */ +data class Order( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("petId") val petId: kotlin.Long? = null, + + @get:JsonProperty("quantity") val quantity: kotlin.Int? = null, + + @get:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null, + + @get:JsonProperty("status") val status: Order.Status? = null, + + @get:JsonProperty("complete") val complete: kotlin.Boolean? = false +) : PlaceOrderResponse, PlaceOrderResponse, GetOrderByIdResponse, GetOrderByIdResponse { + + /** + * Order Status + * Values: placed,approved,delivered + */ + enum class Status(@get:JsonValue val value: kotlin.String) { + + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + } + } + } + +} + diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Pet.kt new file mode 100644 index 000000000000..efeaa3cb4c0d --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Pet.kt @@ -0,0 +1,73 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +import org.openapitools.model.Category +import org.openapitools.model.Tag +import org.openapitools.model.UpdatePetResponse +import org.openapitools.model.UpdatePetResponse +import org.openapitools.model.AddPetResponse +import org.openapitools.model.AddPetResponse +import org.openapitools.model.GetPetByIdResponse +import org.openapitools.model.GetPetByIdResponse +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * A pet for sale in the pet store + * @param name + * @param photoUrls + * @param id + * @param category + * @param tags + * @param status pet status in the store + */ +data class Pet( + + @get:JsonProperty("name", required = true) val name: kotlin.String, + + @get:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @field:Valid + @get:JsonProperty("category") val category: Category? = null, + + @field:Valid + @get:JsonProperty("tags") val tags: kotlin.collections.List? = null, + + @Deprecated(message = "") + @get:JsonProperty("status") val status: Pet.Status? = null +) : UpdatePetResponse, UpdatePetResponse, AddPetResponse, AddPetResponse, GetPetByIdResponse, GetPetByIdResponse { + + /** + * pet status in the store + * Values: available,pending,sold + */ + enum class Status(@get:JsonValue val value: kotlin.String) { + + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + } + } + } + +} + diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/SealedResponseInterfaces.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/SealedResponseInterfaces.kt new file mode 100644 index 000000000000..c77aa1bb2dcb --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/SealedResponseInterfaces.kt @@ -0,0 +1,102 @@ +package org.openapitools.model + +/** + * Sealed interface for all possible responses from deletePet + */ +sealed interface DeletePetResponse + +/** + * Sealed interface for all possible responses from updatePetWithForm + */ +sealed interface UpdatePetWithFormResponse + +/** + * Sealed interface for all possible responses from loginUser + */ +sealed interface LoginUserResponse + +/** + * Sealed interface for all possible responses from updatePet + */ +sealed interface UpdatePetResponse + +/** + * Sealed interface for all possible responses from findPetsByTags + */ +sealed interface FindPetsByTagsResponse + +/** + * Sealed interface for all possible responses from getOrderById + */ +sealed interface GetOrderByIdResponse + +/** + * Sealed interface for all possible responses from uploadFile + */ +sealed interface UploadFileResponse + +/** + * Sealed interface for all possible responses from getInventory + */ +sealed interface GetInventoryResponse + +/** + * Sealed interface for all possible responses from placeOrder + */ +sealed interface PlaceOrderResponse + +/** + * Sealed interface for all possible responses from findPetsByStatus + */ +sealed interface FindPetsByStatusResponse + +/** + * Sealed interface for all possible responses from getUserByName + */ +sealed interface GetUserByNameResponse + +/** + * Sealed interface for all possible responses from logoutUser + */ +sealed interface LogoutUserResponse + +/** + * Sealed interface for all possible responses from createUsersWithArrayInput + */ +sealed interface CreateUsersWithArrayInputResponse + +/** + * Sealed interface for all possible responses from createUsersWithListInput + */ +sealed interface CreateUsersWithListInputResponse + +/** + * Sealed interface for all possible responses from addPet + */ +sealed interface AddPetResponse + +/** + * Sealed interface for all possible responses from createUser + */ +sealed interface CreateUserResponse + +/** + * Sealed interface for all possible responses from updateUser + */ +sealed interface UpdateUserResponse + +/** + * Sealed interface for all possible responses from getPetById + */ +sealed interface GetPetByIdResponse + +/** + * Sealed interface for all possible responses from deleteUser + */ +sealed interface DeleteUserResponse + +/** + * Sealed interface for all possible responses from deleteOrder + */ +sealed interface DeleteOrderResponse + diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Tag.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Tag.kt new file mode 100644 index 000000000000..c1081aeaf97c --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/Tag.kt @@ -0,0 +1,28 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * A tag for a pet + * @param id + * @param name + */ +data class Tag( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("name") val name: kotlin.String? = null +) { + +} + diff --git a/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/User.kt new file mode 100644 index 000000000000..225ccb223d86 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-sealed-interfaces/src/main/kotlin/org/openapitools/model/User.kt @@ -0,0 +1,48 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import org.openapitools.model.GetUserByNameResponse +import org.openapitools.model.GetUserByNameResponse +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * A User who is purchasing from the pet store + * @param id + * @param username + * @param firstName + * @param lastName + * @param email + * @param password + * @param phone + * @param userStatus User Status + */ +data class User( + + @get:JsonProperty("id") val id: kotlin.Long? = null, + + @get:JsonProperty("username") val username: kotlin.String? = null, + + @get:JsonProperty("firstName") val firstName: kotlin.String? = null, + + @get:JsonProperty("lastName") val lastName: kotlin.String? = null, + + @get:JsonProperty("email") val email: kotlin.String? = null, + + @get:JsonProperty("password") val password: kotlin.String? = null, + + @get:JsonProperty("phone") val phone: kotlin.String? = null, + + @get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null +) : GetUserByNameResponse, GetUserByNameResponse { + +} +