diff --git a/.github/workflows/samples-kotlin-server-jdk17.yaml b/.github/workflows/samples-kotlin-server-jdk17.yaml index c148ecfa9aa7..0c874516583e 100644 --- a/.github/workflows/samples-kotlin-server-jdk17.yaml +++ b/.github/workflows/samples-kotlin-server-jdk17.yaml @@ -4,6 +4,7 @@ on: push: paths: - 'samples/server/others/kotlin-server/**' + - 'samples/server/others/kotlin-springboot/**' - 'samples/server/petstore/kotlin-springboot-3*/**' - 'samples/server/petstore/kotlin-server/**' - 'samples/server/petstore/kotlin-server-modelMutable/**' @@ -18,6 +19,7 @@ on: pull_request: paths: - 'samples/server/others/kotlin-server/**' + - 'samples/server/others/kotlin-springboot/**' - 'samples/server/petstore/kotlin-springboot-3*/**' - 'samples/server/petstore/kotlin-server/**' - 'samples/server/petstore/kotlin-server-modelMutable/**' @@ -42,6 +44,9 @@ jobs: matrix: sample: # server + - samples/server/others/kotlin-springboot/oneOf-discriminator + - samples/server/others/kotlin-springboot/oneOf-discriminator-const + - samples/server/others/kotlin-springboot/oneOf-enum-discriminator - samples/server/others/kotlin-server/polymorphism-allof-and-discriminator - samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix - samples/server/others/kotlin-server/polymorphism-and-discriminator diff --git a/.github/workflows/samples-kotlin-server-jdk21.yaml b/.github/workflows/samples-kotlin-server-jdk21.yaml index 1421dd4714d2..b4691689bb70 100644 --- a/.github/workflows/samples-kotlin-server-jdk21.yaml +++ b/.github/workflows/samples-kotlin-server-jdk21.yaml @@ -4,11 +4,13 @@ on: push: paths: - 'samples/server/others/kotlin-server/**' + - 'samples/server/others/kotlin-springboot/**' - 'samples/server/petstore/kotlin-server/**' - 'samples/server/petstore/kotlin-server-required-and-nullable-properties/**' pull_request: paths: - 'samples/server/others/kotlin-server/**' + - 'samples/server/others/kotlin-springboot/**' - 'samples/server/petstore/kotlin-server/**' - 'samples/server/petstore/kotlin-server-required-and-nullable-properties/**' @@ -23,6 +25,9 @@ jobs: fail-fast: false matrix: sample: + - samples/server/others/kotlin-springboot/oneOf-discriminator + - samples/server/others/kotlin-springboot/oneOf-discriminator-const + - samples/server/others/kotlin-springboot/oneOf-enum-discriminator - samples/server/others/kotlin-server/polymorphism-allof-and-discriminator - samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix - samples/server/others/kotlin-server/polymorphism-and-discriminator diff --git a/bin/configs/kotlin-spring-boot-oneof-discriminator-const.yaml b/bin/configs/kotlin-spring-boot-oneof-discriminator-const.yaml new file mode 100644 index 000000000000..1ecd7a2b660e --- /dev/null +++ b/bin/configs/kotlin-spring-boot-oneof-discriminator-const.yaml @@ -0,0 +1,11 @@ +generatorName: kotlin-spring +outputDir: samples/server/others/kotlin-springboot/oneOf-discriminator-const +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/3_1/polymorphism-and-discriminator.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + documentationProvider: none + annotationLibrary: none + useSwaggerUI: "false" + interfaceOnly: "true" + useSpringBoot3: "true" diff --git a/bin/configs/kotlin-spring-boot-oneof-discriminator.yaml b/bin/configs/kotlin-spring-boot-oneof-discriminator.yaml new file mode 100644 index 000000000000..2d2edd95bfd1 --- /dev/null +++ b/bin/configs/kotlin-spring-boot-oneof-discriminator.yaml @@ -0,0 +1,11 @@ +generatorName: kotlin-spring +outputDir: samples/server/others/kotlin-springboot/oneOf-discriminator +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/polymorphism-oneof-discriminator.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + documentationProvider: none + annotationLibrary: none + useSwaggerUI: "false" + interfaceOnly: "true" + useSpringBoot3: "true" diff --git a/bin/configs/kotlin-spring-boot-oneof-enum-discriminator.yaml b/bin/configs/kotlin-spring-boot-oneof-enum-discriminator.yaml new file mode 100644 index 000000000000..235978710b26 --- /dev/null +++ b/bin/configs/kotlin-spring-boot-oneof-enum-discriminator.yaml @@ -0,0 +1,11 @@ +generatorName: kotlin-spring +outputDir: samples/server/others/kotlin-springboot/oneOf-enum-discriminator +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/polymorphism-oneof-enum-discriminator.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + documentationProvider: none + annotationLibrary: none + useSwaggerUI: "false" + interfaceOnly: "true" + useSpringBoot3: "true" diff --git a/docs/generators/kotlin-spring.md b/docs/generators/kotlin-spring.md index 529456315dda..dd869eac2a7a 100644 --- a/docs/generators/kotlin-spring.md +++ b/docs/generators/kotlin-spring.md @@ -313,7 +313,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |Union|✗|OAS3 |allOf|✗|OAS2,OAS3 |anyOf|✗|OAS3 -|oneOf|✗|OAS3 +|oneOf|✓|OAS3 |not|✗|OAS3 ### Security Feature diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java index cd130c766530..4d9b8217d763 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java @@ -421,10 +421,28 @@ public String modelFileFolder() { } @Override + @SuppressWarnings("unchecked") public Map postProcessAllModels(Map objs) { objs = super.postProcessAllModels(objs); objs = super.updateAllModels(objs); + // Bridge x-implements (set by oneOf pipeline) into x-kotlin-implements (read by Kotlin templates) + for (ModelsMap modelsAttrs : objs.values()) { + for (ModelMap mo : modelsAttrs.getModels()) { + CodegenModel cm = mo.getModel(); + List xImplements = (List) cm.getVendorExtensions().get(CodegenConstants.X_IMPLEMENTS); + if (xImplements != null && !xImplements.isEmpty()) { + List kotlinImplements = (List) cm.getVendorExtensions() + .computeIfAbsent(VendorExtension.X_KOTLIN_IMPLEMENTS.getName(), k -> new ArrayList<>()); + for (String iface : xImplements) { + if (!kotlinImplements.contains(iface)) { + kotlinImplements.add(iface); + } + } + } + } + } + if (!additionalModelTypeAnnotations.isEmpty()) { for (String modelName : objs.keySet()) { Map models = (Map) objs.get(modelName); 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 153aef1d5165..40b5fdf50bb3 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 @@ -49,6 +49,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER; import static org.openapitools.codegen.utils.StringUtils.camelize; @@ -224,7 +225,8 @@ public KotlinSpringServerCodegen() { GlobalFeature.ParameterStyling ) .includeSchemaSupportFeatures( - SchemaSupportFeature.Polymorphism + SchemaSupportFeature.Polymorphism, + SchemaSupportFeature.oneOf ) .includeParameterFeatures( ParameterFeature.Cookie @@ -233,6 +235,9 @@ public KotlinSpringServerCodegen() { reservedWords.addAll(VARIABLE_RESERVED_WORDS); + // Enable oneOf interface generation (mirrors SpringCodegen behavior) + useOneOfInterfaces = true; + outputFolder = "generated-code/kotlin-spring"; embeddedTemplateDir = templateDir = "kotlin-spring"; @@ -1328,10 +1333,50 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert } } + @Override + public void addImportsToOneOfInterface(List> imports) { + if (additionalProperties.containsKey("jackson")) { + for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo", "JsonIgnoreProperties")) { + Map oneImport = new HashMap<>(); + oneImport.put("import", importMapping.get(i)); + if (!imports.contains(oneImport)) { + imports.add(oneImport); + } + } + } + } + @Override public Map postProcessAllModels(Map objs) { objs = super.postProcessAllModels(objs); + Map allModelsMap = getAllModels(objs); + + // For each oneOf interface with a discriminator, mark the discriminator property + // as inherited in each subtype and set its default value from the discriminator mapping + for (CodegenModel cm : allModelsMap.values()) { + if (Boolean.TRUE.equals(cm.vendorExtensions.get(CodegenConstants.X_IS_ONE_OF_INTERFACE)) + && cm.discriminator != null) { + String discrimBaseName = cm.discriminator.getPropertyBaseName(); + String discrimType = cm.discriminator.getPropertyType(); + boolean isEnumDiscriminator = cm.discriminator.getIsEnum(); + + // Build child name -> mapping name lookup from discriminator mappings + Map childToMappingName = new HashMap<>(); + for (CodegenDiscriminator.MappedModel mm : cm.discriminator.getMappedModels()) { + childToMappingName.put(mm.getModelName(), mm.getMappingName()); + } + + for (String childName : cm.oneOf) { + CodegenModel child = allModelsMap.get(childName); + if (child != null) { + String mappingName = childToMappingName.get(childName); + markPropertyAsInherited(child, discrimBaseName, discrimType, mappingName, isEnumDiscriminator); + } + } + } + } + if (substituteGenericPagedModel && !pagedModelRegistry.isEmpty()) { if (getAnnotationLibrary() == AnnotationLibrary.NONE) { // No @ApiResponse annotations are generated when annotationLibrary=none, @@ -1375,6 +1420,47 @@ public Map postProcessAllModels(Map objs) return objs; } + /** + * Marks the discriminator property as inherited on a subtype and sets its default value + * from the discriminator mapping, so the constructor has the correct default. + */ + private void markPropertyAsInherited(CodegenModel model, String baseName, String dataType, + String discriminatorValue, boolean isEnumDiscriminator) { + Stream.of(model.vars, model.requiredVars, model.optionalVars, model.allVars) + .flatMap(List::stream) + .filter(p -> baseName.equals(p.baseName)) + .forEach(p -> { + p.isInherited = true; + // Discriminator properties must match the parent interface type (non-null, required) + if (dataType != null) { + p.dataType = dataType; + p.datatypeWithEnum = dataType; + p.isNullable = false; + p.required = true; + } + if (discriminatorValue != null) { + if (isEnumDiscriminator) { + p.defaultValue = dataType + "." + toEnumVarName(discriminatorValue, dataType); + } else { + p.defaultValue = "\"" + escapeText(discriminatorValue) + "\""; + } + } + }); + // Move discriminator property from optionalVars to requiredVars if needed. + // Safe to modify optionalVars here — the stream above has fully completed. + if (dataType != null) { + model.optionalVars.stream() + .filter(p -> baseName.equals(p.baseName)) + .findFirst() + .ifPresent(p -> { + model.optionalVars.remove(p); + model.requiredVars.add(p); + }); + model.hasRequired = !model.requiredVars.isEmpty(); + model.hasOptional = !model.optionalVars.isEmpty(); + } + } + @Override public ModelsMap postProcessModelsEnum(ModelsMap objs) { objs = super.postProcessModelsEnum(objs); 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 178487a26e3b..1c7b263517fe 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache @@ -1,8 +1,11 @@ /** * {{{description}}} -{{#vars}} +{{#requiredVars}} + * @param {{name}} {{{description}}} +{{/requiredVars}} +{{#optionalVars}} * @param {{name}} {{{description}}} -{{/vars}} +{{/optionalVars}} */{{#discriminator}} {{>typeInfoAnnotation}}{{/discriminator}} {{#additionalModelTypeAnnotations}} @@ -54,7 +57,7 @@ @JsonCreator fun forValue(value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}): {{{nameInPascalCase}}} { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum '{{classname}}'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum '{{nameInPascalCase}}'") } } } 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 f6005b5340f6..2cff0647030e 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/model.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/model.mustache @@ -23,6 +23,6 @@ import io.swagger.annotations.ApiModelProperty {{#models}} {{#model}} -{{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}}{{>dataClass}}{{/isEnum}} +{{#isEnum}}{{>enumClass}}{{/isEnum}}{{^isEnum}}{{#vendorExtensions.x-is-one-of-interface}}{{>oneof_interface}}{{/vendorExtensions.x-is-one-of-interface}}{{^vendorExtensions.x-is-one-of-interface}}{{>dataClass}}{{/vendorExtensions.x-is-one-of-interface}}{{/isEnum}} {{/model}} {{/models}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/oneof_interface.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/oneof_interface.mustache new file mode 100644 index 000000000000..de545671d8b3 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/oneof_interface.mustache @@ -0,0 +1,17 @@ +/** + * {{{description}}} + */ +{{#discriminator}} +{{>typeInfoAnnotation}} +{{/discriminator}} +{{#additionalModelTypeAnnotations}} +{{{.}}} +{{/additionalModelTypeAnnotations}} +{{#vendorExtensions.x-class-extra-annotation}} +{{{.}}} +{{/vendorExtensions.x-class-extra-annotation}} +sealed interface {{classname}}{{#vendorExtensions.x-kotlin-implements}}{{#-first}} : {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-kotlin-implements}} { +{{#discriminator}} + val {{propertyName}}: {{{propertyType}}} +{{/discriminator}} +} 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 f094264e2709..a23966701868 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 @@ -1031,7 +1031,7 @@ public void overridePropertyFunction() throws IOException { } @Test - public void generateSerializableModel() throws Exception { + public void generateSerializableModelImplementsOneOfInterfaces() throws Exception { File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); output.deleteOnExit(); String outputPath = output.getAbsolutePath().replace('\\', '/'); @@ -1056,7 +1056,14 @@ public void generateSerializableModel() throws Exception { Path path = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Pet.kt"); assertFileContains( path, - ") : java.io.Serializable {", + ") : java.io.Serializable, UserOrPet, UserOrPetOrArrayString {", + "private const val serialVersionUID: kotlin.Long = 1" + ); + + Path userPath = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/User.kt"); + assertFileContains( + userPath, + ") : java.io.Serializable, UserOrPet, UserOrPetOrArrayString {", "private const val serialVersionUID: kotlin.Long = 1" ); } @@ -5789,4 +5796,154 @@ private Map commonDeclarativeHttpInterfacePagedModelProps() { props.put(USE_RESPONSE_ENTITY, "false"); return props; } + + @Test(description = "oneOf with discriminator generates thin sealed interface with Jackson annotations") + public void testOneOfWithDiscriminatorGeneratesThinInterface() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + new DefaultGenerator().opts(new ClientOptInput() + .openAPI(new OpenAPIParser().readLocation("src/test/resources/3_0/kotlin/polymorphism-oneof-discriminator.yaml", null, new ParseOptions()).getOpenAPI()) + .config(new KotlinSpringServerCodegen() {{ setOutputDir(output.getAbsolutePath()); }})) + .generate(); + + String outputPath = output.getAbsolutePath() + "/src/main/kotlin/org/openapitools/model"; + + // Animal should be a thin sealed interface with Jackson annotations and only the discriminator property + assertFileContains(Paths.get(outputPath + "/Animal.kt"), + "sealed interface Animal", + "@JsonTypeInfo", "property = \"discriminator\"", "visible = true", + "@JsonSubTypes", + "JsonSubTypes.Type(value = Bird::class, name = \"BIRD\")", + "JsonSubTypes.Type(value = Robobird::class, name = \"ROBOBIRD\")", + "@JsonIgnoreProperties", + "val discriminator: kotlin.String\n}" + ); + // Should NOT contain subtype-specific properties (fat interface bug) + assertFileNotContains(Paths.get(outputPath + "/Animal.kt"), "propertyA", "propertyB", "sameNameProperty"); + } + + @Test(description = "oneOf with discriminator generates subtypes that implement the sealed interface") + public void testOneOfSubtypesImplementInterface() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + new DefaultGenerator().opts(new ClientOptInput() + .openAPI(new OpenAPIParser().readLocation("src/test/resources/3_0/kotlin/polymorphism-oneof-discriminator.yaml", null, new ParseOptions()).getOpenAPI()) + .config(new KotlinSpringServerCodegen() {{ setOutputDir(output.getAbsolutePath()); }})) + .generate(); + + String outputPath = output.getAbsolutePath() + "/src/main/kotlin/org/openapitools/model"; + + // Bird and Robobird implement both oneOf hierarchies; discriminator props have default values + assertFileContains(Paths.get(outputPath + "/Bird.kt"), + "data class Bird", + ") : Animal, AnotherAnimal {", + "override val discriminator: kotlin.String = \"BIRD\"", + "override val anotherDiscriminator: kotlin.String = \"ANOTHER_BIRD\"" + ); + // Subtypes must retain their own schema-specific properties + assertFileContains(Paths.get(outputPath + "/Bird.kt"), + "val propertyA: kotlin.String?", + "val sameNameProperty: kotlin.Int?" + ); + assertFileContains(Paths.get(outputPath + "/Robobird.kt"), + "data class Robobird", + ") : Animal, AnotherAnimal {", + "override val discriminator: kotlin.String = \"ROBOBIRD\"", + "override val anotherDiscriminator: kotlin.String = \"ANOTHER_ROBOBIRD\"" + ); + assertFileContains(Paths.get(outputPath + "/Robobird.kt"), + "val propertyB: kotlin.String?", + "val sameNameProperty: kotlin.String?" + ); + // AnotherAnimal should also be a sealed interface with Jackson annotations + assertFileContains(Paths.get(outputPath + "/AnotherAnimal.kt"), + "sealed interface AnotherAnimal", + "val anotherDiscriminator: kotlin.String\n}", + "@JsonTypeInfo", "property = \"another_discriminator\"", "visible = true", + "@JsonSubTypes", + "JsonSubTypes.Type(value = Bird::class, name = \"ANOTHER_BIRD\")", + "JsonSubTypes.Type(value = Robobird::class, name = \"ANOTHER_ROBOBIRD\")", + "@JsonIgnoreProperties" + ); + // Sealed interface must not contain subtype-specific properties or snake_case discriminator + assertFileNotContains(Paths.get(outputPath + "/AnotherAnimal.kt"), + "val another_discriminator", + "propertyA", "propertyB", "sameNameProperty" + ); + } + + @Test(description = "oneOf with discriminator using OpenAPI 3.1 spec generates sealed interface") + public void testOneOf31SpecWithDiscriminator() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + new DefaultGenerator().opts(new ClientOptInput() + .openAPI(new OpenAPIParser().readLocation("src/test/resources/3_1/polymorphism-and-discriminator.yaml", null, new ParseOptions()).getOpenAPI()) + .config(new KotlinSpringServerCodegen() {{ setOutputDir(output.getAbsolutePath()); }})) + .generate(); + + String outputPath = output.getAbsolutePath() + "/src/main/kotlin/org/openapitools/model"; + + assertFileContains(Paths.get(outputPath + "/Pet.kt"), + "sealed interface Pet", + "@JsonTypeInfo", "property = \"petType\"", "visible = true", + "@JsonSubTypes", + "JsonSubTypes.Type(value = Cat::class, name = \"cat\")", + "JsonSubTypes.Type(value = Dog::class, name = \"dog\")", + "@JsonIgnoreProperties", + "val petType: kotlin.String\n" + ); + assertFileNotContains(Paths.get(outputPath + "/Pet.kt"), "kotlin.Any", "huntingSkill", "packSize"); + // Discriminator is a constructor param with default value + assertFileContains(Paths.get(outputPath + "/Cat.kt"), + "data class Cat", + ") : Pet {", + "override val petType: kotlin.String = \"cat\"" + ); + assertFileNotContains(Paths.get(outputPath + "/Cat.kt"), "kotlin.Any"); + assertFileContains(Paths.get(outputPath + "/Dog.kt"), + "data class Dog", + ") : Pet {", + "override val petType: kotlin.String = \"dog\"" + ); + assertFileNotContains(Paths.get(outputPath + "/Dog.kt"), "kotlin.Any"); + } + + @Test(description = "oneOf with $ref enum discriminator resolves property type correctly") + public void testOneOfRefEnumDiscriminatorResolvesType() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + new DefaultGenerator().opts(new ClientOptInput() + .openAPI(new OpenAPIParser().readLocation("src/test/resources/3_0/kotlin/polymorphism-oneof-enum-discriminator.yaml", null, new ParseOptions()).getOpenAPI()) + .config(new KotlinSpringServerCodegen() {{ setOutputDir(output.getAbsolutePath()); }})) + .generate(); + + String outputPath = output.getAbsolutePath() + "/src/main/kotlin/org/openapitools/model"; + + // Vehicle's discriminator should use the $ref enum type, not hardcoded kotlin.String + assertFileContains(Paths.get(outputPath + "/Vehicle.kt"), + "sealed interface Vehicle", + "@JsonTypeInfo", "property = \"vehicleType\"", "visible = true", + "@JsonSubTypes", + "JsonSubTypes.Type(value = Car::class, name = \"CAR\")", + "JsonSubTypes.Type(value = Truck::class, name = \"TRUCK\")", + "@JsonIgnoreProperties", + "val vehicleType: VehicleType\n}" + ); + assertFileNotContains(Paths.get(outputPath + "/Vehicle.kt"), "numDoors", "payloadCapacity"); + // Children should implement Vehicle and have enum discriminator with default value + assertFileContains(Paths.get(outputPath + "/Car.kt"), + "data class Car", + ") : Vehicle {", + "override val vehicleType: VehicleType = VehicleType.CAR" + ); + assertFileContains(Paths.get(outputPath + "/Truck.kt"), + "data class Truck", + ") : Vehicle {", + "override val vehicleType: VehicleType = VehicleType.TRUCK" + ); + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/kotlin/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/kotlin/petstore.yaml index 401f309bf71d..a3800e235c08 100644 --- a/modules/openapi-generator/src/test/resources/3_0/kotlin/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/kotlin/petstore.yaml @@ -799,10 +799,12 @@ components: type: string format: uuid UserOrPet: + description: A schema that can be either a User or a Pet oneOf: - $ref: "#/components/schemas/User" - $ref: "#/components/schemas/Pet" UserOrPetOrArrayString: + description: A schema that can be either a User, a Pet, or an array of strings oneOf: - $ref: "#/components/schemas/User" - $ref: "#/components/schemas/Pet" diff --git a/modules/openapi-generator/src/test/resources/3_0/kotlin/polymorphism-oneof-enum-discriminator.yaml b/modules/openapi-generator/src/test/resources/3_0/kotlin/polymorphism-oneof-enum-discriminator.yaml new file mode 100644 index 000000000000..ddad40c7fef8 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/kotlin/polymorphism-oneof-enum-discriminator.yaml @@ -0,0 +1,48 @@ +openapi: 3.0.3 +info: + title: oneOf with enum discriminator + version: "1.0" +paths: {} +components: + schemas: + Vehicle: + type: object + required: + - vehicleType + properties: + vehicleType: + $ref: '#/components/schemas/VehicleType' + oneOf: + - $ref: '#/components/schemas/Car' + - $ref: '#/components/schemas/Truck' + discriminator: + propertyName: vehicleType + mapping: + CAR: '#/components/schemas/Car' + TRUCK: '#/components/schemas/Truck' + Car: + type: object + required: + - vehicleType + - numDoors + properties: + vehicleType: + $ref: '#/components/schemas/VehicleType' + numDoors: + type: integer + Truck: + type: object + required: + - vehicleType + - payloadCapacity + properties: + vehicleType: + $ref: '#/components/schemas/VehicleType' + payloadCapacity: + type: number + + VehicleType: + type: string + enum: + - CAR + - TRUCK diff --git a/modules/openapi-generator/src/test/resources/3_1/polymorphism-and-discriminator.yaml b/modules/openapi-generator/src/test/resources/3_1/polymorphism-and-discriminator.yaml index 66de012640ef..bc3a7853c6f0 100644 --- a/modules/openapi-generator/src/test/resources/3_1/polymorphism-and-discriminator.yaml +++ b/modules/openapi-generator/src/test/resources/3_1/polymorphism-and-discriminator.yaml @@ -9,6 +9,7 @@ paths: {} components: schemas: Pet: + description: A pet type: object discriminator: propertyName: petType diff --git a/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/models/UserOrPet.kt b/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/models/UserOrPet.kt index 0e8963ca33f7..b2e1c8016f22 100644 --- a/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/models/UserOrPet.kt +++ b/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/models/UserOrPet.kt @@ -31,7 +31,7 @@ import org.openapitools.client.models.User import com.google.gson.annotations.SerializedName /** - * + * A schema that can be either a User or a Pet * * @param username * @param name diff --git a/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/models/UserOrPetOrArrayString.kt b/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/models/UserOrPetOrArrayString.kt index 50662ee2a6cb..2cb265f3caa2 100644 --- a/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/models/UserOrPetOrArrayString.kt +++ b/samples/client/petstore/kotlin-jvm-ktor-gson/src/main/kotlin/org/openapitools/client/models/UserOrPetOrArrayString.kt @@ -31,7 +31,7 @@ import org.openapitools.client.models.User import com.google.gson.annotations.SerializedName /** - * + * A schema that can be either a User, a Pet, or an array of strings * * @param username * @param name diff --git a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiUserOrPet.kt b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiUserOrPet.kt index 0fca13982b55..6eb0feeb2022 100644 --- a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiUserOrPet.kt +++ b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiUserOrPet.kt @@ -40,7 +40,7 @@ import com.google.gson.annotations.SerializedName import java.io.IOException /** - * + * A schema that can be either a User or a Pet * */ data class ApiUserOrPet(var actualInstance: Any? = null) { diff --git a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiUserOrPetOrArrayString.kt b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiUserOrPetOrArrayString.kt index 80906d55409f..19bf5ed7ac49 100644 --- a/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiUserOrPetOrArrayString.kt +++ b/samples/client/petstore/kotlin-model-prefix-type-mappings/src/main/kotlin/org/openapitools/client/models/ApiUserOrPetOrArrayString.kt @@ -40,7 +40,7 @@ import com.google.gson.annotations.SerializedName import java.io.IOException /** - * + * A schema that can be either a User, a Pet, or an array of strings * */ data class ApiUserOrPetOrArrayString(var actualInstance: Any? = null) { diff --git a/samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix/src/main/kotlin/org/openapitools/server/models/Pet.kt index b2c3ac1d7be4..737a74aefcfb 100644 --- a/samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix/src/main/kotlin/org/openapitools/server/models/Pet.kt +++ b/samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix/src/main/kotlin/org/openapitools/server/models/Pet.kt @@ -15,7 +15,7 @@ import org.openapitools.server.models.Cat import org.openapitools.server.models.Dog /** - * + * A pet */ @com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include = com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY, property = "petType", visible = false) @com.fasterxml.jackson.annotation.JsonSubTypes( diff --git a/samples/server/others/kotlin-server/polymorphism-and-discriminator/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/others/kotlin-server/polymorphism-and-discriminator/src/main/kotlin/org/openapitools/server/models/Pet.kt index 1311dc6d56ff..30ada8deb372 100644 --- a/samples/server/others/kotlin-server/polymorphism-and-discriminator/src/main/kotlin/org/openapitools/server/models/Pet.kt +++ b/samples/server/others/kotlin-server/polymorphism-and-discriminator/src/main/kotlin/org/openapitools/server/models/Pet.kt @@ -15,7 +15,7 @@ import org.openapitools.server.models.Cat import org.openapitools.server.models.Dog /** - * + * A pet * @param petType */ @com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include = com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY, property = "petType", visible = true) diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator-const/.openapi-generator-ignore b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/.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/others/kotlin-springboot/oneOf-discriminator-const/.openapi-generator/FILES b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/.openapi-generator/FILES new file mode 100644 index 000000000000..b44f6d80dbdb --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/.openapi-generator/FILES @@ -0,0 +1,13 @@ +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/Exceptions.kt +src/main/kotlin/org/openapitools/model/Cat.kt +src/main/kotlin/org/openapitools/model/Dog.kt +src/main/kotlin/org/openapitools/model/Pet.kt diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator-const/.openapi-generator/VERSION b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/.openapi-generator/VERSION new file mode 100644 index 000000000000..f7962df3e243 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.22.0-SNAPSHOT diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator-const/README.md b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/README.md new file mode 100644 index 000000000000..e840a9666547 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/README.md @@ -0,0 +1,21 @@ +# basicPolymorphismExampleWithDiscriminator + +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/others/kotlin-springboot/oneOf-discriminator-const/build.gradle.kts b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/build.gradle.kts new file mode 100644 index 000000000000..dff0fa211c8d --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/build.gradle.kts @@ -0,0 +1,48 @@ +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.3.13" + id("io.spring.dependency-management") version "1.1.7" +} + +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("org.springframework.boot:spring-boot-starter-validation") + 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/others/kotlin-springboot/oneOf-discriminator-const/gradle/wrapper/gradle-wrapper.jar b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..e6441136f3d4 Binary files /dev/null and b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator-const/gradle/wrapper/gradle-wrapper.properties b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..80187ac30432 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/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/others/kotlin-springboot/oneOf-discriminator-const/gradlew b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/gradlew new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/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/others/kotlin-springboot/oneOf-discriminator-const/gradlew.bat b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/gradlew.bat new file mode 100644 index 000000000000..25da30dbdeee --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/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/others/kotlin-springboot/oneOf-discriminator-const/pom.xml b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/pom.xml new file mode 100644 index 000000000000..70890ca131cc --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/pom.xml @@ -0,0 +1,152 @@ + + 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.3.13 + + + + 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 + + + org.springframework.boot + spring-boot-starter-validation + + + 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/others/kotlin-springboot/oneOf-discriminator-const/settings.gradle b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/settings.gradle new file mode 100644 index 000000000000..14844905cd40 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/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/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 000000000000..03344e13b474 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/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/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/api/Exceptions.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/api/Exceptions.kt new file mode 100644 index 000000000000..1bd78f54576a --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/api/Exceptions.kt @@ -0,0 +1,30 @@ +package org.openapitools.api + +import org.springframework.context.annotation.Configuration +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.bind.annotation.ExceptionHandler +import jakarta.servlet.http.HttpServletResponse +import jakarta.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) + +@Configuration("org.openapitools.api.DefaultExceptionHandler") +@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/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/model/Cat.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/model/Cat.kt new file mode 100644 index 000000000000..045db84aeedc --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/model/Cat.kt @@ -0,0 +1,55 @@ +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 com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +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 cat + * @param huntingSkill The measured skill for hunting + * @param petType + */ +data class Cat( + + @get:JsonProperty("huntingSkill", required = true) val huntingSkill: Cat.HuntingSkill, + + @field:Valid + @get:JsonProperty("petType", required = true) override val petType: kotlin.String = "cat" +) : Pet { + + /** + * The measured skill for hunting + * Values: clueless,lazy,adventurous,aggressive + */ + enum class HuntingSkill(@get:JsonValue val value: kotlin.String) { + + clueless("clueless"), + lazy("lazy"), + adventurous("adventurous"), + aggressive("aggressive"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): HuntingSkill { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'HuntingSkill'") + } + } + } + +} + diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/model/Dog.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/model/Dog.kt new file mode 100644 index 000000000000..f6abcb58897d --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/model/Dog.kt @@ -0,0 +1,35 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +import com.fasterxml.jackson.annotation.JsonValue +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 dog + * @param petType + * @param packSize the size of the pack the dog is from + */ +data class Dog( + + @field:Valid + @get:JsonProperty("petType", required = true) override val petType: kotlin.String = "dog", + + @get:Min(value=0) + @get:JsonProperty("packSize", required = true) val packSize: kotlin.Int = 0 +) : Pet { + +} + diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/model/Pet.kt new file mode 100644 index 000000000000..40869b85e6bb --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator-const/src/main/kotlin/org/openapitools/model/Pet.kt @@ -0,0 +1,37 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +import com.fasterxml.jackson.annotation.JsonValue +import org.openapitools.model.Cat +import org.openapitools.model.Dog +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 + */ +@JsonIgnoreProperties( + value = ["petType"], // ignore manually set petType, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the petType to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "petType", visible = true) +@JsonSubTypes( + JsonSubTypes.Type(value = Cat::class, name = "cat"), + JsonSubTypes.Type(value = Dog::class, name = "dog") +) +sealed interface Pet { + val petType: kotlin.String +} + diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator/.openapi-generator-ignore b/samples/server/others/kotlin-springboot/oneOf-discriminator/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/.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/others/kotlin-springboot/oneOf-discriminator/.openapi-generator/FILES b/samples/server/others/kotlin-springboot/oneOf-discriminator/.openapi-generator/FILES new file mode 100644 index 000000000000..20ee96df46dd --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/.openapi-generator/FILES @@ -0,0 +1,15 @@ +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/Exceptions.kt +src/main/kotlin/org/openapitools/api/V1Api.kt +src/main/kotlin/org/openapitools/model/Animal.kt +src/main/kotlin/org/openapitools/model/AnotherAnimal.kt +src/main/kotlin/org/openapitools/model/Bird.kt +src/main/kotlin/org/openapitools/model/Robobird.kt diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator/.openapi-generator/VERSION b/samples/server/others/kotlin-springboot/oneOf-discriminator/.openapi-generator/VERSION new file mode 100644 index 000000000000..f7962df3e243 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.22.0-SNAPSHOT diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator/README.md b/samples/server/others/kotlin-springboot/oneOf-discriminator/README.md new file mode 100644 index 000000000000..07837a850b30 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/README.md @@ -0,0 +1,21 @@ +# example + +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/others/kotlin-springboot/oneOf-discriminator/build.gradle.kts b/samples/server/others/kotlin-springboot/oneOf-discriminator/build.gradle.kts new file mode 100644 index 000000000000..dff0fa211c8d --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/build.gradle.kts @@ -0,0 +1,48 @@ +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.3.13" + id("io.spring.dependency-management") version "1.1.7" +} + +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("org.springframework.boot:spring-boot-starter-validation") + 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/others/kotlin-springboot/oneOf-discriminator/gradle/wrapper/gradle-wrapper.jar b/samples/server/others/kotlin-springboot/oneOf-discriminator/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..e6441136f3d4 Binary files /dev/null and b/samples/server/others/kotlin-springboot/oneOf-discriminator/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator/gradle/wrapper/gradle-wrapper.properties b/samples/server/others/kotlin-springboot/oneOf-discriminator/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..80187ac30432 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/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/others/kotlin-springboot/oneOf-discriminator/gradlew b/samples/server/others/kotlin-springboot/oneOf-discriminator/gradlew new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/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/others/kotlin-springboot/oneOf-discriminator/gradlew.bat b/samples/server/others/kotlin-springboot/oneOf-discriminator/gradlew.bat new file mode 100644 index 000000000000..25da30dbdeee --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/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/others/kotlin-springboot/oneOf-discriminator/pom.xml b/samples/server/others/kotlin-springboot/oneOf-discriminator/pom.xml new file mode 100644 index 000000000000..70890ca131cc --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/pom.xml @@ -0,0 +1,152 @@ + + 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.3.13 + + + + 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 + + + org.springframework.boot + spring-boot-starter-validation + + + 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/others/kotlin-springboot/oneOf-discriminator/settings.gradle b/samples/server/others/kotlin-springboot/oneOf-discriminator/settings.gradle new file mode 100644 index 000000000000..14844905cd40 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/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/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 000000000000..03344e13b474 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/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/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/api/Exceptions.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/api/Exceptions.kt new file mode 100644 index 000000000000..1bd78f54576a --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/api/Exceptions.kt @@ -0,0 +1,30 @@ +package org.openapitools.api + +import org.springframework.context.annotation.Configuration +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.bind.annotation.ExceptionHandler +import jakarta.servlet.http.HttpServletResponse +import jakarta.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) + +@Configuration("org.openapitools.api.DefaultExceptionHandler") +@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/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/api/V1Api.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/api/V1Api.kt new file mode 100644 index 000000000000..e162703d5670 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/api/V1Api.kt @@ -0,0 +1,52 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.22.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.api + +import org.openapitools.model.Animal +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 V1Api { + + + @RequestMapping( + method = [RequestMethod.GET], + // "/v1/bird/{id}" + value = [PATH_GET_BIRD], + produces = ["application/json"] + ) + fun getBird( + @PathVariable("id") id: java.util.UUID + ): ResponseEntity { + return ResponseEntity(HttpStatus.NOT_IMPLEMENTED) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val PATH_GET_BIRD: String = "/v1/bird/{id}" + } +} diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/Animal.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/Animal.kt new file mode 100644 index 000000000000..cd4ca70bbd76 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/Animal.kt @@ -0,0 +1,35 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +import org.openapitools.model.Bird +import org.openapitools.model.Robobird +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 + +/** + * + */ +@JsonIgnoreProperties( + value = ["discriminator"], // ignore manually set discriminator, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the discriminator to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "discriminator", visible = true) +@JsonSubTypes( + JsonSubTypes.Type(value = Bird::class, name = "BIRD"), + JsonSubTypes.Type(value = Robobird::class, name = "ROBOBIRD") +) +sealed interface Animal { + val discriminator: kotlin.String +} + diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/AnotherAnimal.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/AnotherAnimal.kt new file mode 100644 index 000000000000..2c04b66ba59f --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/AnotherAnimal.kt @@ -0,0 +1,35 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +import org.openapitools.model.Bird +import org.openapitools.model.Robobird +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 + +/** + * + */ +@JsonIgnoreProperties( + value = ["another_discriminator"], // ignore manually set another_discriminator, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the another_discriminator to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "another_discriminator", visible = true) +@JsonSubTypes( + JsonSubTypes.Type(value = Bird::class, name = "ANOTHER_BIRD"), + JsonSubTypes.Type(value = Robobird::class, name = "ANOTHER_ROBOBIRD") +) +sealed interface AnotherAnimal { + val anotherDiscriminator: kotlin.String +} + diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/Bird.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/Bird.kt new file mode 100644 index 000000000000..fb121eeee588 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/Bird.kt @@ -0,0 +1,37 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +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 + +/** + * + * @param discriminator + * @param anotherDiscriminator + * @param propertyA + * @param sameNameProperty + */ +data class Bird( + + @get:JsonProperty("discriminator", required = true) override val discriminator: kotlin.String = "BIRD", + + @get:JsonProperty("another_discriminator", required = true) override val anotherDiscriminator: kotlin.String = "ANOTHER_BIRD", + + @get:JsonProperty("propertyA") val propertyA: kotlin.String? = null, + + @get:JsonProperty("sameNameProperty") val sameNameProperty: kotlin.Int? = null +) : Animal, AnotherAnimal { + +} + diff --git a/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/Robobird.kt b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/Robobird.kt new file mode 100644 index 000000000000..98e06b9b617f --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-discriminator/src/main/kotlin/org/openapitools/model/Robobird.kt @@ -0,0 +1,37 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +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 + +/** + * + * @param discriminator + * @param anotherDiscriminator + * @param propertyB + * @param sameNameProperty + */ +data class Robobird( + + @get:JsonProperty("discriminator", required = true) override val discriminator: kotlin.String = "ROBOBIRD", + + @get:JsonProperty("another_discriminator", required = true) override val anotherDiscriminator: kotlin.String = "ANOTHER_ROBOBIRD", + + @get:JsonProperty("propertyB") val propertyB: kotlin.String? = null, + + @get:JsonProperty("sameNameProperty") val sameNameProperty: kotlin.String? = null +) : Animal, AnotherAnimal { + +} + diff --git a/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/.openapi-generator-ignore b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/.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/others/kotlin-springboot/oneOf-enum-discriminator/.openapi-generator/FILES b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/.openapi-generator/FILES new file mode 100644 index 000000000000..8a5a234bef75 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/.openapi-generator/FILES @@ -0,0 +1,15 @@ +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/Exceptions.kt +src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt +src/main/kotlin/org/openapitools/model/Car.kt +src/main/kotlin/org/openapitools/model/Truck.kt +src/main/kotlin/org/openapitools/model/Vehicle.kt +src/main/kotlin/org/openapitools/model/VehicleType.kt diff --git a/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/.openapi-generator/VERSION b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/.openapi-generator/VERSION new file mode 100644 index 000000000000..f7962df3e243 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.22.0-SNAPSHOT diff --git a/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/README.md b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/README.md new file mode 100644 index 000000000000..9361b302d393 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/README.md @@ -0,0 +1,21 @@ +# oneOfWithEnumDiscriminator + +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/others/kotlin-springboot/oneOf-enum-discriminator/build.gradle.kts b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/build.gradle.kts new file mode 100644 index 000000000000..dff0fa211c8d --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/build.gradle.kts @@ -0,0 +1,48 @@ +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.3.13" + id("io.spring.dependency-management") version "1.1.7" +} + +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("org.springframework.boot:spring-boot-starter-validation") + 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/others/kotlin-springboot/oneOf-enum-discriminator/gradle/wrapper/gradle-wrapper.jar b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..e6441136f3d4 Binary files /dev/null and b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/gradle/wrapper/gradle-wrapper.properties b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..80187ac30432 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/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/others/kotlin-springboot/oneOf-enum-discriminator/gradlew b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/gradlew new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/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/others/kotlin-springboot/oneOf-enum-discriminator/gradlew.bat b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/gradlew.bat new file mode 100644 index 000000000000..25da30dbdeee --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/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/others/kotlin-springboot/oneOf-enum-discriminator/pom.xml b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/pom.xml new file mode 100644 index 000000000000..70890ca131cc --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/pom.xml @@ -0,0 +1,152 @@ + + 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.3.13 + + + + 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 + + + org.springframework.boot + spring-boot-starter-validation + + + 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/others/kotlin-springboot/oneOf-enum-discriminator/settings.gradle b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/settings.gradle new file mode 100644 index 000000000000..14844905cd40 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/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/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 000000000000..03344e13b474 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/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/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/api/Exceptions.kt b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/api/Exceptions.kt new file mode 100644 index 000000000000..1bd78f54576a --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/api/Exceptions.kt @@ -0,0 +1,30 @@ +package org.openapitools.api + +import org.springframework.context.annotation.Configuration +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.bind.annotation.ExceptionHandler +import jakarta.servlet.http.HttpServletResponse +import jakarta.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) + +@Configuration("org.openapitools.api.DefaultExceptionHandler") +@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/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt new file mode 100644 index 000000000000..7f3638ebc805 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt @@ -0,0 +1,26 @@ +package org.openapitools.configuration + +import org.openapitools.model.VehicleType + +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.core.convert.converter.Converter + +/** + * This class provides Spring Converter beans for the enum models in the OpenAPI specification. + * + * By default, Spring only converts primitive types to enums using Enum::valueOf, which can prevent + * correct conversion if the OpenAPI specification is using an `enumPropertyNaming` other than + * `original` or the specification has an integer enum. + */ +@Configuration(value = "org.openapitools.configuration.enumConverterConfiguration") +class EnumConverterConfiguration { + + @Bean(name = ["org.openapitools.configuration.EnumConverterConfiguration.vehicleTypeConverter"]) + fun vehicleTypeConverter(): Converter { + return object: Converter { + override fun convert(source: kotlin.String): VehicleType = VehicleType.forValue(source) + } + } + +} diff --git a/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/Car.kt b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/Car.kt new file mode 100644 index 000000000000..731b9ea0e007 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/Car.kt @@ -0,0 +1,35 @@ +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.VehicleType +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +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 + +/** + * + * @param vehicleType + * @param numDoors + */ +data class Car( + + @field:Valid + @get:JsonProperty("vehicleType", required = true) override val vehicleType: VehicleType = VehicleType.CAR, + + @get:JsonProperty("numDoors", required = true) val numDoors: kotlin.Int +) : Vehicle { + +} + diff --git a/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/Truck.kt b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/Truck.kt new file mode 100644 index 000000000000..d53c76f6fc56 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/Truck.kt @@ -0,0 +1,35 @@ +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.VehicleType +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +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 + +/** + * + * @param vehicleType + * @param payloadCapacity + */ +data class Truck( + + @field:Valid + @get:JsonProperty("vehicleType", required = true) override val vehicleType: VehicleType = VehicleType.TRUCK, + + @get:JsonProperty("payloadCapacity", required = true) val payloadCapacity: java.math.BigDecimal +) : Vehicle { + +} + diff --git a/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/Vehicle.kt b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/Vehicle.kt new file mode 100644 index 000000000000..637caa41c0e0 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/Vehicle.kt @@ -0,0 +1,38 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +import com.fasterxml.jackson.annotation.JsonValue +import org.openapitools.model.Car +import org.openapitools.model.Truck +import org.openapitools.model.VehicleType +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 + +/** + * + */ +@JsonIgnoreProperties( + value = ["vehicleType"], // ignore manually set vehicleType, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the vehicleType to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "vehicleType", visible = true) +@JsonSubTypes( + JsonSubTypes.Type(value = Car::class, name = "CAR"), + JsonSubTypes.Type(value = Truck::class, name = "TRUCK") +) +sealed interface Vehicle { + val vehicleType: VehicleType +} + diff --git a/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/VehicleType.kt b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/VehicleType.kt new file mode 100644 index 000000000000..400f44e12a77 --- /dev/null +++ b/samples/server/others/kotlin-springboot/oneOf-enum-discriminator/src/main/kotlin/org/openapitools/model/VehicleType.kt @@ -0,0 +1,35 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonValue +import com.fasterxml.jackson.annotation.JsonCreator +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 + +/** +* +* Values: CAR,TRUCK +*/ +enum class VehicleType(@get:JsonValue val value: kotlin.String) { + + CAR("CAR"), + TRUCK("TRUCK"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): VehicleType { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'VehicleType'") + } + } +} + diff --git a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Order.kt index 6b034dcbd95c..3837fc6822be 100644 --- a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Order.kt @@ -53,7 +53,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Pet.kt index 58d842d18ba4..142ad86789b1 100644 --- a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Pet.kt @@ -58,7 +58,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/model/Order.kt index 5b7c406fbc7d..4749b654be89 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/model/Order.kt @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/model/Pet.kt index cb4f41ddff01..b5645e48a282 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-coroutines/src/main/kotlin/org/openapitools/model/Pet.kt @@ -65,7 +65,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/model/Order.kt index 5b7c406fbc7d..4749b654be89 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/model/Order.kt @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/model/Pet.kt index cb4f41ddff01..b5645e48a282 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-reactive-reactor-wrapped/src/main/kotlin/org/openapitools/model/Pet.kt @@ -65,7 +65,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/model/Order.kt index 5b7c406fbc7d..4749b654be89 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/model/Order.kt @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/model/Pet.kt index cb4f41ddff01..b5645e48a282 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface-wrapped/src/main/kotlin/org/openapitools/model/Pet.kt @@ -65,7 +65,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/model/Order.kt index 5b7c406fbc7d..4749b654be89 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/model/Order.kt @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/model/Pet.kt index cb4f41ddff01..b5645e48a282 100644 --- a/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-spring-declarative-interface/src/main/kotlin/org/openapitools/model/Pet.kt @@ -65,7 +65,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPet.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPet.kt index c92cd44d214a..317d5386108e 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPet.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPet.kt @@ -95,7 +95,7 @@ data class AnyOfUserOrPet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'AnyOfUserOrPet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPetOrArrayString.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPetOrArrayString.kt index 773f41c9d94b..03df455663f1 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPetOrArrayString.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPetOrArrayString.kt @@ -95,7 +95,7 @@ data class AnyOfUserOrPetOrArrayString( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'AnyOfUserOrPetOrArrayString'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Order.kt index bf762a03281c..9e29b16a1d27 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Order.kt @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Pet.kt index a5e465fe87bb..c491482d5d14 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Pet.kt @@ -48,7 +48,7 @@ data class Pet( @Schema(example = "null", description = "pet status in the store") @Deprecated(message = "") @get:JsonProperty("status") val status: Pet.Status? = null -) { +) : UserOrPet, UserOrPetOrArrayString { /** * pet status in the store @@ -65,7 +65,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/User.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/User.kt index 54e6eba1fee5..ec6d754415d8 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/User.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/User.kt @@ -2,6 +2,8 @@ package org.openapitools.model import java.util.Objects import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonValue import javax.validation.constraints.DecimalMax import javax.validation.constraints.DecimalMin import javax.validation.constraints.Email @@ -49,7 +51,7 @@ data class User( @Schema(example = "null", description = "User Status") @get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null -) { +) : UserOrPet, UserOrPetOrArrayString { } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPet.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPet.kt index 193726729695..c337b9d447ac 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPet.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPet.kt @@ -8,6 +8,9 @@ import org.openapitools.model.Category import org.openapitools.model.Pet import org.openapitools.model.Tag import org.openapitools.model.User +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +import com.fasterxml.jackson.annotation.JsonIgnoreProperties import javax.validation.constraints.DecimalMax import javax.validation.constraints.DecimalMin import javax.validation.constraints.Email @@ -20,85 +23,8 @@ import javax.validation.Valid import io.swagger.v3.oas.annotations.media.Schema /** - * - * @param username - * @param name - * @param photoUrls - * @param id - * @param firstName - * @param lastName - * @param email - * @param password - * @param phone - * @param userStatus User Status - * @param category - * @param tags - * @param status pet status in the store + * A schema that can be either a User or a Pet */ -data class UserOrPet( - - @Schema(example = "null", required = true, description = "") - @get:JsonProperty("username", required = true) val username: kotlin.String, - - @Schema(example = "doggie", required = true, description = "") - @get:JsonProperty("name", required = true) val name: kotlin.String, - - @Schema(example = "null", required = true, description = "") - @get:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, - - @Schema(example = "null", description = "") - @get:JsonProperty("id") val id: kotlin.Long? = null, - - @Schema(example = "null", description = "") - @get:JsonProperty("firstName") val firstName: kotlin.String? = null, - - @Schema(example = "null", description = "") - @get:JsonProperty("lastName") val lastName: kotlin.String? = null, - - @Schema(example = "null", description = "") - @get:JsonProperty("email") val email: kotlin.String? = null, - - @Schema(example = "null", description = "") - @get:JsonProperty("password") val password: kotlin.String? = null, - - @Schema(example = "null", description = "") - @get:JsonProperty("phone") val phone: kotlin.String? = null, - - @Schema(example = "null", description = "User Status") - @get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null, - - @field:Valid - @Schema(example = "null", description = "") - @get:JsonProperty("category") val category: Category? = null, - - @field:Valid - @Schema(example = "null", description = "") - @get:JsonProperty("tags") val tags: kotlin.collections.List? = null, - - @Schema(example = "null", description = "pet status in the store") - @Deprecated(message = "") - @get:JsonProperty("status") val status: UserOrPet.Status? = null -) { - - /** - * pet status in the store - * Values: available,pending,sold - */ - enum class Status(@get:JsonValue val value: kotlin.String) { - - available("available"), - pending("pending"), - sold("sold"); - - companion object { - @JvmStatic - @JsonCreator - fun forValue(value: kotlin.String): Status { - return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'UserOrPet'") - } - } - } - +sealed interface UserOrPet { } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPetOrArrayString.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPetOrArrayString.kt index ff90fc8523b7..e94b3aee8c38 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPetOrArrayString.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPetOrArrayString.kt @@ -8,6 +8,9 @@ import org.openapitools.model.Category import org.openapitools.model.Pet import org.openapitools.model.Tag import org.openapitools.model.User +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +import com.fasterxml.jackson.annotation.JsonIgnoreProperties import javax.validation.constraints.DecimalMax import javax.validation.constraints.DecimalMin import javax.validation.constraints.Email @@ -20,85 +23,8 @@ import javax.validation.Valid import io.swagger.v3.oas.annotations.media.Schema /** - * - * @param username - * @param name - * @param photoUrls - * @param id - * @param firstName - * @param lastName - * @param email - * @param password - * @param phone - * @param userStatus User Status - * @param category - * @param tags - * @param status pet status in the store + * A schema that can be either a User, a Pet, or an array of strings */ -data class UserOrPetOrArrayString( - - @Schema(example = "null", required = true, description = "") - @get:JsonProperty("username", required = true) val username: kotlin.String, - - @Schema(example = "doggie", required = true, description = "") - @get:JsonProperty("name", required = true) val name: kotlin.String, - - @Schema(example = "null", required = true, description = "") - @get:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List, - - @Schema(example = "null", description = "") - @get:JsonProperty("id") val id: kotlin.Long? = null, - - @Schema(example = "null", description = "") - @get:JsonProperty("firstName") val firstName: kotlin.String? = null, - - @Schema(example = "null", description = "") - @get:JsonProperty("lastName") val lastName: kotlin.String? = null, - - @Schema(example = "null", description = "") - @get:JsonProperty("email") val email: kotlin.String? = null, - - @Schema(example = "null", description = "") - @get:JsonProperty("password") val password: kotlin.String? = null, - - @Schema(example = "null", description = "") - @get:JsonProperty("phone") val phone: kotlin.String? = null, - - @Schema(example = "null", description = "User Status") - @get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null, - - @field:Valid - @Schema(example = "null", description = "") - @get:JsonProperty("category") val category: Category? = null, - - @field:Valid - @Schema(example = "null", description = "") - @get:JsonProperty("tags") val tags: kotlin.collections.List? = null, - - @Schema(example = "null", description = "pet status in the store") - @Deprecated(message = "") - @get:JsonProperty("status") val status: UserOrPetOrArrayString.Status? = null -) { - - /** - * pet status in the store - * Values: available,pending,sold - */ - enum class Status(@get:JsonValue val value: kotlin.String) { - - available("available"), - pending("pending"), - sold("sold"); - - companion object { - @JvmStatic - @JsonCreator - fun forValue(value: kotlin.String): Status { - return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'UserOrPetOrArrayString'") - } - } - } - +sealed interface UserOrPetOrArrayString { } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/resources/openapi.yaml b/samples/server/petstore/kotlin-spring-default/src/main/resources/openapi.yaml index 1d90883560f5..1f2e34812c4b 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/resources/openapi.yaml +++ b/samples/server/petstore/kotlin-spring-default/src/main/resources/openapi.yaml @@ -831,16 +831,20 @@ components: type: string type: object UserOrPet: + description: A schema that can be either a User or a Pet oneOf: - $ref: "#/components/schemas/User" - $ref: "#/components/schemas/Pet" + x-one-of-name: UserOrPet UserOrPetOrArrayString: + description: "A schema that can be either a User, a Pet, or an array of strings" oneOf: - $ref: "#/components/schemas/User" - $ref: "#/components/schemas/Pet" - items: type: string type: array + x-one-of-name: UserOrPetOrArrayString AnyOfUserOrPet: anyOf: - $ref: "#/components/schemas/User" 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 index c4eb2a435633..23b812a1c833 100644 --- 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 @@ -55,7 +55,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 index c34aad1ce770..2b982141d636 100644 --- 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 @@ -61,7 +61,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt index 0f0b3bee85d1..89e7b2a343bf 100644 --- a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt @@ -53,7 +53,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt index 2e5bc0d19d69..ecd6a3004900 100644 --- a/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-3-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt @@ -58,7 +58,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Order.kt index 0f0b3bee85d1..89e7b2a343bf 100644 --- a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Order.kt @@ -53,7 +53,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Pet.kt index 2e5bc0d19d69..ecd6a3004900 100644 --- a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Pet.kt @@ -58,7 +58,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-4/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-4/src/main/kotlin/org/openapitools/model/Order.kt index 0f0b3bee85d1..89e7b2a343bf 100644 --- a/samples/server/petstore/kotlin-springboot-4/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-4/src/main/kotlin/org/openapitools/model/Order.kt @@ -53,7 +53,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-4/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-4/src/main/kotlin/org/openapitools/model/Pet.kt index 2e5bc0d19d69..ecd6a3004900 100644 --- a/samples/server/petstore/kotlin-springboot-4/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-4/src/main/kotlin/org/openapitools/model/Pet.kt @@ -58,7 +58,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/model/Order.kt index 0f0b3bee85d1..89e7b2a343bf 100644 --- a/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/model/Order.kt @@ -53,7 +53,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/model/Pet.kt index eacd4bb4972d..ec96343526db 100644 --- a/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-additionalproperties/src/main/kotlin/org/openapitools/model/Pet.kt @@ -58,7 +58,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Order.kt index 061eb4eb25d1..421fba2bc288 100644 --- a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Order.kt @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Pet.kt index 17e286dfec05..6c697505209a 100644 --- a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Pet.kt @@ -65,7 +65,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 bf762a03281c..9e29b16a1d27 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 @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 a5e465fe87bb..bf7fe3ba7e30 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 @@ -65,7 +65,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Cat.kt b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Cat.kt index 8bdc14b3f5a0..0a473c42c892 100644 --- a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Cat.kt +++ b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Cat.kt @@ -21,8 +21,15 @@ import io.swagger.annotations.ApiModelProperty /** * + * @param name + * @param photoUrls + * @param petType * @param hunts * @param age + * @param id + * @param category + * @param tags + * @param color */ data class Cat( diff --git a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Dog.kt b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Dog.kt index b7e3769d4f7f..5f78da36f834 100644 --- a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Dog.kt +++ b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Dog.kt @@ -24,6 +24,13 @@ import io.swagger.annotations.ApiModelProperty * @param bark * @param breed * @param likesFetch Whether the dog enjoys fetching + * @param name + * @param photoUrls + * @param petType + * @param id + * @param category + * @param tags + * @param color */ data class Dog( @@ -77,7 +84,7 @@ data class Dog( @JsonCreator fun forValue(value: kotlin.String): Breed { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Dog'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Breed'") } } } diff --git a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Order.kt index 4bcfa0d4f201..59ff0e5d49cf 100644 --- a/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Order.kt @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/model/ApiError.kt b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/model/ApiError.kt index a4505462941f..fc9125438859 100644 --- a/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/model/ApiError.kt +++ b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/model/ApiError.kt @@ -42,7 +42,7 @@ data class ApiError( @JsonCreator fun forValue(value: kotlin.Int): ErrorCode { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'ApiError'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'ErrorCode'") } } } 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 8a674d72ff31..bb277f934a55 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 @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 24755152a4ba..f3b940591d40 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 @@ -64,7 +64,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Order.kt index 6b034dcbd95c..3837fc6822be 100644 --- a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Order.kt @@ -53,7 +53,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Pet.kt index 23ee20b45ad8..6bf5e554c941 100644 --- a/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-no-response-entity-delegate/src/main/kotlin/org/openapitools/model/Pet.kt @@ -57,7 +57,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt index 6b034dcbd95c..3837fc6822be 100644 --- a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Order.kt @@ -53,7 +53,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt index 23ee20b45ad8..6bf5e554c941 100644 --- a/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-no-response-entity/src/main/kotlin/org/openapitools/model/Pet.kt @@ -57,7 +57,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Order.kt index bf762a03281c..9e29b16a1d27 100644 --- a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Order.kt @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Pet.kt index a5e465fe87bb..bf7fe3ba7e30 100644 --- a/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-reactive-without-flow/src/main/kotlin/org/openapitools/model/Pet.kt @@ -65,7 +65,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 bf762a03281c..9e29b16a1d27 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 @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 a5e465fe87bb..bf7fe3ba7e30 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 @@ -65,7 +65,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Cat.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Cat.kt index b95dcea62816..7ff41fa0b477 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Cat.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Cat.kt @@ -16,7 +16,9 @@ import io.swagger.v3.oas.annotations.media.Schema /** * + * @param className * @param declawed + * @param color */ data class Cat( diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Dog.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Dog.kt index 64c523f06df5..883bf9c5d6b8 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Dog.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Dog.kt @@ -16,7 +16,9 @@ import io.swagger.v3.oas.annotations.media.Schema /** * + * @param className * @param breed + * @param color */ data class Dog( diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Order.kt index 23b9fb66c8e2..bfa82f37b53e 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Order.kt @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Pet.kt index fe1d8ab00905..b7fafeffcd87 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Pet.kt @@ -64,7 +64,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 index 070d17372ab1..be36c58d3a54 100644 --- 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 @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 index d2d474e56026..006e3b29ac02 100644 --- 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 @@ -64,7 +64,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 index 90133d570186..92c4a5fea678 100644 --- 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 @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 index f32079718483..2e3073226b2c 100644 --- 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 @@ -64,7 +64,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } diff --git a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Cat.kt b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Cat.kt index 8bdc14b3f5a0..0a473c42c892 100644 --- a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Cat.kt +++ b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Cat.kt @@ -21,8 +21,15 @@ import io.swagger.annotations.ApiModelProperty /** * + * @param name + * @param photoUrls + * @param petType * @param hunts * @param age + * @param id + * @param category + * @param tags + * @param color */ data class Cat( diff --git a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Dog.kt b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Dog.kt index 53df2c21f79b..30027815fb0d 100644 --- a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Dog.kt +++ b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Dog.kt @@ -24,6 +24,13 @@ import io.swagger.annotations.ApiModelProperty * @param bark * @param breed * @param likesFetch Whether the dog enjoys fetching + * @param name + * @param photoUrls + * @param petType + * @param id + * @param category + * @param tags + * @param color */ data class Dog( @@ -77,7 +84,7 @@ data class Dog( @JsonCreator fun forValue(value: kotlin.String): Breed { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Dog'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Breed'") } } } diff --git a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Order.kt index 4bcfa0d4f201..59ff0e5d49cf 100644 --- a/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Order.kt @@ -60,7 +60,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 6b034dcbd95c..3837fc6822be 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 @@ -53,7 +53,7 @@ data class Order( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Order'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } } 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 23ee20b45ad8..6bf5e554c941 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 @@ -57,7 +57,7 @@ data class Pet( @JsonCreator fun forValue(value: kotlin.String): Status { return values().firstOrNull{it -> it.value == value} - ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Pet'") + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'Status'") } } }