diff --git a/.github/workflows/samples-kotlin-client.yaml b/.github/workflows/samples-kotlin-client.yaml index 7a3fb62e8ddc..5bdb89052933 100644 --- a/.github/workflows/samples-kotlin-client.yaml +++ b/.github/workflows/samples-kotlin-client.yaml @@ -71,6 +71,7 @@ jobs: - samples/client/others/kotlin-jvm-okhttp-path-comments - samples/client/others/kotlin-integer-enum - samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization + - samples/client/others/kotlin-oneOf-discriminator steps: - uses: actions/checkout@v5 - uses: actions/setup-java@v5 diff --git a/bin/configs/kotlin-oneOf-discriminator.yaml b/bin/configs/kotlin-oneOf-discriminator.yaml new file mode 100644 index 000000000000..c06502007549 --- /dev/null +++ b/bin/configs/kotlin-oneOf-discriminator.yaml @@ -0,0 +1,11 @@ +generatorName: kotlin +library: jvm-spring-restclient +outputDir: samples/client/others/kotlin-oneOf-discriminator +inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/oneOf-with-discriminator-mapping.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-client +additionalProperties: + artifactId: kotlin-oneOf-discriminator + serializableModel: "false" + dateLibrary: java8 + useSpringBoot3: true + serializationLibrary: jackson diff --git a/docs/generators/kotlin.md b/docs/generators/kotlin.md index ae2675a51de7..7cd249d576ec 100644 --- a/docs/generators/kotlin.md +++ b/docs/generators/kotlin.md @@ -59,6 +59,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl | Extension name | Description | Applicable for | Default value | | -------------- | ----------- | -------------- | ------------- | +|x-kotlin-implements|Ability to specify interfaces that model must implement|MODEL|empty array +|x-kotlin-implements-fields|Specify attributes that are implemented by the interface(s) added via `x-kotlin-implements`|MODEL|empty array |x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null |x-field-extra-annotation|List of custom annotations to be added to property|FIELD, OPERATION_PARAMETER|null diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/VendorExtension.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/VendorExtension.java index 70aa9ce222b1..b1ce1f57503c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/VendorExtension.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/VendorExtension.java @@ -26,8 +26,7 @@ public enum VendorExtension { X_OPERATION_EXTRA_ANNOTATION("x-operation-extra-annotation", ExtensionLevel.OPERATION, "List of custom annotations to be added to operation", null), X_VERSION_PARAM("x-version-param", ExtensionLevel.OPERATION_PARAMETER, "Marker property that tells that this parameter would be used for endpoint versioning. Applicable for headers & query params. true/false", null), X_PATTERN_MESSAGE("x-pattern-message", Arrays.asList(ExtensionLevel.FIELD, ExtensionLevel.OPERATION_PARAMETER), "Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable", null), - X_ZERO_BASED_ENUM("x-zero-based-enum", ExtensionLevel.MODEL, "When used on an enum, the index will not be generated and the default numbering will be used, zero-based", "false"), - ; + X_ZERO_BASED_ENUM("x-zero-based-enum", ExtensionLevel.MODEL, "When used on an enum, the index will not be generated and the default numbering will be used, zero-based", "false"); private final String name; private final List levels; 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 e637234fb0f6..d0046bd1636c 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 @@ -828,23 +828,13 @@ protected boolean isReservedWord(String word) { protected boolean needToImport(String type) { // provides extra protection against improperly trying to import language primitives and java types return !type.startsWith("kotlin.") && !type.startsWith("java.") && - !defaultIncludes.contains(type) && !languageSpecificPrimitives.contains(type) && - !type.contains("."); + !defaultIncludes.contains(type) && !languageSpecificPrimitives.contains(type) && + !type.contains("."); } @Override public CodegenModel fromModel(String name, Schema schema) { CodegenModel m = super.fromModel(name, schema); - List implementedInterfacesClasses = (List) m.getVendorExtensions().getOrDefault(VendorExtension.X_KOTLIN_IMPLEMENTS.getName(), List.of()); - List implementedInterfacesFields = Optional.ofNullable((List) m.getVendorExtensions().get(VendorExtension.X_KOTLIN_IMPLEMENTS_FIELDS.getName())) - .map(xKotlinImplementsFields -> { - if (implementedInterfacesClasses.isEmpty() && !xKotlinImplementsFields.isEmpty()) { - LOGGER.warn("Annotating {} with {} without {} is not supported. {} will be ignored.", - name, VendorExtension.X_KOTLIN_IMPLEMENTS_FIELDS.getName(), VendorExtension.X_KOTLIN_IMPLEMENTS.getName(), - VendorExtension.X_KOTLIN_IMPLEMENTS_FIELDS.getName()); - } - return xKotlinImplementsFields; - }).orElse(List.of()); m.optionalVars = m.optionalVars.stream().distinct().collect(Collectors.toList()); // Update allVars/requiredVars/optionalVars with isInherited // Each of these lists contains elements that are similar, but they are all cloned @@ -860,11 +850,9 @@ public CodegenModel fromModel(String name, Schema schema) { // Update any other vars (requiredVars, optionalVars) Stream.of(m.requiredVars, m.optionalVars) .flatMap(List::stream) - .filter(p -> allVarsMap.containsKey(p.baseName) - || implementedInterfacesFields.contains(p.baseName) - ) + .filter(p -> allVarsMap.containsKey(p.baseName)) .forEach(p -> p.isInherited = true); - return m; + return addIsInheritedBasedOnImplementsVendorExtension(name, m); } @Override @@ -1172,4 +1160,44 @@ protected void doDataTypeAssignment(final String returnType, DataTypeAssigner da } } } + + /** + * Uses the x-kotlin-implements and the x-kotlin-implements-fields vendor extensions to set the isInherited CodegenProperty field. + * Will log a warning if an invalid vendor extension combination is used. + * @param name The name + * @param codegenModel The codegenModel + * @return The modified CodegenModel where isInherited has been added to the var CodegenProperty + */ + private CodegenModel addIsInheritedBasedOnImplementsVendorExtension(String name, CodegenModel codegenModel) { + String warningMessage = "Annotating {} with {} without {} is not supported. {} will be ignored."; + String kotlinImplements = VendorExtension.X_KOTLIN_IMPLEMENTS.getName(); + String kotlinImplementsFields = VendorExtension.X_KOTLIN_IMPLEMENTS_FIELDS.getName(); + Map vendorExtensions = codegenModel.getVendorExtensions(); + List implementedInterfacesClasses = (List) vendorExtensions.getOrDefault(kotlinImplements, List.of()); + List implementedInterfacesFields = Optional.ofNullable((List) vendorExtensions.get(kotlinImplementsFields)) + .map(xKotlinImplementsFields -> { + if (implementedInterfacesClasses.isEmpty() && !xKotlinImplementsFields.isEmpty()) { + LOGGER.warn(warningMessage, name, + kotlinImplementsFields, + kotlinImplements, + kotlinImplementsFields + ); + } + return xKotlinImplementsFields; + }) + .orElse(List.of()); + codegenModel.optionalVars.stream() + .filter(p -> implementedInterfacesFields.contains(p.baseName)) + .forEach(p -> p.isInherited = true); + codegenModel.requiredVars.stream() + .filter(p -> implementedInterfacesFields.contains(p.baseName)) + .forEach(p -> p.isInherited = true); + codegenModel.allVars.stream() + .filter(p -> implementedInterfacesFields.contains(p.baseName)) + .forEach(p -> p.isInherited = true); + codegenModel.vars.stream() + .filter(p -> implementedInterfacesFields.contains(p.baseName)) + .forEach(p -> p.isInherited = true); + return codegenModel; + } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java index 29d315e2f74a..94ac45197a9a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java @@ -1128,6 +1128,8 @@ public void postProcess() { @Override public List getSupportedVendorExtensions() { var extensions = super.getSupportedVendorExtensions(); + extensions.add(VendorExtension.X_KOTLIN_IMPLEMENTS); + extensions.add(VendorExtension.X_KOTLIN_IMPLEMENTS_FIELDS); extensions.add(VendorExtension.X_CLASS_EXTRA_ANNOTATION); extensions.add(VendorExtension.X_FIELD_EXTRA_ANNOTATION); return extensions; diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache index 564ce0214e50..5b8f8fd15998 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache @@ -108,7 +108,7 @@ import {{packageName}}.infrastructure.ITransformForStorage {{#required}}{{>data_class_req_var}}{{/required}}{{^required}}{{>data_class_opt_var}}{{/required}}{{^-last}},{{/-last}} {{/allVars}} -){{/discriminator}}{{#parent}}{{^serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#kotlinx_serialization}}(){{/kotlinx_serialization}}{{#multiplatform}}(){{/multiplatform}}{{#isArray}}(){{/isArray}}{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{^serializableModel}}{{#parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{#parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{^parcelizeModels}} : Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{#parcelizeModels}} : Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#generateRoomModels}}{{#parent}}, {{/parent}}{{^discriminator}}{{^parent}}:{{/parent}} ITransformForStorage<{{classname}}RoomModel>{{/discriminator}}{{/generateRoomModels}}{{#vendorExtensions.x-has-data-class-body}} { +){{/discriminator}}{{#vendorExtensions.x-kotlin-implements}} : {{{.}}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-kotlin-implements}}{{#parent}}{{^serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#kotlinx_serialization}}(){{/kotlinx_serialization}}{{#multiplatform}}(){{/multiplatform}}{{#isArray}}(){{/isArray}}{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{^serializableModel}}{{#parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{#parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{^parcelizeModels}} : Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{#parcelizeModels}} : Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#generateRoomModels}}{{#parent}}, {{/parent}}{{^discriminator}}{{^parent}}:{{/parent}} ITransformForStorage<{{classname}}RoomModel>{{/discriminator}}{{/generateRoomModels}}{{#vendorExtensions.x-has-data-class-body}} { {{/vendorExtensions.x-has-data-class-body}} {{#generateRoomModels}} companion object { } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java index 3e1ed97b5a32..f2720906505c 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java @@ -47,6 +47,8 @@ @SuppressWarnings("static-method") public class KotlinClientCodegenModelTest { + private static final String GENERATOR = "kotlin"; + private Schema getArrayTestSchema() { return new ObjectSchema() .description("a sample model") @@ -367,7 +369,7 @@ public void testNativeClientExplodedQueryParamObject() throws IOException { output.deleteOnExit(); final CodegenConfigurator configurator = new CodegenConfigurator() - .setGeneratorName("kotlin") + .setGeneratorName(GENERATOR) .setLibrary("jvm-retrofit2") .setAdditionalProperties(properties) .setInputSpec("src/test/resources/3_0/issue4808.yaml") @@ -384,24 +386,22 @@ public void testNativeClientExplodedQueryParamObject() throws IOException { } @Test - public void testOmitGradleWrapperDoesNotGenerateWrapper() throws IOException { - File output = Files.createTempDirectory("test").toFile(); - String path = output.getAbsolutePath(); - output.deleteOnExit(); + public void testOmitGradleWrapperDoesNotGenerateWrapper() { + final Path output = TestUtils.newTempFolder(); final CodegenConfigurator configurator = new CodegenConfigurator() - .setGeneratorName("kotlin") + .setGeneratorName(GENERATOR) .setInputSpec("src/test/resources/3_0/ping.yaml") .addAdditionalProperty("omitGradleWrapper", true) - .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + .setOutputDir(output.toString().replace("\\", "/")); DefaultGenerator generator = new DefaultGenerator(); generator.opts(configurator.toClientOptInput()).generate(); - TestUtils.assertFileNotExists(Paths.get(path, "gradlew")); - TestUtils.assertFileNotExists(Paths.get(path, "gradlew.bat")); - TestUtils.assertFileNotExists(Paths.get(path, "gradle", "wrapper", "gradle-wrapper.properties")); - TestUtils.assertFileNotExists(Paths.get(path, "gradle", "wrapper", "gradle-wrapper.jar")); + TestUtils.assertFileNotExists(Paths.get(output.toString(), "gradlew")); + TestUtils.assertFileNotExists(Paths.get(output.toString(), "gradlew.bat")); + TestUtils.assertFileNotExists(Paths.get(output.toString(), "gradle", "wrapper", "gradle-wrapper.properties")); + TestUtils.assertFileNotExists(Paths.get(output.toString(), "gradle", "wrapper", "gradle-wrapper.jar")); } @Test @@ -444,12 +444,10 @@ public Object[][] pathResponses() { @Test(dataProvider = "gsonClientLibraries") public void testLocalVariablesUseSanitizedDataTypeNamesForOneOfProperty_19942(ClientLibrary clientLibrary) throws IOException { - File output = Files.createTempDirectory("test").toFile(); - String path = output.getAbsolutePath(); - output.deleteOnExit(); + final Path output = TestUtils.newTempFolder(); final CodegenConfigurator configurator = new CodegenConfigurator() - .setGeneratorName("kotlin") + .setGeneratorName(GENERATOR) .setLibrary(clientLibrary.getLibraryName()) .setInputSpec("src/test/resources/3_0/issue_19942.json") .addAdditionalProperty("omitGradleWrapper", true) @@ -457,23 +455,21 @@ public void testLocalVariablesUseSanitizedDataTypeNamesForOneOfProperty_19942(Cl .addAdditionalProperty("dateLibrary", "kotlinx-datetime") .addAdditionalProperty("useSpringBoot3", "true") .addAdditionalProperty("generateOneOfAnyOfWrappers", true) - .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + .setOutputDir(output.toString().replace("\\", "/")); DefaultGenerator generator = new DefaultGenerator(); generator.opts(configurator.toClientOptInput()).generate(); - TestUtils.assertFileNotContains(Paths.get(path + "/src/" + clientLibrary.getSourceRoot() + "/org/openapitools/client/models/ObjectWithComplexOneOfId.kt"), + TestUtils.assertFileNotContains(Paths.get(output + "/src/" + clientLibrary.getSourceRoot() + "/org/openapitools/client/models/ObjectWithComplexOneOfId.kt"), "val adapterkotlin.String", "val adapterjava.math.BigDecimal"); } @Test(dataProvider = "gsonClientLibraries") public void testLocalVariablesUseSanitizedDataTypeNamesForAnyOfProperty_19942(ClientLibrary clientLibrary) throws IOException { - File output = Files.createTempDirectory("test").toFile(); - String path = output.getAbsolutePath(); - output.deleteOnExit(); + final Path output = TestUtils.newTempFolder(); final CodegenConfigurator configurator = new CodegenConfigurator() - .setGeneratorName("kotlin") + .setGeneratorName(GENERATOR) .setLibrary(clientLibrary.getLibraryName()) .setInputSpec("src/test/resources/3_0/issue_19942.json") .addAdditionalProperty("omitGradleWrapper", true) @@ -481,22 +477,21 @@ public void testLocalVariablesUseSanitizedDataTypeNamesForAnyOfProperty_19942(Cl .addAdditionalProperty("dateLibrary", "kotlinx-datetime") .addAdditionalProperty("useSpringBoot3", "true") .addAdditionalProperty("generateOneOfAnyOfWrappers", true) - .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + .setOutputDir(output.toString().replace("\\", "/")); DefaultGenerator generator = new DefaultGenerator(); generator.opts(configurator.toClientOptInput()).generate(); - TestUtils.assertFileNotContains(Paths.get(path + "/src/" + clientLibrary.getSourceRoot() + "/org/openapitools/client/models/ObjectWithComplexAnyOfId.kt"), + TestUtils.assertFileNotContains(Paths.get(output + "/src/" + clientLibrary.getSourceRoot() + "/org/openapitools/client/models/ObjectWithComplexAnyOfId.kt"), "val adapterkotlin.String", "val adapterjava.math.BigDecimal"); } @Test(description = "Issue #20960") private void givenSchemaObjectPropertyNameContainsDollarSignWhenGenerateThenDollarSignIsProperlyEscapedInAnnotation() throws Exception { - File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); - output.deleteOnExit(); + final Path output = TestUtils.newTempFolder(); KotlinClientCodegen codegen = new KotlinClientCodegen(); - codegen.setOutputDir(output.getAbsolutePath()); + codegen.setOutputDir(output.toString()); Map properties = new HashMap<>(); // properties.put(CodegenConstants.LIBRARY, ClientLibrary.JVM_KTOR); properties.put(CodegenConstants.ENUM_PROPERTY_NAMING, CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.UPPERCASE.toString()); @@ -512,7 +507,7 @@ private void givenSchemaObjectPropertyNameContainsDollarSignWhenGenerateThenDoll .config(codegen)) .generate(); - String outputPath = output.getAbsolutePath() + "/src/main/kotlin/com/toasttab/service/scim"; + String outputPath = output + "/src/main/kotlin/com/toasttab/service/scim"; Path baseGroupModel = Paths.get(outputPath + "/models/BaseGroupMembersInner.kt"); String baseGroupModelContent = Files.readString(baseGroupModel); KotlinLexer kotlinLexer = new KotlinLexer(CharStreams.fromString(baseGroupModelContent)); @@ -530,19 +525,18 @@ private void givenSchemaObjectPropertyNameContainsDollarSignWhenGenerateThenDoll } @Test(description = "generate polymorphic kotlinx_serialization model") - public void polymorphicKotlinxSerialization() throws IOException { - File output = Files.createTempDirectory("test").toFile(); - output.deleteOnExit(); + public void polymorphicKotlinxSerialization() { + final Path output = TestUtils.newTempFolder(); final CodegenConfigurator configurator = new CodegenConfigurator() - .setGeneratorName("kotlin") + .setGeneratorName(GENERATOR) .setLibrary("jvm-retrofit2") .setAdditionalProperties(new HashMap<>() {{ put(CodegenConstants.SERIALIZATION_LIBRARY, "kotlinx_serialization"); put(CodegenConstants.MODEL_PACKAGE, "xyz.abcdef.model"); }}) .setInputSpec("src/test/resources/3_0/kotlin/polymorphism.yaml") - .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + .setOutputDir(output.toString().replace("\\", "/")); final ClientOptInput clientOptInput = configurator.toClientOptInput(); DefaultGenerator generator = new DefaultGenerator(); @@ -563,7 +557,7 @@ public void polymorphicKotlinxSerialization() throws IOException { TestUtils.assertFileContains(animalKt, "import kotlinx.serialization.json.JsonClassDiscriminator"); final Path birdKt = Paths.get(output + "/src/main/kotlin/xyz/abcdef/model/Bird.kt"); - // derived doesn't contain disciminator + // derived doesn't contain discriminator TestUtils.assertFileNotContains(birdKt, "val discriminator"); // derived has serial name set to mapping key TestUtils.assertFileContains(birdKt, "@SerialName(value = \"BIRD\")"); @@ -571,18 +565,17 @@ public void polymorphicKotlinxSerialization() throws IOException { @Test(description = "generate polymorphic jackson model") public void polymorphicJacksonSerialization() throws IOException { - File output = Files.createTempDirectory("test").toFile(); -// output.deleteOnExit(); + final Path output = TestUtils.newTempFolder(); final CodegenConfigurator configurator = new CodegenConfigurator() - .setGeneratorName("kotlin") + .setGeneratorName(GENERATOR) .setLibrary("jvm-okhttp4") .setAdditionalProperties(new HashMap<>() {{ put(CodegenConstants.SERIALIZATION_LIBRARY, "jackson"); put(CodegenConstants.MODEL_PACKAGE, "xyz.abcdef.model"); }}) .setInputSpec("src/test/resources/3_0/kotlin/polymorphism.yaml") - .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + .setOutputDir(output.toString().replace("\\", "/")); final ClientOptInput clientOptInput = configurator.toClientOptInput(); DefaultGenerator generator = new DefaultGenerator(); @@ -613,10 +606,39 @@ public void polymorphicJacksonSerialization() throws IOException { // derived properties are overridden TestUtils.assertFileContains(birdKt, "override val id"); TestUtils.assertFileContains(birdKt, "override val optionalProperty"); - // derived doesn't contain disciminator + // derived doesn't contain discriminator TestUtils.assertFileNotContains(birdKt, "val discriminator"); } + @Test + public void oneOfWithXKotlinImplementsVendorExtension() { + final Path output = TestUtils.newTempFolder(); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName(GENERATOR) + .setLibrary("jvm-spring-restclient") + .setAdditionalProperties(new HashMap<>() {{ + put(CodegenConstants.SERIALIZATION_LIBRARY, "jackson"); + put("useSpringBoot3", true); + put(CodegenConstants.MODEL_PACKAGE, "xyz.abcdef.model"); + }}) + .setInputSpec("src/test/resources/3_0/kotlin/oneOf-with-discriminator-mapping.yaml") + .setOutputDir(output.toString().replace("\\", "/")); + + List files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + + Assert.assertEquals(files.size(), 40); + + Path child1 = output.resolve("src/main/kotlin/xyz/abcdef/model/Child1.kt"); + Path child2 = output.resolve("src/main/kotlin/xyz/abcdef/model/Child2.kt"); + + TestUtils.assertFileContains(child1, "data class Child1 ("); + TestUtils.assertFileContains(child1, ") : WithoutAllOfEndpoint200Response {"); + TestUtils.assertFileContains(child1, "override val jobType: kotlin.String? = null"); + TestUtils.assertFileContains(child2, "data class Child2 ("); + TestUtils.assertFileContains(child2, ") : WithoutAllOfEndpoint200Response {"); + TestUtils.assertFileContains(child2, "override val jobType: kotlin.String? = null"); + } + private static class ModelNameTest { private final String expectedName; private final String expectedClassName; diff --git a/modules/openapi-generator/src/test/resources/3_0/kotlin/oneOf-with-discriminator-mapping.yaml b/modules/openapi-generator/src/test/resources/3_0/kotlin/oneOf-with-discriminator-mapping.yaml new file mode 100644 index 000000000000..479e93017e77 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/kotlin/oneOf-with-discriminator-mapping.yaml @@ -0,0 +1,83 @@ +openapi: 3.0.1 +info: + title: some + version: 1.0.0 +servers: + - url: http://localhost:8080 + description: Local server +paths: + "/one-of-with-without-all-of-inheritance": + get: + operationId: WithoutAllOfEndpoint + responses: + '200': + description: Success + content: + application/json: + schema: + oneOf: + - "$ref": "#/components/schemas/Child1" + - "$ref": "#/components/schemas/Child2" + discriminator: + propertyName: jobType + mapping: + Child1: "#/components/schemas/Child1" + Child2: "#/components/schemas/Child2" + "/one-of-with-all-of-inheritance": + get: + operationId: WithAllOfEndpoint + responses: + '200': + description: Success + content: + application/json: + schema: + oneOf: + - "$ref": "#/components/schemas/AllOfChild1" + - "$ref": "#/components/schemas/AllOfChild2" + discriminator: + propertyName: jobType + mapping: + AllOfChild1: "#/components/schemas/AllOfChild1" + AllOfChild2: "#/components/schemas/AllOfChild2" +components: + schemas: + Child1: + x-kotlin-implements: [ "WithoutAllOfEndpoint200Response" ] + x-kotlin-implements-fields: [ "jobType" ] + type: object + properties: + jobType: + type: string + property1: + type: string + Child2: + x-kotlin-implements: [ "WithoutAllOfEndpoint200Response" ] + x-kotlin-implements-fields: [ "jobType" ] + type: object + properties: + jobType: + type: string + property2: + type: string + Parent: + type: object + properties: + jobType: + type: string + discriminator: + propertyName: jobType + AllOfChild1: + allOf: + - $ref: "#/components/schemas/Parent" + - type: object + properties: + property1: + type: string + AllOfChild2: + allOf: + - $ref: "#/components/schemas/Parent" + - type: object + properties: + property2: + type: string \ No newline at end of file diff --git a/samples/client/others/kotlin-oneOf-discriminator/.openapi-generator-ignore b/samples/client/others/kotlin-oneOf-discriminator/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/others/kotlin-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/client/others/kotlin-oneOf-discriminator/.openapi-generator/FILES b/samples/client/others/kotlin-oneOf-discriminator/.openapi-generator/FILES new file mode 100644 index 000000000000..97d46fc6df4a --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/.openapi-generator/FILES @@ -0,0 +1,29 @@ +README.md +build.gradle +docs/AllOfChild1.md +docs/AllOfChild2.md +docs/Child1.md +docs/Child2.md +docs/DefaultApi.md +docs/Parent.md +docs/WithAllOfEndpoint200Response.md +docs/WithoutAllOfEndpoint200Response.md +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +settings.gradle +src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt +src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt +src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +src/main/kotlin/org/openapitools/client/models/AllOfChild1.kt +src/main/kotlin/org/openapitools/client/models/AllOfChild2.kt +src/main/kotlin/org/openapitools/client/models/Child1.kt +src/main/kotlin/org/openapitools/client/models/Child2.kt +src/main/kotlin/org/openapitools/client/models/Parent.kt +src/main/kotlin/org/openapitools/client/models/WithAllOfEndpoint200Response.kt +src/main/kotlin/org/openapitools/client/models/WithoutAllOfEndpoint200Response.kt diff --git a/samples/client/others/kotlin-oneOf-discriminator/.openapi-generator/VERSION b/samples/client/others/kotlin-oneOf-discriminator/.openapi-generator/VERSION new file mode 100644 index 000000000000..5e5282953086 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.16.0-SNAPSHOT diff --git a/samples/client/others/kotlin-oneOf-discriminator/README.md b/samples/client/others/kotlin-oneOf-discriminator/README.md new file mode 100644 index 000000000000..21989146fbf5 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/README.md @@ -0,0 +1,68 @@ +# org.openapitools.client - Kotlin client library for some + +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Package version: +- Generator version: 7.16.0-SNAPSHOT +- Build package: org.openapitools.codegen.languages.KotlinClientCodegen + +## Requires + +* Kotlin 2.2.20 +* Gradle 8.14 + +## Build + +First, create the gradle wrapper script: + +``` +gradle wrapper +``` + +Then, run: + +``` +./gradlew check assemble +``` + +This runs all tests and packages the library. + +## Features/Implementation Notes + +* Supports JSON inputs/outputs, File inputs, and Form inputs. +* Supports collection formats for query parameters: csv, tsv, ssv, pipes. +* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions. +* Implementation of ApiClient is intended to reduce method counts, specifically to benefit Android targets. + + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost:8080* + +| Class | Method | HTTP request | Description | +| ------------ | ------------- | ------------- | ------------- | +| *DefaultApi* | [**withAllOfEndpoint**](docs/DefaultApi.md#withallofendpoint) | **GET** /one-of-with-all-of-inheritance | | +| *DefaultApi* | [**withoutAllOfEndpoint**](docs/DefaultApi.md#withoutallofendpoint) | **GET** /one-of-with-without-all-of-inheritance | | + + + +## Documentation for Models + + - [org.openapitools.client.models.AllOfChild1](docs/AllOfChild1.md) + - [org.openapitools.client.models.AllOfChild2](docs/AllOfChild2.md) + - [org.openapitools.client.models.Child1](docs/Child1.md) + - [org.openapitools.client.models.Child2](docs/Child2.md) + - [org.openapitools.client.models.Parent](docs/Parent.md) + - [org.openapitools.client.models.WithAllOfEndpoint200Response](docs/WithAllOfEndpoint200Response.md) + - [org.openapitools.client.models.WithoutAllOfEndpoint200Response](docs/WithoutAllOfEndpoint200Response.md) + + + +## Documentation for Authorization + +Endpoints do not require authorization. + diff --git a/samples/client/others/kotlin-oneOf-discriminator/build.gradle b/samples/client/others/kotlin-oneOf-discriminator/build.gradle new file mode 100644 index 000000000000..dde9b1789935 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/build.gradle @@ -0,0 +1,68 @@ +group 'org.openapitools' +version '1.0.0' + +wrapper { + gradleVersion = '8.14.3' + distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" +} + +buildscript { + ext.kotlin_version = '2.2.20' + ext.spring_boot_version = "3.5.5" + ext.spotless_version = "7.2.1" + + repositories { + maven { url "https://repo1.maven.org/maven2" } + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotless_version" + } +} + +apply plugin: 'kotlin' +apply plugin: 'maven-publish' +apply plugin: 'com.diffplug.spotless' + +repositories { + maven { url "https://repo1.maven.org/maven2" } +} + +// Use spotless plugin to automatically format code, remove unused import, etc +// To apply changes directly to the file, run `gradlew spotlessApply` +// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle +spotless { + // comment out below to run spotless as part of the `check` task + enforceCheck false + + format 'misc', { + // define the files (e.g. '*.gradle', '*.md') to apply `misc` to + target '.gitignore' + + // define the steps to apply to those files + trimTrailingWhitespace() + indentWithSpaces() // Takes an integer argument if you don't like 4 + endWithNewline() + } + kotlin { + ktfmt() + } +} + +test { + useJUnitPlatform() +} + +kotlin { + jvmToolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" + implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.20.0" + implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.20.0" + implementation "org.springframework.boot:spring-boot-starter-web:$spring_boot_version" + testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/docs/AllOfChild1.md b/samples/client/others/kotlin-oneOf-discriminator/docs/AllOfChild1.md new file mode 100644 index 000000000000..53bd898f7615 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/docs/AllOfChild1.md @@ -0,0 +1,10 @@ + +# AllOfChild1 + +## Properties +| Name | Type | Description | Notes | +| ------------ | ------------- | ------------- | ------------- | +| **property1** | **kotlin.String** | | [optional] | + + + diff --git a/samples/client/others/kotlin-oneOf-discriminator/docs/AllOfChild2.md b/samples/client/others/kotlin-oneOf-discriminator/docs/AllOfChild2.md new file mode 100644 index 000000000000..1f22220b4108 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/docs/AllOfChild2.md @@ -0,0 +1,10 @@ + +# AllOfChild2 + +## Properties +| Name | Type | Description | Notes | +| ------------ | ------------- | ------------- | ------------- | +| **property2** | **kotlin.String** | | [optional] | + + + diff --git a/samples/client/others/kotlin-oneOf-discriminator/docs/Child1.md b/samples/client/others/kotlin-oneOf-discriminator/docs/Child1.md new file mode 100644 index 000000000000..a746b2c0e69d --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/docs/Child1.md @@ -0,0 +1,11 @@ + +# Child1 + +## Properties +| Name | Type | Description | Notes | +| ------------ | ------------- | ------------- | ------------- | +| **jobType** | **kotlin.String** | | [optional] | +| **property1** | **kotlin.String** | | [optional] | + + + diff --git a/samples/client/others/kotlin-oneOf-discriminator/docs/Child2.md b/samples/client/others/kotlin-oneOf-discriminator/docs/Child2.md new file mode 100644 index 000000000000..028c70eaf0a6 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/docs/Child2.md @@ -0,0 +1,11 @@ + +# Child2 + +## Properties +| Name | Type | Description | Notes | +| ------------ | ------------- | ------------- | ------------- | +| **jobType** | **kotlin.String** | | [optional] | +| **property2** | **kotlin.String** | | [optional] | + + + diff --git a/samples/client/others/kotlin-oneOf-discriminator/docs/DefaultApi.md b/samples/client/others/kotlin-oneOf-discriminator/docs/DefaultApi.md new file mode 100644 index 000000000000..2ccf6dd724b7 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/docs/DefaultApi.md @@ -0,0 +1,92 @@ +# DefaultApi + +All URIs are relative to *http://localhost:8080* + +| Method | HTTP request | Description | +| ------------- | ------------- | ------------- | +| [**withAllOfEndpoint**](DefaultApi.md#withAllOfEndpoint) | **GET** /one-of-with-all-of-inheritance | | +| [**withoutAllOfEndpoint**](DefaultApi.md#withoutAllOfEndpoint) | **GET** /one-of-with-without-all-of-inheritance | | + + + +# **withAllOfEndpoint** +> WithAllOfEndpoint200Response withAllOfEndpoint() + + + +### Example +```kotlin +// Import classes: +//import org.openapitools.client.infrastructure.* +//import org.openapitools.client.models.* + +val apiInstance = DefaultApi() +try { + val result : WithAllOfEndpoint200Response = apiInstance.withAllOfEndpoint() + println(result) +} catch (e: ClientException) { + println("4xx response calling DefaultApi#withAllOfEndpoint") + e.printStackTrace() +} catch (e: ServerException) { + println("5xx response calling DefaultApi#withAllOfEndpoint") + e.printStackTrace() +} +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**WithAllOfEndpoint200Response**](WithAllOfEndpoint200Response.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + + +# **withoutAllOfEndpoint** +> WithoutAllOfEndpoint200Response withoutAllOfEndpoint() + + + +### Example +```kotlin +// Import classes: +//import org.openapitools.client.infrastructure.* +//import org.openapitools.client.models.* + +val apiInstance = DefaultApi() +try { + val result : WithoutAllOfEndpoint200Response = apiInstance.withoutAllOfEndpoint() + println(result) +} catch (e: ClientException) { + println("4xx response calling DefaultApi#withoutAllOfEndpoint") + e.printStackTrace() +} catch (e: ServerException) { + println("5xx response calling DefaultApi#withoutAllOfEndpoint") + e.printStackTrace() +} +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**WithoutAllOfEndpoint200Response**](WithoutAllOfEndpoint200Response.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + diff --git a/samples/client/others/kotlin-oneOf-discriminator/docs/Parent.md b/samples/client/others/kotlin-oneOf-discriminator/docs/Parent.md new file mode 100644 index 000000000000..9b9c57c2d855 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/docs/Parent.md @@ -0,0 +1,10 @@ + +# Parent + +## Properties +| Name | Type | Description | Notes | +| ------------ | ------------- | ------------- | ------------- | +| **jobType** | **kotlin.String** | | [optional] | + + + diff --git a/samples/client/others/kotlin-oneOf-discriminator/docs/WithAllOfEndpoint200Response.md b/samples/client/others/kotlin-oneOf-discriminator/docs/WithAllOfEndpoint200Response.md new file mode 100644 index 000000000000..2fa815849a63 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/docs/WithAllOfEndpoint200Response.md @@ -0,0 +1,12 @@ + +# WithAllOfEndpoint200Response + +## Properties +| Name | Type | Description | Notes | +| ------------ | ------------- | ------------- | ------------- | +| **jobType** | **kotlin.String** | | [optional] | +| **property1** | **kotlin.String** | | [optional] | +| **property2** | **kotlin.String** | | [optional] | + + + diff --git a/samples/client/others/kotlin-oneOf-discriminator/docs/WithoutAllOfEndpoint200Response.md b/samples/client/others/kotlin-oneOf-discriminator/docs/WithoutAllOfEndpoint200Response.md new file mode 100644 index 000000000000..db19e3a6bde5 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/docs/WithoutAllOfEndpoint200Response.md @@ -0,0 +1,12 @@ + +# WithoutAllOfEndpoint200Response + +## Properties +| Name | Type | Description | Notes | +| ------------ | ------------- | ------------- | ------------- | +| **jobType** | **kotlin.String** | | [optional] | +| **property1** | **kotlin.String** | | [optional] | +| **property2** | **kotlin.String** | | [optional] | + + + diff --git a/samples/client/others/kotlin-oneOf-discriminator/gradle/wrapper/gradle-wrapper.jar b/samples/client/others/kotlin-oneOf-discriminator/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..2c3521197d7c Binary files /dev/null and b/samples/client/others/kotlin-oneOf-discriminator/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/client/others/kotlin-oneOf-discriminator/gradle/wrapper/gradle-wrapper.properties b/samples/client/others/kotlin-oneOf-discriminator/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..7705927e949f --- /dev/null +++ b/samples/client/others/kotlin-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.14.3-all.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/client/others/kotlin-oneOf-discriminator/gradlew b/samples/client/others/kotlin-oneOf-discriminator/gradlew new file mode 100644 index 000000000000..51eb8bb47109 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/gradlew @@ -0,0 +1,252 @@ +#!/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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# 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/platforms/jvm/plugins-application/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 -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || 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/client/others/kotlin-oneOf-discriminator/gradlew.bat b/samples/client/others/kotlin-oneOf-discriminator/gradlew.bat new file mode 100644 index 000000000000..9d21a21834d5 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/gradlew.bat @@ -0,0 +1,94 @@ +@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 +@rem SPDX-License-Identifier: Apache-2.0 +@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/client/others/kotlin-oneOf-discriminator/settings.gradle b/samples/client/others/kotlin-oneOf-discriminator/settings.gradle new file mode 100644 index 000000000000..bdd710c62b9b --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'kotlin-oneOf-discriminator' diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt new file mode 100644 index 000000000000..c578807da84e --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -0,0 +1,110 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.apis + +import com.fasterxml.jackson.annotation.JsonProperty + +import org.springframework.web.client.RestClient +import org.springframework.web.client.RestClientResponseException + +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter +import org.springframework.http.ResponseEntity +import org.springframework.http.MediaType + + +import org.openapitools.client.models.WithAllOfEndpoint200Response +import org.openapitools.client.models.WithoutAllOfEndpoint200Response +import org.openapitools.client.infrastructure.* + +class DefaultApi(client: RestClient) : ApiClient(client) { + + constructor(baseUrl: String) : this(RestClient.builder() + .baseUrl(baseUrl) + .messageConverters { it.add(MappingJackson2HttpMessageConverter()) } + .build() + ) + + + @Throws(RestClientResponseException::class) + fun withAllOfEndpoint(): WithAllOfEndpoint200Response { + val result = withAllOfEndpointWithHttpInfo() + return result.body!! + } + + @Throws(RestClientResponseException::class) + fun withAllOfEndpointWithHttpInfo(): ResponseEntity { + val localVariableConfig = withAllOfEndpointRequestConfig() + return request( + localVariableConfig + ) + } + + fun withAllOfEndpointRequestConfig() : RequestConfig { + val localVariableBody = null + val localVariableQuery = mutableMapOf>() + val localVariableHeaders: MutableMap = mutableMapOf() + localVariableHeaders["Accept"] = "application/json" + + val params = mutableMapOf( + ) + + return RequestConfig( + method = RequestMethod.GET, + path = "/one-of-with-all-of-inheritance", + params = params, + query = localVariableQuery, + headers = localVariableHeaders, + requiresAuthentication = false, + body = localVariableBody + ) + } + + + @Throws(RestClientResponseException::class) + fun withoutAllOfEndpoint(): WithoutAllOfEndpoint200Response { + val result = withoutAllOfEndpointWithHttpInfo() + return result.body!! + } + + @Throws(RestClientResponseException::class) + fun withoutAllOfEndpointWithHttpInfo(): ResponseEntity { + val localVariableConfig = withoutAllOfEndpointRequestConfig() + return request( + localVariableConfig + ) + } + + fun withoutAllOfEndpointRequestConfig() : RequestConfig { + val localVariableBody = null + val localVariableQuery = mutableMapOf>() + val localVariableHeaders: MutableMap = mutableMapOf() + localVariableHeaders["Accept"] = "application/json" + + val params = mutableMapOf( + ) + + return RequestConfig( + method = RequestMethod.GET, + path = "/one-of-with-without-all-of-inheritance", + params = params, + query = localVariableQuery, + headers = localVariableHeaders, + requiresAuthentication = false, + body = localVariableBody + ) + } + +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt new file mode 100644 index 000000000000..7fe8da468374 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -0,0 +1,23 @@ +package org.openapitools.client.infrastructure + +typealias MultiValueMap = MutableMap> + +fun collectionDelimiter(collectionFormat: String): String = when(collectionFormat) { + "csv" -> "," + "tsv" -> "\t" + "pipe" -> "|" + "space" -> " " + else -> "" +} + +val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" } + +fun toMultiValue(items: Array, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List + = toMultiValue(items.asIterable(), collectionFormat, map) + +fun toMultiValue(items: Iterable, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List { + return when(collectionFormat) { + "multi" -> items.map(map) + else -> listOf(items.joinToString(separator = collectionDelimiter(collectionFormat), transform = map)) + } +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt new file mode 100644 index 000000000000..b1675a9ff649 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -0,0 +1,76 @@ +package org.openapitools.client.infrastructure; + +import org.springframework.core.ParameterizedTypeReference +import org.springframework.http.HttpHeaders +import org.springframework.http.HttpMethod +import org.springframework.http.MediaType +import org.springframework.web.client.RestClient +import org.springframework.http.ResponseEntity +import org.springframework.util.LinkedMultiValueMap + +open class ApiClient(protected val client: RestClient) { + + protected inline fun request(requestConfig: RequestConfig): ResponseEntity { + return prepare(defaults(requestConfig)) + .retrieve() + .toEntity(object : ParameterizedTypeReference() {}) + } + + protected fun prepare(requestConfig: RequestConfig) = + client.method(requestConfig) + .uri(requestConfig) + .headers(requestConfig) + .nullableBody(requestConfig) + + protected fun defaults(requestConfig: RequestConfig) = + requestConfig.apply { + if (body != null && headers[HttpHeaders.CONTENT_TYPE].isNullOrEmpty()) { + headers[HttpHeaders.CONTENT_TYPE] = MediaType.APPLICATION_JSON_VALUE + } + if (headers[HttpHeaders.ACCEPT].isNullOrEmpty()) { + headers[HttpHeaders.ACCEPT] = MediaType.APPLICATION_JSON_VALUE + } + } + + private fun RestClient.method(requestConfig: RequestConfig)= + method(HttpMethod.valueOf(requestConfig.method.name)) + + private fun RestClient.RequestBodyUriSpec.uri(requestConfig: RequestConfig) = + uri(requestConfig.path) { builder -> + builder + .queryParams(LinkedMultiValueMap(requestConfig.query)) + .build(requestConfig.params) + } + + private fun RestClient.RequestBodySpec.headers(requestConfig: RequestConfig) = + apply { requestConfig.headers.forEach { (name, value) -> header(name, value) } } + + private fun RestClient.RequestBodySpec.nullableBody(requestConfig: RequestConfig): RestClient.RequestBodySpec { + when { + requestConfig.headers[HttpHeaders.CONTENT_TYPE] == MediaType.MULTIPART_FORM_DATA_VALUE -> { + val parts = LinkedMultiValueMap() + @Suppress("UNCHECKED_CAST") + (requestConfig.body as Map>).forEach { (name, part) -> + if (part.body != null) { + parts.add(name, part.body) + } + } + return apply { body(parts) } + } + + else -> { + return apply { if (requestConfig.body != null) body(requestConfig.body) } + } + } + } +} + +inline fun parseDateToQueryString(value : T): String { + /* + .replace("\"", "") converts the json object string to an actual string for the query parameter. + The moshi or gson adapter allows a more generic solution instead of trying to use a native + formatter. It also easily allows to provide a simple way to define a custom date format pattern + inside a gson/moshi adapter. + */ + return Serializer.jacksonObjectMapper.writeValueAsString(value).replace("\"", "") + } diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt new file mode 100644 index 000000000000..be00e38fbaee --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt @@ -0,0 +1,11 @@ +package org.openapitools.client.infrastructure + +/** + * Defines a config object for a given part of a multi-part request. + * NOTE: Headers is a Map because rfc2616 defines + * multi-valued headers as csv-only. + */ +data class PartConfig( + val headers: MutableMap = mutableMapOf(), + val body: T? = null +) diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt new file mode 100644 index 000000000000..6578b9381b78 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -0,0 +1,19 @@ +package org.openapitools.client.infrastructure + +/** + * Defines a config object for a given request. + * NOTE: This object doesn't include 'body' because it + * allows for caching of the constructed object + * for many request definitions. + * NOTE: Headers is a Map because rfc2616 defines + * multi-valued headers as csv-only. + */ +data class RequestConfig( + val method: RequestMethod, + val path: String, + val headers: MutableMap = mutableMapOf(), + val params: MutableMap = mutableMapOf(), + val query: MutableMap> = mutableMapOf(), + val requiresAuthentication: Boolean, + val body: T? = null +) diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt new file mode 100644 index 000000000000..beb56f07cdde --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt @@ -0,0 +1,8 @@ +package org.openapitools.client.infrastructure + +/** + * Provides enumerated HTTP verbs + */ +enum class RequestMethod { + GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt new file mode 100644 index 000000000000..3fc7935a7bf6 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -0,0 +1,16 @@ +package org.openapitools.client.infrastructure + +import com.fasterxml.jackson.databind.DeserializationFeature +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.SerializationFeature +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper + +object Serializer { + @JvmStatic + val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper() + .findAndRegisterModules() + .setSerializationInclusion(JsonInclude.Include.NON_ABSENT) + .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/AllOfChild1.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/AllOfChild1.kt new file mode 100644 index 000000000000..1d23026a99c8 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/AllOfChild1.kt @@ -0,0 +1,42 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import org.openapitools.client.models.Parent + +import com.fasterxml.jackson.annotation.JsonProperty + +/** + * + * + * @param jobType + * @param property1 + */ + + +data class AllOfChild1 ( + + @get:JsonProperty("jobType") + override val jobType: kotlin.String? = null, + + @get:JsonProperty("property1") + val property1: kotlin.String? = null + +) : Parent { + + +} + diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/AllOfChild2.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/AllOfChild2.kt new file mode 100644 index 000000000000..18f431b05015 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/AllOfChild2.kt @@ -0,0 +1,42 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import org.openapitools.client.models.Parent + +import com.fasterxml.jackson.annotation.JsonProperty + +/** + * + * + * @param jobType + * @param property2 + */ + + +data class AllOfChild2 ( + + @get:JsonProperty("jobType") + override val jobType: kotlin.String? = null, + + @get:JsonProperty("property2") + val property2: kotlin.String? = null + +) : Parent { + + +} + diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/Child1.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/Child1.kt new file mode 100644 index 000000000000..943d761e176a --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/Child1.kt @@ -0,0 +1,41 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.fasterxml.jackson.annotation.JsonProperty + +/** + * + * + * @param jobType + * @param property1 + */ + + +data class Child1 ( + + @get:JsonProperty("jobType") + override val jobType: kotlin.String? = null, + + @get:JsonProperty("property1") + val property1: kotlin.String? = null + +) : WithoutAllOfEndpoint200Response { + + +} + diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/Child2.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/Child2.kt new file mode 100644 index 000000000000..70f574605816 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/Child2.kt @@ -0,0 +1,41 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.fasterxml.jackson.annotation.JsonProperty + +/** + * + * + * @param jobType + * @param property2 + */ + + +data class Child2 ( + + @get:JsonProperty("jobType") + override val jobType: kotlin.String? = null, + + @get:JsonProperty("property2") + val property2: kotlin.String? = null + +) : WithoutAllOfEndpoint200Response { + + +} + diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/Parent.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/Parent.kt new file mode 100644 index 000000000000..2f55b14ff23c --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/Parent.kt @@ -0,0 +1,45 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo + +/** + * + * + * @param jobType + */ +@JsonIgnoreProperties( + value = ["jobType"], // ignore manually set jobType, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the jobType to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "jobType", visible = true) +@JsonSubTypes( + JsonSubTypes.Type(value = AllOfChild1::class, name = "AllOfChild1"), + JsonSubTypes.Type(value = AllOfChild2::class, name = "AllOfChild2") +) + +interface Parent { + + @get:JsonProperty("jobType") + val jobType: kotlin.String? + +} + diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/WithAllOfEndpoint200Response.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/WithAllOfEndpoint200Response.kt new file mode 100644 index 000000000000..3c8396721782 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/WithAllOfEndpoint200Response.kt @@ -0,0 +1,53 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import org.openapitools.client.models.AllOfChild1 +import org.openapitools.client.models.AllOfChild2 + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo + +/** + * + * + * @param jobType + * @param property1 + * @param property2 + */ +@JsonIgnoreProperties( + value = ["jobType"], // ignore manually set jobType, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the jobType to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "jobType", visible = true) +@JsonSubTypes( + JsonSubTypes.Type(value = AllOfChild1::class, name = "AllOfChild1"), + JsonSubTypes.Type(value = AllOfChild2::class, name = "AllOfChild2") +) + +interface WithAllOfEndpoint200Response { + + @get:JsonProperty("jobType") + val jobType: kotlin.String? + @get:JsonProperty("property1") + val property1: kotlin.String? + @get:JsonProperty("property2") + val property2: kotlin.String? + +} + diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/WithoutAllOfEndpoint200Response.kt b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/WithoutAllOfEndpoint200Response.kt new file mode 100644 index 000000000000..b1c5224da1e7 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/main/kotlin/org/openapitools/client/models/WithoutAllOfEndpoint200Response.kt @@ -0,0 +1,53 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import org.openapitools.client.models.Child1 +import org.openapitools.client.models.Child2 + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo + +/** + * + * + * @param jobType + * @param property1 + * @param property2 + */ +@JsonIgnoreProperties( + value = ["jobType"], // ignore manually set jobType, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the jobType to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "jobType", visible = true) +@JsonSubTypes( + JsonSubTypes.Type(value = Child1::class, name = "Child1"), + JsonSubTypes.Type(value = Child2::class, name = "Child2") +) + +interface WithoutAllOfEndpoint200Response { + + @get:JsonProperty("jobType") + val jobType: kotlin.String? + @get:JsonProperty("property1") + val property1: kotlin.String? + @get:JsonProperty("property2") + val property2: kotlin.String? + +} + diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/apis/DefaultApiTest.kt b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/apis/DefaultApiTest.kt new file mode 100644 index 000000000000..7c04d5c2b658 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/apis/DefaultApiTest.kt @@ -0,0 +1,45 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.apis + +import io.kotlintest.shouldBe +import io.kotlintest.specs.ShouldSpec + +import org.openapitools.client.apis.DefaultApi +import org.openapitools.client.models.WithAllOfEndpoint200Response +import org.openapitools.client.models.WithoutAllOfEndpoint200Response + +class DefaultApiTest : ShouldSpec() { + init { + // uncomment below to create an instance of DefaultApi + //val apiInstance = DefaultApi() + + // to test withAllOfEndpoint + should("test withAllOfEndpoint") { + // uncomment below to test withAllOfEndpoint + //val result : WithAllOfEndpoint200Response = apiInstance.withAllOfEndpoint() + //result shouldBe ("TODO") + } + + // to test withoutAllOfEndpoint + should("test withoutAllOfEndpoint") { + // uncomment below to test withoutAllOfEndpoint + //val result : WithoutAllOfEndpoint200Response = apiInstance.withoutAllOfEndpoint() + //result shouldBe ("TODO") + } + + } +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/AllOfChild1Test.kt b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/AllOfChild1Test.kt new file mode 100644 index 000000000000..600a1a741277 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/AllOfChild1Test.kt @@ -0,0 +1,36 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import io.kotlintest.shouldBe +import io.kotlintest.specs.ShouldSpec + +import org.openapitools.client.models.AllOfChild1 +import org.openapitools.client.models.Parent + +class AllOfChild1Test : ShouldSpec() { + init { + // uncomment below to create an instance of AllOfChild1 + //val modelInstance = AllOfChild1() + + // to test the property `property1` + should("test property1") { + // uncomment below to test the property + //modelInstance.property1 shouldBe ("TODO") + } + + } +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/AllOfChild2Test.kt b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/AllOfChild2Test.kt new file mode 100644 index 000000000000..03f15140b22a --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/AllOfChild2Test.kt @@ -0,0 +1,36 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import io.kotlintest.shouldBe +import io.kotlintest.specs.ShouldSpec + +import org.openapitools.client.models.AllOfChild2 +import org.openapitools.client.models.Parent + +class AllOfChild2Test : ShouldSpec() { + init { + // uncomment below to create an instance of AllOfChild2 + //val modelInstance = AllOfChild2() + + // to test the property `property2` + should("test property2") { + // uncomment below to test the property + //modelInstance.property2 shouldBe ("TODO") + } + + } +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/Child1Test.kt b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/Child1Test.kt new file mode 100644 index 000000000000..7ed847911130 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/Child1Test.kt @@ -0,0 +1,41 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import io.kotlintest.shouldBe +import io.kotlintest.specs.ShouldSpec + +import org.openapitools.client.models.Child1 + +class Child1Test : ShouldSpec() { + init { + // uncomment below to create an instance of Child1 + //val modelInstance = Child1() + + // to test the property `jobType` + should("test jobType") { + // uncomment below to test the property + //modelInstance.jobType shouldBe ("TODO") + } + + // to test the property `property1` + should("test property1") { + // uncomment below to test the property + //modelInstance.property1 shouldBe ("TODO") + } + + } +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/Child2Test.kt b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/Child2Test.kt new file mode 100644 index 000000000000..3370707dbbf0 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/Child2Test.kt @@ -0,0 +1,41 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import io.kotlintest.shouldBe +import io.kotlintest.specs.ShouldSpec + +import org.openapitools.client.models.Child2 + +class Child2Test : ShouldSpec() { + init { + // uncomment below to create an instance of Child2 + //val modelInstance = Child2() + + // to test the property `jobType` + should("test jobType") { + // uncomment below to test the property + //modelInstance.jobType shouldBe ("TODO") + } + + // to test the property `property2` + should("test property2") { + // uncomment below to test the property + //modelInstance.property2 shouldBe ("TODO") + } + + } +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/ParentTest.kt b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/ParentTest.kt new file mode 100644 index 000000000000..1e754526d4dd --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/ParentTest.kt @@ -0,0 +1,35 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import io.kotlintest.shouldBe +import io.kotlintest.specs.ShouldSpec + +import org.openapitools.client.models.Parent + +class ParentTest : ShouldSpec() { + init { + // uncomment below to create an instance of Parent + //val modelInstance = Parent() + + // to test the property `jobType` + should("test jobType") { + // uncomment below to test the property + //modelInstance.jobType shouldBe ("TODO") + } + + } +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/WithAllOfEndpoint200ResponseTest.kt b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/WithAllOfEndpoint200ResponseTest.kt new file mode 100644 index 000000000000..db2a5968c749 --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/WithAllOfEndpoint200ResponseTest.kt @@ -0,0 +1,49 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import io.kotlintest.shouldBe +import io.kotlintest.specs.ShouldSpec + +import org.openapitools.client.models.WithAllOfEndpoint200Response +import org.openapitools.client.models.AllOfChild1 +import org.openapitools.client.models.AllOfChild2 + +class WithAllOfEndpoint200ResponseTest : ShouldSpec() { + init { + // uncomment below to create an instance of WithAllOfEndpoint200Response + //val modelInstance = WithAllOfEndpoint200Response() + + // to test the property `jobType` + should("test jobType") { + // uncomment below to test the property + //modelInstance.jobType shouldBe ("TODO") + } + + // to test the property `property1` + should("test property1") { + // uncomment below to test the property + //modelInstance.property1 shouldBe ("TODO") + } + + // to test the property `property2` + should("test property2") { + // uncomment below to test the property + //modelInstance.property2 shouldBe ("TODO") + } + + } +} diff --git a/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/WithoutAllOfEndpoint200ResponseTest.kt b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/WithoutAllOfEndpoint200ResponseTest.kt new file mode 100644 index 000000000000..47cfc28a1a3b --- /dev/null +++ b/samples/client/others/kotlin-oneOf-discriminator/src/test/kotlin/org/openapitools/client/models/WithoutAllOfEndpoint200ResponseTest.kt @@ -0,0 +1,49 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import io.kotlintest.shouldBe +import io.kotlintest.specs.ShouldSpec + +import org.openapitools.client.models.WithoutAllOfEndpoint200Response +import org.openapitools.client.models.Child1 +import org.openapitools.client.models.Child2 + +class WithoutAllOfEndpoint200ResponseTest : ShouldSpec() { + init { + // uncomment below to create an instance of WithoutAllOfEndpoint200Response + //val modelInstance = WithoutAllOfEndpoint200Response() + + // to test the property `jobType` + should("test jobType") { + // uncomment below to test the property + //modelInstance.jobType shouldBe ("TODO") + } + + // to test the property `property1` + should("test property1") { + // uncomment below to test the property + //modelInstance.property1 shouldBe ("TODO") + } + + // to test the property `property2` + should("test property2") { + // uncomment below to test the property + //modelInstance.property2 shouldBe ("TODO") + } + + } +} diff --git a/samples/client/petstore/kotlin-allOf-discriminator/.openapi-generator/FILES b/samples/client/petstore/kotlin-allOf-discriminator/.openapi-generator/FILES index 3584a03b3b54..1865a6a28ba8 100644 --- a/samples/client/petstore/kotlin-allOf-discriminator/.openapi-generator/FILES +++ b/samples/client/petstore/kotlin-allOf-discriminator/.openapi-generator/FILES @@ -1,3 +1,4 @@ +.openapi-generator-ignore README.md build.gradle docs/Animal.md @@ -29,3 +30,6 @@ src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt src/main/kotlin/org/openapitools/client/models/Animal.kt src/main/kotlin/org/openapitools/client/models/Bird.kt +src/test/kotlin/org/openapitools/client/apis/BirdApiTest.kt +src/test/kotlin/org/openapitools/client/models/AnimalTest.kt +src/test/kotlin/org/openapitools/client/models/BirdTest.kt diff --git a/samples/client/petstore/kotlin-allOf-discriminator/gradlew b/samples/client/petstore/kotlin-allOf-discriminator/gradlew old mode 100755 new mode 100644