diff --git a/.github/workflows/openapi-generator.yaml b/.github/workflows/openapi-generator.yaml index a48c4c4db470..c4678365f435 100644 --- a/.github/workflows/openapi-generator.yaml +++ b/.github/workflows/openapi-generator.yaml @@ -1,10 +1,13 @@ name: OpenAPI Generator +permissions: + contents: write + on: push: - branches: - - master - - '[5-9]+.[0-9]+.x' + # branches: + # - master + # - '[5-9]+.[0-9]+.x' pull_request: branches: - master @@ -36,158 +39,189 @@ jobs: ${{ runner.os }}-build-${{ env.cache-name }}- ${{ runner.os }}-build- - name: Run maven - run: ./mvnw clean --no-snapshot-updates --batch-mode --quiet install -DskipTests -Dorg.slf4j.simpleLogger.defaultLogLevel=error + run: ./mvnw clean package -DskipTests env: GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - run: ls -la modules/openapi-generator-cli/target - - name: Upload openapi-generator-cli.jar artifact - uses: actions/upload-artifact@v4 - with: - name: openapi-generator-cli.jar - path: modules/openapi-generator-cli/target/openapi-generator-cli.jar - retention-days: 1 - - test: - name: Unit tests - runs-on: ubuntu-latest - needs: - - build - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 11 - uses: actions/setup-java@v4 - with: - java-version: 11 - distribution: 'temurin' - - name: Cache maven dependencies - uses: actions/cache@v4 - env: - cache-name: cache-maven-repository - with: - path: | - ~/.m2/repository - ~/.gradle - !~/.gradle/caches/*/plugin-resolution/ - !~/.m2/repository/org/openapitools/ - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - - name: Run unit tests - run: ./mvnw clean --no-snapshot-updates --batch-mode --quiet --fail-at-end test -Dorg.slf4j.simpleLogger.defaultLogLevel=error - env: - GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} - - name: Publish unit test reports - if: ${{ always() }} - uses: actions/upload-artifact@v4 - with: - name: surefire-test-results - path: '**/surefire-reports/TEST-*.xml' - documentation: - name: Docs up-to-date - runs-on: ubuntu-latest - needs: - - build - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 11 - uses: actions/setup-java@v4 - with: - java-version: 11 - distribution: 'temurin' - - name: Download openapi-generator-cli.jar artifact - uses: actions/download-artifact@v4 - with: - name: openapi-generator-cli.jar - path: modules/openapi-generator-cli/target - - name: Generate docs + - name: Extract current branch name + id: branch-name run: | - bash bin/meta-codegen.sh - bash bin/utils/export_docs_generators.sh - bash bin/utils/copy-to-website.sh - bash bin/utils/export_generators_readme.sh - - name: Verify git status + BRANCH_NAME=${{ github.ref }} + echo "Full ref: $BRANCH_NAME" + # Strip the refs/heads/ part to get the branch name + BRANCH_NAME=${BRANCH_NAME#refs/heads/} + echo "::set-output name=branch_name::$BRANCH_NAME" + + - name: Generate tag string + id: generate_snapshot_string run: | - if [[ "$(git status --porcelain)" != "" ]]; then - echo "UNCOMMITTED CHANGES ERROR" - echo "There are uncommitted changes in working tree after execution of 'bin/ensure-up-to-date'" - echo "Perform git diff" - git --no-pager diff - echo "Perform git status" - git status - echo -e "\nThis script runs in pull requests against the anticipated merge commit (as if the PR was merged now)." - echo "When you see unexpected files here, it likely means that there are newer commits in master that you need to " - echo -e "rebase or merge into your branch.\n" - echo "Please run 'bin/utils/ensure-up-to-date' locally and commit changes (UNCOMMITTED CHANGES ERROR)" - exit 1 - fi + SNAPSHOT_STRING="tidal-SNAPSHOT-$(date +%Y-%m-%d)" + echo "Generated string: $SNAPSHOT_STRING" - samples: - name: Samples up-to-date - needs: - - build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 11 - uses: actions/setup-java@v4 + # Set the output for this step + echo "::set-output name=snapshot_string::$SNAPSHOT_STRING" + + - name: Generate Release Draft + id: generate-release + uses: ncipollo/release-action@v1 with: - java-version: 11 - distribution: 'temurin' - - name: Download openapi-generator-cli.jar artifact - uses: actions/download-artifact@v4 + tag: ${{ steps.generate_snapshot_string.outputs.snapshot_string }} + allowUpdates: true + draft: true + body: "This is a release draft for ${{ github.ref }}" + + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 with: - name: openapi-generator-cli.jar - path: modules/openapi-generator-cli/target - - name: Delete samples that are entirely generated - run: | - rm -rf samples/client/petstore/csharp/generichost/latest/Tags + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: modules/openapi-generator-cli/target/openapi-generator-cli.jar + asset_name: openapi-generator-cli.jar + tag: ${{ steps.generate_snapshot_string.outputs.snapshot_string }} + overwrite: true + target_commit: ${{ steps.branch-name.outputs.branch_name }} + body: "This is the latest snapshot release of our openapi-generator fork" + # test: + # name: Unit tests + # runs-on: ubuntu-latest + # needs: + # - build + # steps: + # - uses: actions/checkout@v4 + # - name: Set up JDK 11 + # uses: actions/setup-java@v4 + # with: + # java-version: 11 + # distribution: 'temurin' + # - name: Cache maven dependencies + # uses: actions/cache@v4 + # env: + # cache-name: cache-maven-repository + # with: + # path: | + # ~/.m2/repository + # ~/.gradle + # !~/.gradle/caches/*/plugin-resolution/ + # !~/.m2/repository/org/openapitools/ + # key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }} + # restore-keys: | + # ${{ runner.os }}-build-${{ env.cache-name }}- + # ${{ runner.os }}-build- + # - name: Run unit tests + # run: ./mvnw clean --no-snapshot-updates --batch-mode --quiet --fail-at-end test -Dorg.slf4j.simpleLogger.defaultLogLevel=error + # env: + # GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }} + # - name: Publish unit test reports + # if: ${{ always() }} + # uses: actions/upload-artifact@v4 + # with: + # name: surefire-test-results + # path: '**/surefire-reports/TEST-*.xml' - rm -rf samples/client/petstore/csharp/generichost/net8/AllOf - rm -rf samples/client/petstore/csharp/generichost/net8/AnyOf - rm -rf samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare - rm -rf samples/client/petstore/csharp/generichost/net8/FormModels - rm -rf samples/client/petstore/csharp/generichost/net8/NullReferenceTypes - rm -rf samples/client/petstore/csharp/generichost/net8/OneOf - rm -rf samples/client/petstore/csharp/generichost/net8/Petstore - rm -rf samples/client/petstore/csharp/generichost/net8/SourceGeneration - rm -rf samples/client/petstore/csharp/generichost/net8/UseDateTimeForDate + # documentation: + # name: Docs up-to-date + # runs-on: ubuntu-latest + # needs: + # - build + # steps: + # - uses: actions/checkout@v4 + # - name: Set up JDK 11 + # uses: actions/setup-java@v4 + # with: + # java-version: 11 + # distribution: 'temurin' + # - name: Download openapi-generator-cli.jar artifact + # uses: actions/download-artifact@v4 + # with: + # name: openapi-generator-cli.jar + # path: modules/openapi-generator-cli/target + # - name: Generate docs + # run: | + # bash bin/meta-codegen.sh + # bash bin/utils/export_docs_generators.sh + # bash bin/utils/copy-to-website.sh + # bash bin/utils/export_generators_readme.sh + # - name: Verify git status + # run: | + # if [[ "$(git status --porcelain)" != "" ]]; then + # echo "UNCOMMITTED CHANGES ERROR" + # echo "There are uncommitted changes in working tree after execution of 'bin/ensure-up-to-date'" + # echo "Perform git diff" + # git --no-pager diff + # echo "Perform git status" + # git status + # echo -e "\nThis script runs in pull requests against the anticipated merge commit (as if the PR was merged now)." + # echo "When you see unexpected files here, it likely means that there are newer commits in master that you need to " + # echo -e "rebase or merge into your branch.\n" + # echo "Please run 'bin/utils/ensure-up-to-date' locally and commit changes (UNCOMMITTED CHANGES ERROR)" + # exit 1 + # fi - rm -rf samples/client/petstore/csharp/generichost/standard2.0/Petstore + # samples: + # name: Samples up-to-date + # needs: + # - build + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - name: Set up JDK 11 + # uses: actions/setup-java@v4 + # with: + # java-version: 11 + # distribution: 'temurin' + # - name: Download openapi-generator-cli.jar artifact + # uses: actions/download-artifact@v4 + # with: + # name: openapi-generator-cli.jar + # path: modules/openapi-generator-cli/target + # - name: Delete samples that are entirely generated + # run: | + # rm -rf samples/client/petstore/csharp/generichost/latest/Tags - rm -rf samples/client/petstore/csharp/generichost/net4.8/AllOf - rm -rf samples/client/petstore/csharp/generichost/net4.8/AnyOf - rm -rf samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare - rm -rf samples/client/petstore/csharp/generichost/net4.8/FormModels - rm -rf samples/client/petstore/csharp/generichost/net4.8/OneOf - rm -rf samples/client/petstore/csharp/generichost/net4.8/Petstore - rm -rf samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate + # rm -rf samples/client/petstore/csharp/generichost/net8/AllOf + # rm -rf samples/client/petstore/csharp/generichost/net8/AnyOf + # rm -rf samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare + # rm -rf samples/client/petstore/csharp/generichost/net8/FormModels + # rm -rf samples/client/petstore/csharp/generichost/net8/NullReferenceTypes + # rm -rf samples/client/petstore/csharp/generichost/net8/OneOf + # rm -rf samples/client/petstore/csharp/generichost/net8/Petstore + # rm -rf samples/client/petstore/csharp/generichost/net8/SourceGeneration + # rm -rf samples/client/petstore/csharp/generichost/net8/UseDateTimeForDate - rm -rf samples/client/petstore/csharp/generichost/net4.7/AllOf - rm -rf samples/client/petstore/csharp/generichost/net4.7/AnyOf - rm -rf samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare - rm -rf samples/client/petstore/csharp/generichost/net4.7/FormModels - rm -rf samples/client/petstore/csharp/generichost/net4.7/OneOf - rm -rf samples/client/petstore/csharp/generichost/net4.7/Petstore - rm -rf samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate - - name: Generate samples - run: | - bash bin/generate-samples.sh - # when a sample is deleted, you have to generate it twice for all files to get created - bash bin/generate-samples.sh - - name: Verify git status - run: | - if [[ "$(git status --porcelain)" != "" ]]; then - echo "UNCOMMITTED CHANGES ERROR" - echo "There are uncommitted changes in working tree after execution of 'bin/generate-samples.sh'" - echo "Perform git diff" - git --no-pager diff - echo "Perform git status" - git status - echo -e "\nThis script runs in pull requests against the anticipated merge commit (as if the PR was merged now)." - echo "When you see unexpected files here, it likely means that there are newer commits in master that you need to " - echo -e "rebase or merge into your branch.\n" - echo "Please run 'bin/generate-samples.sh' locally and commit changes (UNCOMMITTED CHANGES ERROR)" - exit 1 - fi + # rm -rf samples/client/petstore/csharp/generichost/standard2.0/Petstore + + # rm -rf samples/client/petstore/csharp/generichost/net4.8/AllOf + # rm -rf samples/client/petstore/csharp/generichost/net4.8/AnyOf + # rm -rf samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare + # rm -rf samples/client/petstore/csharp/generichost/net4.8/FormModels + # rm -rf samples/client/petstore/csharp/generichost/net4.8/OneOf + # rm -rf samples/client/petstore/csharp/generichost/net4.8/Petstore + # rm -rf samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate + + # rm -rf samples/client/petstore/csharp/generichost/net4.7/AllOf + # rm -rf samples/client/petstore/csharp/generichost/net4.7/AnyOf + # rm -rf samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare + # rm -rf samples/client/petstore/csharp/generichost/net4.7/FormModels + # rm -rf samples/client/petstore/csharp/generichost/net4.7/OneOf + # rm -rf samples/client/petstore/csharp/generichost/net4.7/Petstore + # rm -rf samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate + # - name: Generate samples + # run: | + # bash bin/generate-samples.sh + # # when a sample is deleted, you have to generate it twice for all files to get created + # bash bin/generate-samples.sh + # - name: Verify git status + # run: | + # if [[ "$(git status --porcelain)" != "" ]]; then + # echo "UNCOMMITTED CHANGES ERROR" + # echo "There are uncommitted changes in working tree after execution of 'bin/generate-samples.sh'" + # echo "Perform git diff" + # git --no-pager diff + # echo "Perform git status" + # git status + # echo -e "\nThis script runs in pull requests against the anticipated merge commit (as if the PR was merged now)." + # echo "When you see unexpected files here, it likely means that there are newer commits in master that you need to " + # echo -e "rebase or merge into your branch.\n" + # echo "Please run 'bin/generate-samples.sh' locally and commit changes (UNCOMMITTED CHANGES ERROR)" + # exit 1 + # fi diff --git a/bin/configs/tidal-kotlin-petstore-new.yaml b/bin/configs/tidal-kotlin-petstore-new.yaml new file mode 100644 index 000000000000..32a6f6212ccd --- /dev/null +++ b/bin/configs/tidal-kotlin-petstore-new.yaml @@ -0,0 +1,6 @@ +generatorName: tidal-kotlin +outputDir: samples/client/petstore/tidal/kotlin +inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/tidal-kotlin +additionalProperties: + hideGenerationTimestamp: "true" 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 69258bdf092b..0f130e478800 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 @@ -18,10 +18,8 @@ package org.openapitools.codegen.languages; import java.io.File; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.function.BiConsumer; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -899,6 +897,9 @@ private void commonSupportingFiles() { supportingFiles.add(new SupportingFile("gradle-wrapper.properties.mustache", "gradle.wrapper".replace(".", File.separator), "gradle-wrapper.properties")); supportingFiles.add(new SupportingFile("gradle-wrapper.jar", "gradle.wrapper".replace(".", File.separator), "gradle-wrapper.jar")); } + if (getSerializationLibrary().equals(SERIALIZATION_LIBRARY_TYPE.kotlinx_serialization) && getGenerateOneOfAnyOfWrappers()) { + supportingFiles.add(new SupportingFile("Utils.kt.mustache", (sourceFolder + "." + modelPackage).replace(".", File.separator), "Utils.kt")); + } } @Override @@ -932,6 +933,72 @@ public ModelsMap postProcessModels(ModelsMap objs) { return objects; } + @Override + public Map postProcessAllModels(Map objs) { + objs = super.postProcessAllModels(objs); + objs = super.updateAllModels(objs); + + Map> resourceRelationShips = new HashMap<>(); + BiConsumer addToResourceRelationships = (key, value) -> { + resourceRelationShips.computeIfAbsent(key, k -> new ArrayList<>()).add(value); + }; + + // Find all oneOf parents + objs.forEach((key, value) -> { + List models = value.getModels(); + for (ModelMap modelMap : models) { + CodegenModel codegenModel = modelMap.getModel(); + + if (!codegenModel.oneOf.isEmpty()) { + String className = codegenModel.classname; + codegenModel.oneOf.forEach(oneOfClass -> addToResourceRelationships.accept(className, oneOfClass)); + codegenModel.vendorExtensions.put("x-is-oneof-parent", true); + } else { + // this field needs to be null to prevent mustache from getting triggered by an empty set + codegenModel.oneOf = null; + } + } + }); + + List combinedList = resourceRelationShips.values().stream() + .flatMap(List::stream) + .collect(Collectors.toList()); + + // Find all oneOf children and assign relationships + objs.forEach((key, value) -> { + List models = value.getModels(); + for (ModelMap modelMap : models) { + CodegenModel codegenModel = modelMap.getModel(); + String className = codegenModel.classname; + + if (combinedList.contains(className)) { + codegenModel.vendorExtensions.put("x-has-oneof-parent", true); + codegenModel.vendorExtensions.put("x-has-serializable-type", "hello"); + int index = codegenModel.classname.indexOf("Resource"); + if (index != -1) { + String serializableType = + Character.toLowerCase(codegenModel.classname.charAt(0)) + codegenModel.classname.substring(1, index); + codegenModel.vendorExtensions.put("x-has-serializable-type", serializableType); + } + + codegenModel.allVars.stream() + .filter(p -> Objects.equals(p.name, "type")) + .forEach(p -> { + LOGGER.info("Found type field in " + className); + p.vendorExtensions.put("x-is-transient", true); + LOGGER.info("VendorExtensions: " + p.vendorExtensions); + LOGGER.info("model VendorExtensions: " + codegenModel.vendorExtensions); + }); + // Find all parents for the current class and add to allParents + codegenModel.allParents = resourceRelationShips.entrySet().stream() + .filter(entry -> entry.getValue().contains(className)) + .map(Map.Entry::getKey).collect(Collectors.toList()); + } + } + }); + return objs; + } + private boolean usesRetrofit2Library() { return getLibrary() != null && getLibrary().contains(JVM_RETROFIT2); } diff --git a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig index 2f8c6c6074c2..8c7e0d3eb4d5 100644 --- a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig +++ b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig @@ -153,3 +153,6 @@ org.openapitools.codegen.languages.TypeScriptRxjsClientCodegen org.openapitools.codegen.languages.WsdlSchemaCodegen org.openapitools.codegen.languages.XojoClientCodegen org.openapitools.codegen.languages.ZapierClientCodegen +org.openapitools.codegen.languages.RustAxumServerCodegen + +org.openapitools.codegen.languages.TidalKotlinClientCodegen diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/Utils.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/Utils.kt.mustache new file mode 100644 index 000000000000..c5e9419da20c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-client/Utils.kt.mustache @@ -0,0 +1,19 @@ +package {{modelPackage}} + +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.polymorphic + +fun getOneOfSerializer() = SerializersModule { +{{#models}} +{{#model}} +{{#oneOf.size}} + polymorphic({{classname}}::class) { +{{#oneOf}} + subclass({{.}}::class, {{.}}.serializer()) +{{/oneOf}} + } +{{/oneOf.size}} +{{/model}} +{{/models}} +} + 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 394af616a128..4291f0bc1d97 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 @@ -31,6 +31,8 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo import {{#serializableModel}}kotlinx.serialization.Serializable as KSerializable{{/serializableModel}}{{^serializableModel}}kotlinx.serialization.Serializable{{/serializableModel}} import kotlinx.serialization.SerialName import kotlinx.serialization.Contextual +import kotlinx.serialization.Polymorphic +import kotlinx.serialization.Transient {{#enumUnknownDefaultCase}} import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializer @@ -66,24 +68,32 @@ import {{packageName}}.infrastructure.ITransformForStorage * @param {{{name}}} {{{description}}} {{/allVars}} */ +{{#kotlinx_serialization}} +{{#vendorExtensions.x-is-oneof-parent}} +@Serializable +@Polymorphic +sealed interface {{classname}} +{{/vendorExtensions.x-is-oneof-parent}} +{{/kotlinx_serialization}} +{{^vendorExtensions.x-is-oneof-parent}} {{#parcelizeModels}} @Parcelize {{/parcelizeModels}} + {{#multiplatform}}{{^discriminator}}@Serializable{{/discriminator}}{{/multiplatform}}{{#kotlinx_serialization}}{{#serializableModel}}@KSerializable{{/serializableModel}}{{^serializableModel}}@Serializable{{/serializableModel}}{{/kotlinx_serialization}}{{#moshi}}{{#moshiCodeGen}}@JsonClass(generateAdapter = true){{/moshiCodeGen}}{{/moshi}}{{#jackson}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{/jackson}} {{#isDeprecated}} @Deprecated(message = "This schema is deprecated.") {{/isDeprecated}} +{{#vendorExtensions.x-has-serializable-type}} +@SerialName(value = "{{vendorExtensions.x-has-serializable-type}}") +{{/vendorExtensions.x-has-serializable-type}} {{>additionalModelTypeAnnotations}} -{{#vendorExtensions.x-class-extra-annotation}} -{{{vendorExtensions.x-class-extra-annotation}}} -{{/vendorExtensions.x-class-extra-annotation}} -{{#nonPublicApi}}internal {{/nonPublicApi}}{{#discriminator}}interface{{/discriminator}}{{^discriminator}}{{#hasVars}}data {{/hasVars}}class{{/discriminator}} {{classname}}{{^discriminator}} ( +{{#nonPublicApi}}internal {{/nonPublicApi}}{{#discriminator}}interface{{/discriminator}}{{^discriminator}}data class{{/discriminator}} {{classname}}{{^discriminator}} ( {{#allVars}} {{#required}}{{>data_class_req_var}}{{/required}}{{^required}}{{>data_class_opt_var}}{{/required}}{{^-last}},{{/-last}} - {{/allVars}} -){{/discriminator}}{{#parent}}{{^serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#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-has-oneof-parent}}: {{#allParents}}{{.}}{{^-last}}, {{/-last}}{{/allParents}}{{/vendorExtensions.x-has-oneof-parent}}{{#parent}}{{^serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#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 { } @@ -364,3 +374,4 @@ import {{packageName}}.infrastructure.ITransformForStorage {{#vendorExtensions.x-has-data-class-body}} } {{/vendorExtensions.x-has-data-class-body}} +{{/vendorExtensions.x-is-oneof-parent}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/data_class_opt_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/data_class_opt_var.mustache index 897b18f9e599..851a0cc3fa16 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/data_class_opt_var.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/data_class_opt_var.mustache @@ -12,6 +12,7 @@ @get:JsonProperty("{{{vendorExtensions.x-base-name-literal}}}") {{/jackson}} {{#kotlinx_serialization}} + {{#vendorExtensions.x-is-transient}}@Transient{{/vendorExtensions.x-is-transient}} {{^isEnum}}{{^isArray}}{{^isPrimitiveType}}{{^isModel}}@Contextual {{/isModel}}{{/isPrimitiveType}}{{/isArray}}{{/isEnum}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") {{/kotlinx_serialization}} {{/multiplatform}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/data_class_req_var.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/data_class_req_var.mustache index 811867dfc51f..01d156f1d6cc 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/data_class_req_var.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/data_class_req_var.mustache @@ -12,6 +12,7 @@ @get:JsonProperty("{{{vendorExtensions.x-base-name-literal}}}") {{/jackson}} {{#kotlinx_serialization}} + {{#vendorExtensions.x-is-transient}}@Transient{{/vendorExtensions.x-is-transient}} {{^isEnum}}{{^isArray}}{{^isPrimitiveType}}{{^isModel}}@Contextual {{/isModel}}{{/isPrimitiveType}}{{/isArray}}{{/isEnum}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") {{/kotlinx_serialization}} {{/multiplatform}} @@ -21,4 +22,4 @@ {{#deprecated}} @Deprecated(message = "This property is deprecated.") {{/deprecated}} - {{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") @Required {{/multiplatform}}{{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isArray}}{{#isList}}{{#uniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}Set{{/uniqueItems}}{{^uniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}List{{/uniqueItems}}{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{^items.isEnum}}{{^items.isPrimitiveType}}{{^items.isModel}}{{#kotlinx_serialization}}@Contextual {{/kotlinx_serialization}}{{/items.isModel}}{{/items.isPrimitiveType}}{{{items.dataType}}}{{/items.isEnum}}{{#items.isEnum}}{{classname}}.{{{nameInPascalCase}}}{{/items.isEnum}}>{{/isArray}}{{^isEnum}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isEnum}}{{#isEnum}}{{^isArray}}{{classname}}.{{{nameInPascalCase}}}{{/isArray}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{^multiplatform}}{{{dataType}}}("{{{defaultValue}}}"){{/multiplatform}}{{#multiplatform}}({{{defaultValue}}}).toDouble(){{/multiplatform}}{{/isNumber}}{{/defaultValue}} \ No newline at end of file + {{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") @Required {{/multiplatform}}{{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isArray}}{{#isList}}{{#uniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}Set{{/uniqueItems}}{{^uniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}List{{/uniqueItems}}{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{^items.isEnum}}{{^items.isPrimitiveType}}{{^items.isModel}}{{#kotlinx_serialization}}@Contextual {{/kotlinx_serialization}}{{/items.isModel}}{{/items.isPrimitiveType}}{{{items.dataType}}}{{/items.isEnum}}{{#items.isEnum}}{{classname}}.{{{nameInPascalCase}}}{{/items.isEnum}}>{{/isArray}}{{^isEnum}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isEnum}}{{#isEnum}}{{^isArray}}{{classname}}.{{{nameInPascalCase}}}{{/isArray}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{^multiplatform}}{{{dataType}}}("{{{defaultValue}}}"){{/multiplatform}}{{#multiplatform}}({{{defaultValue}}}).toDouble(){{/multiplatform}}{{/isNumber}}{{/defaultValue}}{{#vendorExtensions.x-is-transient}} = ""{{/vendorExtensions.x-is-transient}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/oneof_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/oneof_class.mustache index eebf9858773b..3c1afa2af7c5 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/oneof_class.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/oneof_class.mustache @@ -30,6 +30,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo import {{#serializableModel}}kotlinx.serialization.Serializable as KSerializable{{/serializableModel}}{{^serializableModel}}kotlinx.serialization.Serializable{{/serializableModel}} import kotlinx.serialization.SerialName import kotlinx.serialization.Contextual +import kotlinx.serialization.Polymorphic {{#enumUnknownDefaultCase}} import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializer @@ -71,8 +72,19 @@ import java.io.IOException @Deprecated(message = "This schema is deprecated.") {{/isDeprecated}} {{>additionalModelTypeAnnotations}} -{{#nonPublicApi}}internal {{/nonPublicApi}}data class {{classname}}(var actualInstance: Any? = null) { - +{{#nonPublicApi}}internal {{/nonPublicApi}}data class {{classname}}( +{{^kotlinx_serialization}} + var actualInstance: Any? = null) +{{/kotlinx_serialization}} +{{#kotlinx_serialization}} + val resource: {{classname}}Resource? = null +) { +} +@Serializable +@Polymorphic +sealed interface {{classname}}Resource +{{/kotlinx_serialization}} +{{^kotlinx_serialization}} class CustomTypeAdapterFactory : TypeAdapterFactory { override fun create(gson: Gson, type: TypeToken): TypeAdapter? { if (!{{classname}}::class.java.isAssignableFrom(type.rawType)) { @@ -236,4 +248,5 @@ import java.io.IOException }.nullSafe() as TypeAdapter } } -} \ No newline at end of file +} +{{/kotlinx_serialization}} diff --git a/test.sh b/test.sh new file mode 100755 index 000000000000..080232fd595f --- /dev/null +++ b/test.sh @@ -0,0 +1,10 @@ +#!/bin/zsh + +echo "Compiling" +mvn clean package -DskipTests + +echo "Go to module" +cd ~/work/tidal-sdk/tidal-sdk-android-private/userprofile + +echo "Run generate script" +./bin/generate.sh clean.json