diff --git a/.github/workflows/samples-kotlin-server.yaml b/.github/workflows/samples-kotlin-server.yaml index 216963aaf691..096401d03407 100644 --- a/.github/workflows/samples-kotlin-server.yaml +++ b/.github/workflows/samples-kotlin-server.yaml @@ -41,6 +41,7 @@ jobs: - samples/server/petstore/kotlin-springboot-source-swagger2 - samples/server/petstore/kotlin-springboot-x-kotlin-implements - samples/server/petstore/kotlin-springboot-include-http-request-context-delegate + - samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call - samples/server/petstore/kotlin-server/ktor2 - samples/server/petstore/kotlin-server/jaxrs-spec - samples/server/petstore/kotlin-server/jaxrs-spec-mutiny diff --git a/bin/configs/kotlin-spring-issue8366-inheritance-parent-ctor-call.yaml b/bin/configs/kotlin-spring-issue8366-inheritance-parent-ctor-call.yaml new file mode 100644 index 000000000000..3973b6b4c83c --- /dev/null +++ b/bin/configs/kotlin-spring-issue8366-inheritance-parent-ctor-call.yaml @@ -0,0 +1,12 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/issue8366-inheritance-parent-ctor-call.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + documentationProvider: springdoc + annotationLibrary: swagger2 + useSwaggerUI: "true" + serviceImplementation: "true" + reactive: "true" + beanValidations: "false" \ No newline at end of file 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 8036919680b8..169bb4dd7708 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 @@ -123,6 +123,8 @@ public enum KotlinEnumNamingType { // ref: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-hash-map/ protected Set propertyAdditionalKeywords = new HashSet<>(Arrays.asList("entries", "keys", "size", "values")); + private final List PARENT_TYPES_NEEDING_CTOR_CALL = List.of(Pattern.compile("^kotlin\\.collections\\.HashMap.*")); + private final Map schemaKeyToModelNameCache = new HashMap<>(); @Getter @Setter protected List additionalModelTypeAnnotations = new LinkedList<>(); @@ -498,10 +500,46 @@ public ModelsMap postProcessModels(ModelsMap objs) { break; } } + + final boolean isParentCtorCallNeeded = isParentCtorCallNeeded(cm); + cm.vendorExtensions.put("x-is-parent-ctor-call-needed", isParentCtorCallNeeded); } return postProcessModelsEnum(objs); } + /** + * Determines if a constructor call is needed for the parent type of a model + * and if yes, the invocation syntax `()` is added in the generated code. + * + * Important note: This is kotlin specific at the moment, but could be + * extended with to support detection for other languages as well. + * + * The generator used to default to issuing a supertype + * constructor call and then it was changed to default to not doing it. + * Both are wrong since there are different cases and the decision has to be + * made at runtime based on the parent type itself. + * + * For example if it is a HashMap (because you set + * additionalProperties: true for example) then it MUST HAVE a parent + * constructor call. If the parent type is an interface because you are + * using allOf with a discriminator property then the generated code for the + * model will have it's parent type as the interface which MUST NOT HAVE a + * parent constructor call. + * + * @see https://github.com/OpenAPITools/openapi-generator/issues/8366 + * + * @return {boolean} `true` if the () call syntax is needed, false otherwise. + */ + protected boolean isParentCtorCallNeeded(CodegenModel cm) { + final String parent = cm.getParent(); + + if (parent != null) { + return PARENT_TYPES_NEEDING_CTOR_CALL.stream() + .anyMatch(pattern -> pattern.matcher(parent).matches()); + } + return false; + } + @Override public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List allModels) { handleImplicitHeaders(objs); diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache index 3eeb19e70bcd..bb0487b77ebe 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache @@ -21,9 +21,9 @@ {{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>dataClassOptVar}}{{^-last}}, {{/-last}}{{/optionalVars}} ){{/discriminator}}{{! no newline -}}{{#parent}} : {{{.}}}{{#isMap}}(){{/isMap}}{{! no newline - }}{{#vendorExtensions.x-kotlin-implements}}, {{{.}}}{{/vendorExtensions.x-kotlin-implements}}{{! <- serializableModel is also handled via x-kotlin-implements - }}{{#vendorExtensions.x-implements-sealed-interfaces}}{{#.}}, {{{.}}}{{/.}}{{/vendorExtensions.x-implements-sealed-interfaces}}{{! <- add sealed interface implementations +}}{{#parent}} : {{{.}}}{{#vendorExtensions.x-is-parent-ctor-call-needed}}(){{/vendorExtensions.x-is-parent-ctor-call-needed}}{{! no newline + }}{{#vendorExtensions.x-kotlin-implements}}, {{{.}}}{{/vendorExtensions.x-kotlin-implements}}{{! no newline + }}{{#vendorExtensions.x-implements-sealed-interfaces}}{{#.}}, {{{.}}}{{/.}}{{/vendorExtensions.x-implements-sealed-interfaces}}{{! no newline }}{{/parent}}{{! no newline }}{{^parent}}{{! no newline }}{{#vendorExtensions.x-kotlin-implements}}{{! no newline diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java index fb53bafa3ad0..6ef447d45f05 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java @@ -1248,6 +1248,108 @@ public void generateSerializableModelWithXimplementsSkipAndSchemaImplements() th ); } + @Test + public void generateSerializableModelWithParentCtorCallNeeded() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + String outputPath = output.getAbsolutePath().replace('\\', '/'); + + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + codegen.additionalProperties().put(CodegenConstants.SERIALIZABLE_MODEL, true); + + ClientOptInput input = new ClientOptInput() + .openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue8366-inheritance-parent-ctor-call.yaml")) + .config(codegen); + DefaultGenerator generator = new DefaultGenerator(); + + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false"); + + generator.opts(input).generate(); + + Path path = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/JarFile.kt"); + assertFileContains( + path, + ") : kotlin.collections.HashMap(), java.io.Serializable {", + "private const val serialVersionUID: kotlin.Long = 1" + ); + assertFileNotContains(path, ") : kotlin.collections.HashMap {"); + } + + @Test + public void generateNonSerializableModelWithParentCtorCallNeeded() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + String outputPath = output.getAbsolutePath().replace('\\', '/'); + + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + + ClientOptInput input = new ClientOptInput() + .openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue8366-inheritance-parent-ctor-call.yaml")) + .config(codegen); + DefaultGenerator generator = new DefaultGenerator(); + + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false"); + + generator.opts(input).generate(); + + Path path = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/JarFile.kt"); + assertFileContains( + path, + ") : kotlin.collections.HashMap() {" + ); + assertFileNotContains( + path, + "java.io.Serializable", + ") : kotlin.collections.HashMap {" + ); + } + + @Test + public void generateNonSerializableModelWithParentCtorCallNeededAndXimplements() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + String outputPath = output.getAbsolutePath().replace('\\', '/'); + + KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOutputDir(output.getAbsolutePath()); + codegen.additionalProperties().put(KotlinSpringServerCodegen.SCHEMA_IMPLEMENTS, Map.of( + "JarFile", List.of("com.some.pack.ExtraInterface") + )); + + ClientOptInput input = new ClientOptInput() + .openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue8366-inheritance-parent-ctor-call.yaml")) + .config(codegen); + DefaultGenerator generator = new DefaultGenerator(); + + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false"); + + generator.opts(input).generate(); + + Path path = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/JarFile.kt"); + assertFileContains( + path, + ") : kotlin.collections.HashMap(), com.some.pack.ExtraInterface {" + ); + assertFileNotContains( + path, + "java.io.Serializable" + ); + } + @Test public void generateHttpInterfaceReactiveWithReactorResponseEntity() throws Exception { File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); diff --git a/modules/openapi-generator/src/test/resources/3_0/kotlin/issue8366-inheritance-parent-ctor-call.yaml b/modules/openapi-generator/src/test/resources/3_0/kotlin/issue8366-inheritance-parent-ctor-call.yaml new file mode 100644 index 000000000000..3fdfaf4437c1 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/kotlin/issue8366-inheritance-parent-ctor-call.yaml @@ -0,0 +1,93 @@ +openapi: 3.0.3 +info: + version: "1.0.0" + title: "" +paths: + /documents/v1: + get: + responses: + 200: + description: lorem + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/ParentSchema" +components: + schemas: + JarFiles: + type: array + items: + $ref: "#/components/schemas/JarFile" + JarFile: + type: object + required: + - filename + - contentBase64 + - hasDbMigrations + additionalProperties: true + properties: + filename: + type: string + nullable: false + minLength: 1 + maxLength: 255 + hasDbMigrations: + description: Indicates whether the cordapp jar in question contains any + embedded migrations that Cactus can/should execute between copying the + jar into the cordapp directory and starting the node back up. + type: boolean + nullable: false + contentBase64: + type: string + format: base64 + nullable: false + minLength: 1 + maxLength: 1073741824 + + ParentSchema: + type: object + properties: + id: + type: string + type: + $ref: "#/components/schemas/DiscriminatingType" + discriminator: + propertyName: type + mapping: + subtypeA: "#/components/schemas/SubtypeA" + subtypeB: "#/components/schemas/SubtypeB" + subtypeC: "#/components/schemas/SubtypeC" + SubtypeA: + type: object + allOf: + - $ref: '#/components/schemas/ParentSchema' + - type: object + properties: + subtypeAproperty: + type: integer + SubtypeB: + type: object + allOf: + - $ref: '#/components/schemas/ParentSchema' + - type: object + properties: + subtypeBproperty: + type: string + SubtypeC: + type: object + additionalProperties: true + allOf: + - $ref: '#/components/schemas/ParentSchema' + - type: object + properties: + subtypeAproperty: + type: integer + + DiscriminatingType: + type: string + enum: + - subtypeA + - subtypeB + - subtypeC diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/.openapi-generator-ignore b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/.openapi-generator/FILES b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/.openapi-generator/FILES new file mode 100644 index 000000000000..a58f9967ab7e --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/.openapi-generator/FILES @@ -0,0 +1,23 @@ +README.md +build.gradle.kts +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +pom.xml +settings.gradle +src/main/kotlin/org/openapitools/Application.kt +src/main/kotlin/org/openapitools/HomeController.kt +src/main/kotlin/org/openapitools/api/ApiUtil.kt +src/main/kotlin/org/openapitools/api/DocumentsApiController.kt +src/main/kotlin/org/openapitools/api/DocumentsApiService.kt +src/main/kotlin/org/openapitools/api/DocumentsApiServiceImpl.kt +src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt +src/main/kotlin/org/openapitools/model/DiscriminatingType.kt +src/main/kotlin/org/openapitools/model/JarFile.kt +src/main/kotlin/org/openapitools/model/ParentSchema.kt +src/main/kotlin/org/openapitools/model/SubtypeA.kt +src/main/kotlin/org/openapitools/model/SubtypeB.kt +src/main/kotlin/org/openapitools/model/SubtypeC.kt +src/main/resources/application.yaml +src/main/resources/openapi.yaml diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/.openapi-generator/VERSION b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/.openapi-generator/VERSION new file mode 100644 index 000000000000..186c33c96ed8 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.24.0-SNAPSHOT diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/README.md b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/README.md new file mode 100644 index 000000000000..43b436dbc2a7 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/README.md @@ -0,0 +1,21 @@ +# + +This Kotlin based [Spring Boot](https://spring.io/projects/spring-boot) application has been generated using the [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator). + +## Getting Started + +This document assumes you have either maven or gradle available, either via the wrapper or otherwise. This does not come with a gradle / maven wrapper checked in. + +By default a [`pom.xml`](pom.xml) file will be generated. If you specified `gradleBuildFile=true` when generating this project, a `build.gradle.kts` will also be generated. Note this uses [Gradle Kotlin DSL](https://github.com/gradle/kotlin-dsl). + +To build the project using maven, run: +```bash +mvn package && java -jar target/openapi-spring-1.0.0.jar +``` + +To build the project using gradle, run: +```bash +gradle build && java -jar build/libs/openapi-spring-1.0.0.jar +``` + +If all builds successfully, the server should run on [http://localhost:8080/](http://localhost:8080/) diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/build.gradle.kts b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/build.gradle.kts new file mode 100644 index 000000000000..d41e7c6cee1e --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/build.gradle.kts @@ -0,0 +1,56 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.7") + } +} + +group = "org.openapitools" +version = "1.0.0" + +repositories { + mavenCentral() +} + +tasks.withType { + kotlinOptions.jvmTarget = "11" +} + +plugins { + val kotlinVersion = "1.9.25" + id("org.jetbrains.kotlin.jvm") version kotlinVersion + id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion + id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion + id("org.springframework.boot") version "2.6.7" + id("io.spring.dependency-management") version "1.0.11.RELEASE" +} + +dependencies { + val kotlinxCoroutinesVersion = "1.6.1" + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion") + implementation("org.springdoc:springdoc-openapi-webflux-ui:1.6.8") + + implementation("com.google.code.findbugs:jsr305:3.0.2") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + implementation("org.springframework.data:spring-data-commons") + implementation("org.springframework.boot:spring-boot-starter-validation") + implementation("javax.validation:validation-api") + + implementation("javax.annotation:javax.annotation-api:1.3.2") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") + testImplementation("org.springframework.boot:spring-boot-starter-test") { + exclude(module = "junit") + } + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesVersion") +} diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradle/wrapper/gradle-wrapper.jar b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..e6441136f3d4 Binary files /dev/null and b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..80187ac30432 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradlew b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradlew new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while +APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path +[ -h "$app_path" ] +do +ls=$( ls -ld "$app_path" ) +link=${ls#*' -> '} +case $link in #( +/*) app_path=$link ;; #( +*) app_path=$APP_HOME$link ;; +esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { +echo "$*" +} >&2 + +die () { +echo +echo "$*" +echo +exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( +CYGWIN* ) cygwin=true ;; #( +Darwin* ) darwin=true ;; #( +MSYS* | MINGW* ) msys=true ;; #( +NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then +if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +# IBM's JDK on AIX uses strange locations for the executables +JAVACMD=$JAVA_HOME/jre/sh/java +else +JAVACMD=$JAVA_HOME/bin/java +fi +if [ ! -x "$JAVACMD" ] ; then +die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +else +JAVACMD=java +if ! command -v java >/dev/null 2>&1 +then +die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then +case $MAX_FD in #( +max*) +# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +MAX_FD=$( ulimit -H -n ) || +warn "Could not query maximum file descriptor limit" +esac +case $MAX_FD in #( +'' | soft) :;; #( +*) +# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +ulimit -n "$MAX_FD" || +warn "Could not set maximum file descriptor limit to $MAX_FD" +esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then +APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) +CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + +JAVACMD=$( cygpath --unix "$JAVACMD" ) + +# Now convert the arguments - kludge to limit ourselves to /bin/sh +for arg do +if +case $arg in #( +-*) false ;; # don't mess with options #( +/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath +[ -e "$t" ] ;; #( +*) false ;; +esac +then +arg=$( cygpath --path --ignore --mixed "$arg" ) +fi +# Roll the args list around exactly as many times as the number of +# args, so each arg winds up back in the position where it started, but +# possibly modified. +# +# NB: a `for` loop captures its iteration list before it begins, so +# changing the positional parameters here affects neither the number of +# iterations, nor the values presented in `arg`. +shift # remove old arg +set -- "$@" "$arg" # push replacement arg +done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ +"-Dorg.gradle.appname=$APP_BASE_NAME" \ +-classpath "$CLASSPATH" \ +org.gradle.wrapper.GradleWrapperMain \ +"$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then +die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( +printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | +xargs -n1 | +sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | +tr '\n' ' ' +)" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradlew.bat b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradlew.bat new file mode 100644 index 000000000000..25da30dbdeee --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/pom.xml b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/pom.xml new file mode 100644 index 000000000000..3eec599d0c42 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/pom.xml @@ -0,0 +1,162 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 1.6.1 + 1.6.8 + 3.0.2 + 1.3.2 + 1.6.21 + + 1.6.21 + UTF-8 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.15 + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + spring + + 11 + + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + + + org.springframework.boot + spring-boot-starter-webflux + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + ${kotlinx-coroutines.version} + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + ${kotlinx-coroutines.version} + + + org.springframework.data + spring-data-commons + + + + + org.springdoc + springdoc-openapi-webflux-ui + ${springdoc-openapi.version} + + + + + com.google.code.findbugs + jsr305 + ${findbugs-jsr305.version} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + javax.validation + validation-api + + + org.springframework.boot + spring-boot-starter-validation + + + + javax.annotation + javax.annotation-api + ${javax-annotation.version} + provided + + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin-test-junit5.version} + test + + + org.springframework.boot + spring-boot-starter-test + test + + + diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/settings.gradle b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/settings.gradle new file mode 100644 index 000000000000..14844905cd40 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/settings.gradle @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + maven { url = uri("https://repo.spring.io/snapshot") } + maven { url = uri("https://repo.spring.io/milestone") } + gradlePluginPortal() + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "org.springframework.boot") { + useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}") + } + } + } +} +rootProject.name = "openapi-spring" diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/Application.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/Application.kt new file mode 100644 index 000000000000..2fe6de62479e --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/Application.kt @@ -0,0 +1,13 @@ +package org.openapitools + +import org.springframework.boot.runApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.context.annotation.ComponentScan + +@SpringBootApplication +@ComponentScan(basePackages = ["org.openapitools", "org.openapitools.api", "org.openapitools.model"]) +class Application + +fun main(args: Array) { + runApplication(*args) +} diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/HomeController.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/HomeController.kt new file mode 100644 index 000000000000..78f8cce7d83d --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/HomeController.kt @@ -0,0 +1,26 @@ +package org.openapitools + +import org.springframework.context.annotation.Bean +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.reactive.function.server.HandlerFunction +import org.springframework.web.reactive.function.server.RequestPredicates.GET +import org.springframework.web.reactive.function.server.RouterFunction +import org.springframework.web.reactive.function.server.RouterFunctions.route +import org.springframework.web.reactive.function.server.ServerResponse +import java.net.URI + +/** + * Home redirection to OpenAPI api documentation + */ +@Controller +class HomeController { + + @Bean + fun index(): RouterFunction = route( + GET("/"), HandlerFunction { + ServerResponse.temporaryRedirect(URI.create("swagger-ui.html")).build() + }) +} diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 000000000000..7c275cbf30ed --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,5 @@ +package org.openapitools.api + + +object ApiUtil { +} diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/DocumentsApiController.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/DocumentsApiController.kt new file mode 100644 index 000000000000..c2496d76853b --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/DocumentsApiController.kt @@ -0,0 +1,59 @@ +package org.openapitools.api + +import org.openapitools.model.ParentSchema +import io.swagger.v3.oas.annotations.* +import io.swagger.v3.oas.annotations.enums.* +import io.swagger.v3.oas.annotations.media.* +import io.swagger.v3.oas.annotations.responses.* +import io.swagger.v3.oas.annotations.security.* +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import javax.validation.Valid +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size + +import kotlinx.coroutines.flow.Flow +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +@RequestMapping("\${api.base-path:}") +class DocumentsApiController(@Autowired(required = true) val service: DocumentsApiService) { + + @Operation( + summary = "", + operationId = "documentsV1Get", + description = """""", + responses = [ + ApiResponse(responseCode = "200", description = "lorem", content = [Content(array = ArraySchema(schema = Schema(implementation = ParentSchema::class)))]) ] + ) + @RequestMapping( + method = [RequestMethod.GET], + // "/documents/v1" + value = [PATH_DOCUMENTS_V1_GET], + produces = ["application/json"] + ) + fun documentsV1Get(): ResponseEntity> { + return ResponseEntity(service.documentsV1Get(), HttpStatus.valueOf(200)) + } + + companion object { + //for your own safety never directly reuse these path definitions in tests + const val BASE_PATH: String = "" + const val PATH_DOCUMENTS_V1_GET: String = "/documents/v1" + } +} diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/DocumentsApiService.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/DocumentsApiService.kt new file mode 100644 index 000000000000..5096dd5b2c0a --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/DocumentsApiService.kt @@ -0,0 +1,15 @@ +package org.openapitools.api + +import org.openapitools.model.ParentSchema +import kotlinx.coroutines.flow.Flow + +interface DocumentsApiService { + + /** + * GET /documents/v1 + * + * @return lorem (status code 200) + * @see DocumentsApi#documentsV1Get + */ + fun documentsV1Get(): Flow +} diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/DocumentsApiServiceImpl.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/DocumentsApiServiceImpl.kt new file mode 100644 index 000000000000..d0d12b8b11eb --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/api/DocumentsApiServiceImpl.kt @@ -0,0 +1,12 @@ +package org.openapitools.api + +import org.openapitools.model.ParentSchema +import kotlinx.coroutines.flow.Flow +import org.springframework.stereotype.Service +@Service +class DocumentsApiServiceImpl : DocumentsApiService { + + override fun documentsV1Get(): Flow { + TODO("Implement me") + } +} diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt new file mode 100644 index 000000000000..ad9978696c77 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/configuration/EnumConverterConfiguration.kt @@ -0,0 +1,26 @@ +package org.openapitools.configuration + +import org.openapitools.model.DiscriminatingType + +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.core.convert.converter.Converter + +/** + * This class provides Spring Converter beans for the enum models in the OpenAPI specification. + * + * By default, Spring only converts primitive types to enums using Enum::valueOf, which can prevent + * correct conversion if the OpenAPI specification is using an `enumPropertyNaming` other than + * `original` or the specification has an integer enum. + */ +@Configuration(value = "org.openapitools.configuration.enumConverterConfiguration") +class EnumConverterConfiguration { + + @Bean(name = ["org.openapitools.configuration.EnumConverterConfiguration.discriminatingTypeConverter"]) + fun discriminatingTypeConverter(): Converter { + return object: Converter { + override fun convert(source: kotlin.String): DiscriminatingType = DiscriminatingType.forValue(source) + } + } + +} diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/DiscriminatingType.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/DiscriminatingType.kt new file mode 100644 index 000000000000..4696ef399118 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/DiscriminatingType.kt @@ -0,0 +1,37 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonValue +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid +import io.swagger.v3.oas.annotations.media.Schema + +/** +* +* Values: subtypeA,subtypeB,subtypeC +*/ +enum class DiscriminatingType(@get:JsonValue val value: kotlin.String) { + + subtypeA("subtypeA"), + subtypeB("subtypeB"), + subtypeC("subtypeC"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): DiscriminatingType { + return values().firstOrNull{it -> it.value == value} + ?: throw IllegalArgumentException("Unexpected value '$value' for enum 'DiscriminatingType'") + } + } +} + diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/JarFile.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/JarFile.kt new file mode 100644 index 000000000000..c22519c3fa81 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/JarFile.kt @@ -0,0 +1,40 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonProperty +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid +import io.swagger.v3.oas.annotations.media.Schema + +/** + * + * @param filename + * @param hasDbMigrations Indicates whether the cordapp jar in question contains any embedded migrations that Cactus can/should execute between copying the jar into the cordapp directory and starting the node back up. + * @param contentBase64 + */ +data class JarFile( + + @get:Size(min=1,max=255) + @Schema(example = "null", required = true, description = "") + @param:JsonProperty("filename") + @get:JsonProperty("filename", required = true) val filename: kotlin.String, + + @Schema(example = "null", required = true, description = "Indicates whether the cordapp jar in question contains any embedded migrations that Cactus can/should execute between copying the jar into the cordapp directory and starting the node back up.") + @param:JsonProperty("hasDbMigrations") + @get:JsonProperty("hasDbMigrations", required = true) val hasDbMigrations: kotlin.Boolean, + + @get:Size(min=1,max=1073741824) + @Schema(example = "null", required = true, description = "") + @param:JsonProperty("contentBase64") + @get:JsonProperty("contentBase64", required = true) val contentBase64: kotlin.String +) : kotlin.collections.HashMap() { + +} + diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/ParentSchema.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/ParentSchema.kt new file mode 100644 index 000000000000..2c1e6d12c402 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/ParentSchema.kt @@ -0,0 +1,50 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonSetter +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo +import com.fasterxml.jackson.annotation.JsonValue +import com.fasterxml.jackson.annotation.Nulls +import org.openapitools.model.DiscriminatingType +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid +import io.swagger.v3.oas.annotations.media.Schema + +/** + * + * @param id + * @param type + */ +@JsonIgnoreProperties( + value = ["type"], // ignore manually set type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the type to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true) +@JsonSubTypes( + JsonSubTypes.Type(value = SubtypeA::class, name = "subtypeA"), + JsonSubTypes.Type(value = SubtypeB::class, name = "subtypeB"), + JsonSubTypes.Type(value = SubtypeC::class, name = "subtypeC") +) + +interface ParentSchema { + @get:Schema(example = "null", description = "") + val id: kotlin.String? + + @get:Schema(example = "null", description = "") + val type: DiscriminatingType? + + +} + diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/SubtypeA.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/SubtypeA.kt new file mode 100644 index 000000000000..5215e6964859 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/SubtypeA.kt @@ -0,0 +1,52 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonSetter +import com.fasterxml.jackson.annotation.JsonValue +import com.fasterxml.jackson.annotation.Nulls +import org.openapitools.model.DiscriminatingType +import org.openapitools.model.ParentSchema +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid +import io.swagger.v3.oas.annotations.media.Schema + +/** + * + * @param subtypeAproperty + * @param id + * @param type + */ +data class SubtypeA( + + @Schema(example = "null", description = "") + @field:JsonInclude(JsonInclude.Include.NON_NULL) + @field:JsonSetter(nulls = Nulls.SKIP) + @param:JsonProperty("subtypeAproperty") + @get:JsonProperty("subtypeAproperty") val subtypeAproperty: kotlin.Int? = null, + + @Schema(example = "null", description = "") + @field:JsonInclude(JsonInclude.Include.NON_NULL) + @field:JsonSetter(nulls = Nulls.SKIP) + @param:JsonProperty("id") + @get:JsonProperty("id") override val id: kotlin.String? = null, + + @field:Valid + @Schema(example = "null", description = "") + @field:JsonInclude(JsonInclude.Include.NON_NULL) + @field:JsonSetter(nulls = Nulls.SKIP) + @param:JsonProperty("type") + @get:JsonProperty("type") override val type: DiscriminatingType? = null +) : ParentSchema { + +} + diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/SubtypeB.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/SubtypeB.kt new file mode 100644 index 000000000000..62ec559a2ae7 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/SubtypeB.kt @@ -0,0 +1,52 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonSetter +import com.fasterxml.jackson.annotation.JsonValue +import com.fasterxml.jackson.annotation.Nulls +import org.openapitools.model.DiscriminatingType +import org.openapitools.model.ParentSchema +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid +import io.swagger.v3.oas.annotations.media.Schema + +/** + * + * @param subtypeBproperty + * @param id + * @param type + */ +data class SubtypeB( + + @Schema(example = "null", description = "") + @field:JsonInclude(JsonInclude.Include.NON_NULL) + @field:JsonSetter(nulls = Nulls.SKIP) + @param:JsonProperty("subtypeBproperty") + @get:JsonProperty("subtypeBproperty") val subtypeBproperty: kotlin.String? = null, + + @Schema(example = "null", description = "") + @field:JsonInclude(JsonInclude.Include.NON_NULL) + @field:JsonSetter(nulls = Nulls.SKIP) + @param:JsonProperty("id") + @get:JsonProperty("id") override val id: kotlin.String? = null, + + @field:Valid + @Schema(example = "null", description = "") + @field:JsonInclude(JsonInclude.Include.NON_NULL) + @field:JsonSetter(nulls = Nulls.SKIP) + @param:JsonProperty("type") + @get:JsonProperty("type") override val type: DiscriminatingType? = null +) : ParentSchema { + +} + diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/SubtypeC.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/SubtypeC.kt new file mode 100644 index 000000000000..4021077e9a1f --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/kotlin/org/openapitools/model/SubtypeC.kt @@ -0,0 +1,52 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonSetter +import com.fasterxml.jackson.annotation.JsonValue +import com.fasterxml.jackson.annotation.Nulls +import org.openapitools.model.DiscriminatingType +import org.openapitools.model.ParentSchema +import javax.validation.constraints.DecimalMax +import javax.validation.constraints.DecimalMin +import javax.validation.constraints.Email +import javax.validation.constraints.Max +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull +import javax.validation.constraints.Pattern +import javax.validation.constraints.Size +import javax.validation.Valid +import io.swagger.v3.oas.annotations.media.Schema + +/** + * + * @param subtypeAproperty + * @param id + * @param type + */ +data class SubtypeC( + + @Schema(example = "null", description = "") + @field:JsonInclude(JsonInclude.Include.NON_NULL) + @field:JsonSetter(nulls = Nulls.SKIP) + @param:JsonProperty("subtypeAproperty") + @get:JsonProperty("subtypeAproperty") val subtypeAproperty: kotlin.Int? = null, + + @Schema(example = "null", description = "") + @field:JsonInclude(JsonInclude.Include.NON_NULL) + @field:JsonSetter(nulls = Nulls.SKIP) + @param:JsonProperty("id") + @get:JsonProperty("id") override val id: kotlin.String? = null, + + @field:Valid + @Schema(example = "null", description = "") + @field:JsonInclude(JsonInclude.Include.NON_NULL) + @field:JsonSetter(nulls = Nulls.SKIP) + @param:JsonProperty("type") + @get:JsonProperty("type") override val type: DiscriminatingType? = null +) : ParentSchema { + +} + diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/resources/application.yaml b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/resources/application.yaml new file mode 100644 index 000000000000..ce8dd418ac3d --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/resources/application.yaml @@ -0,0 +1,10 @@ +spring: + application: + name: + + jackson: + serialization: + WRITE_DATES_AS_TIMESTAMPS: false + +server: + port: 8080 diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/resources/openapi.yaml b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/resources/openapi.yaml new file mode 100644 index 000000000000..b4069ce0c653 --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/main/resources/openapi.yaml @@ -0,0 +1,96 @@ +openapi: 3.0.3 +info: + title: "" + version: 1.0.0 +servers: +- url: / +paths: + /documents/v1: + get: + responses: + "200": + content: + application/json: + schema: + items: + $ref: "#/components/schemas/ParentSchema" + type: array + description: lorem +components: + schemas: + JarFiles: + items: + $ref: "#/components/schemas/JarFile" + type: array + JarFile: + additionalProperties: true + properties: + filename: + maxLength: 255 + minLength: 1 + nullable: false + type: string + hasDbMigrations: + description: Indicates whether the cordapp jar in question contains any + embedded migrations that Cactus can/should execute between copying the + jar into the cordapp directory and starting the node back up. + nullable: false + type: boolean + contentBase64: + format: base64 + maxLength: 1073741824 + minLength: 1 + nullable: false + type: string + required: + - contentBase64 + - filename + - hasDbMigrations + type: object + ParentSchema: + discriminator: + mapping: + subtypeA: "#/components/schemas/SubtypeA" + subtypeB: "#/components/schemas/SubtypeB" + subtypeC: "#/components/schemas/SubtypeC" + propertyName: type + example: + id: id + type: subtypeA + properties: + id: + type: string + type: + $ref: "#/components/schemas/DiscriminatingType" + type: object + SubtypeA: + allOf: + - $ref: "#/components/schemas/ParentSchema" + - properties: + subtypeAproperty: + type: integer + type: object + type: object + SubtypeB: + allOf: + - $ref: "#/components/schemas/ParentSchema" + - properties: + subtypeBproperty: + type: string + type: object + type: object + SubtypeC: + additionalProperties: true + allOf: + - $ref: "#/components/schemas/ParentSchema" + - properties: + subtypeAproperty: + type: integer + type: object + type: object + DiscriminatingType: + enum: + - subtypeA + - subtypeB + - subtypeC + type: string diff --git a/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/test/kotlin/org/openapitools/api/DocumentsApiTest.kt b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/test/kotlin/org/openapitools/api/DocumentsApiTest.kt new file mode 100644 index 000000000000..6da88dc7b51e --- /dev/null +++ b/samples/server/petstore/kotlin-spring-issue8366-inheritance-parent-ctor-call/src/test/kotlin/org/openapitools/api/DocumentsApiTest.kt @@ -0,0 +1,26 @@ +package org.openapitools.api + +import org.openapitools.model.ParentSchema +import org.junit.jupiter.api.Test +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.test.runBlockingTest +import org.springframework.http.ResponseEntity + +class DocumentsApiTest { + + private val service: DocumentsApiService = DocumentsApiServiceImpl() + private val api: DocumentsApiController = DocumentsApiController(service) + + /** + * To test DocumentsApiController.documentsV1Get + * + * @throws ApiException + * if the Api call fails + */ + @Test + fun documentsV1GetTest() = runBlockingTest { + val response: ResponseEntity> = api.documentsV1Get() + + // TODO: test validations + } +}