diff --git a/bin/configs/kotlin-spring-boot-integer-enum.yaml b/bin/configs/kotlin-spring-boot-integer-enum.yaml new file mode 100644 index 00000000000..8298ce6be08 --- /dev/null +++ b/bin/configs/kotlin-spring-boot-integer-enum.yaml @@ -0,0 +1,13 @@ +generatorName: kotlin-spring +outputDir: samples/server/petstore/kotlin-springboot-integer-enum +library: spring-boot +inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/issue19244_integer_enum.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-spring +additionalProperties: + interfaceOnly: "true" + skipDefaultInterface: "true" + useTags: "true" + useSpringBoot3: "true" + annotationLibrary: none + documentationProvider: none + enumPropertyNaming: UPPERCASE diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java index e8f251fd483..4c50581c0bb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java @@ -815,6 +815,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen model.imports.add("JsonProperty"); if (Boolean.TRUE.equals(model.hasEnums)) { model.imports.add("JsonValue"); + model.imports.add("JsonCreator"); } } else { //Needed imports for Jackson's JsonCreator @@ -840,10 +841,14 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen .filter(cm -> Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) .forEach(cm -> { cm.imports.add(importMapping.get("JsonValue")); + cm.imports.add(importMapping.get("JsonCreator")); cm.imports.add(importMapping.get("JsonProperty")); Map itemJsonValue = new HashMap<>(); itemJsonValue.put("import", importMapping.get("JsonValue")); imports.add(itemJsonValue); + Map itemJsonCreator = new HashMap<>(); + itemJsonCreator.put("import", importMapping.get("JsonCreator")); + imports.add(itemJsonCreator); Map itemJsonProperty = new HashMap<>(); itemJsonProperty.put("import", importMapping.get("JsonProperty")); imports.add(itemJsonProperty); 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 9b58b57a41b..3e3c269dc61 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache @@ -31,9 +31,17 @@ * {{{description}}} * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} */ - enum class {{{nameInPascalCase}}}(val value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}) { + enum class {{{nameInPascalCase}}}(@get:JsonValue val value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}) { {{#allowableValues}}{{#enumVars}} - @JsonProperty({{{value}}}) {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} + {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}; + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}): {{{nameInPascalCase}}} { + return values().first{it -> it.value == value} + } + } } {{/isEnum}}{{/vars}}{{/hasEnums}} {{#serializableModel}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/enumClass.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/enumClass.mustache index 572875356af..fafbb66708d 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/enumClass.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/enumClass.mustache @@ -2,7 +2,15 @@ * {{{description}}} * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} */ -enum class {{classname}}(val value: {{dataType}}) { +enum class {{classname}}(@get:JsonValue val value: {{dataType}}) { {{#allowableValues}}{{#enumVars}} - @JsonProperty({{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} + {{&name}}({{{value}}}){{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}; + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: {{dataType}}): {{classname}} { + return values().first{it -> it.value == value} + } + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/kotlin/issue19244_integer_enum.yaml b/modules/openapi-generator/src/test/resources/3_0/kotlin/issue19244_integer_enum.yaml new file mode 100644 index 00000000000..bbcff074c71 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/kotlin/issue19244_integer_enum.yaml @@ -0,0 +1,46 @@ +openapi: 3.0.3 +info: + description: >- + Example created + version: 1.0.0 + title: OpenAPI Stuff API created to reproduce issue + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' +paths: + /healthcheck: + get: + summary: Health check endpoint. + operationId: healthcheck + responses: + 204: + description: Successful health check + default: + description: Unexpected error + content: + 'application/json': + schema: + $ref: '#/components/schemas/ApiError' + +components: + schemas: + ApiError: + required: + - errorCode + type: object + properties: + errorCode: + type: integer + enum: + - 0 + - 100 + x-enum-varnames: + - OK + - ERROR + reasonCode: + $ref: '#/components/schemas/ReasonCode' + ReasonCode: + type: integer + enum: + - 10 + - 20 diff --git a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Order.kt index 845f39a5b77..e88107612a1 100644 --- a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import java.io.Serializable @@ -42,11 +43,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Pet.kt index a7bd444a071..c18e094b919 100644 --- a/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-spring-cloud/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -47,11 +48,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPet.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPet.kt index 58c2718005f..857abc14b17 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPet.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -83,11 +84,19 @@ data class AnyOfUserOrPet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPetOrArrayString.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPetOrArrayString.kt index 89350ba0920..10b9afe6a13 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPetOrArrayString.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/AnyOfUserOrPetOrArrayString.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -83,11 +84,19 @@ data class AnyOfUserOrPetOrArrayString( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Order.kt index 128eee7f628..0d3f1978748 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import javax.validation.constraints.DecimalMax @@ -48,11 +49,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Pet.kt index 12a5a585b40..128cd0840fd 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -53,11 +54,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPet.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPet.kt index a332ca3e87b..6f1df02b9ca 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPet.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -83,11 +84,19 @@ data class UserOrPet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPetOrArrayString.kt b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPetOrArrayString.kt index 0a39fac9f4d..fcaaa92a2f1 100644 --- a/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPetOrArrayString.kt +++ b/samples/server/petstore/kotlin-spring-default/src/main/kotlin/org/openapitools/model/UserOrPetOrArrayString.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -83,11 +84,19 @@ data class UserOrPetOrArrayString( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Order.kt index 443fcf79c33..995c2c48498 100644 --- a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import java.io.Serializable @@ -42,11 +43,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Pet.kt index c7730d10e37..cfeae46e08a 100644 --- a/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-3/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -47,11 +48,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Order.kt index 1ffd604abeb..934a82a19cb 100644 --- a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import jakarta.validation.constraints.DecimalMax @@ -48,11 +49,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Pet.kt index 3073f0ea9ee..2001adf693e 100644 --- a/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-delegate-nodefaults/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -53,11 +54,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Order.kt index 128eee7f628..0d3f1978748 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import javax.validation.constraints.DecimalMax @@ -48,11 +49,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Pet.kt index 12a5a585b40..128cd0840fd 100644 --- a/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-delegate/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -53,11 +54,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/.openapi-generator-ignore b/samples/server/petstore/kotlin-springboot-integer-enum/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/.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-springboot-integer-enum/.openapi-generator/FILES b/samples/server/petstore/kotlin-springboot-integer-enum/.openapi-generator/FILES new file mode 100644 index 00000000000..210f79aeeaa --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/.openapi-generator/FILES @@ -0,0 +1,9 @@ +README.md +build.gradle.kts +pom.xml +settings.gradle +src/main/kotlin/org/openapitools/api/ApiUtil.kt +src/main/kotlin/org/openapitools/api/DefaultApi.kt +src/main/kotlin/org/openapitools/api/Exceptions.kt +src/main/kotlin/org/openapitools/model/ApiError.kt +src/main/kotlin/org/openapitools/model/ReasonCode.kt diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/.openapi-generator/VERSION b/samples/server/petstore/kotlin-springboot-integer-enum/.openapi-generator/VERSION new file mode 100644 index 00000000000..6116b14d2c5 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.8.0-SNAPSHOT diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/README.md b/samples/server/petstore/kotlin-springboot-integer-enum/README.md new file mode 100644 index 00000000000..e45035f878f --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/README.md @@ -0,0 +1,21 @@ +# openAPIStuffAPICreatedToReproduceIssue + +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-springboot-integer-enum/build.gradle.kts b/samples/server/petstore/kotlin-springboot-integer-enum/build.gradle.kts new file mode 100644 index 00000000000..02857aa8582 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/build.gradle.kts @@ -0,0 +1,46 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +group = "org.openapitools" +version = "1.0.0" +java.sourceCompatibility = JavaVersion.VERSION_17 + +repositories { + mavenCentral() + maven { url = uri("https://repo.spring.io/milestone") } +} + +tasks.withType { + kotlinOptions.jvmTarget = "17" +} + +tasks.bootJar { + enabled = false +} + +plugins { + val kotlinVersion = "1.7.10" + id("org.jetbrains.kotlin.jvm") version kotlinVersion + id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion + id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion + id("org.springframework.boot") version "3.0.2" + id("io.spring.dependency-management") version "1.0.14.RELEASE" +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.springframework.boot:spring-boot-starter-web") + + implementation("com.google.code.findbugs:jsr305:3.0.2") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + implementation("jakarta.validation:jakarta.validation-api") + implementation("jakarta.annotation:jakarta.annotation-api:2.1.0") + + testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") + testImplementation("org.springframework.boot:spring-boot-starter-test") { + exclude(module = "junit") + } +} diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/pom.xml b/samples/server/petstore/kotlin-springboot-integer-enum/pom.xml new file mode 100644 index 00000000000..975b084d5a3 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/pom.xml @@ -0,0 +1,132 @@ + + 4.0.0 + org.openapitools + openapi-spring + jar + openapi-spring + 1.0.0 + + 3.0.2 + 2.1.0 + 1.7.10 + + 1.7.10 + UTF-8 + + + org.springframework.boot + spring-boot-starter-parent + 3.1.3 + + + + repository.spring.milestone + Spring Milestone Repository + https://repo.spring.io/milestone + + + + + spring-milestones + https://repo.spring.io/milestone + + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + spring + + 17 + + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + + + org.springframework.boot + spring-boot-starter-web + + + + + + + com.google.code.findbugs + jsr305 + ${findbugs-jsr305.version} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + jakarta.validation + jakarta.validation-api + + + jakarta.annotation + jakarta.annotation-api + ${jakarta-annotation.version} + provided + + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin-test-junit5.version} + test + + + diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/settings.gradle b/samples/server/petstore/kotlin-springboot-integer-enum/settings.gradle new file mode 100644 index 00000000000..14844905cd4 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/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-springboot-integer-enum/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/ApiUtil.kt new file mode 100644 index 00000000000..03344e13b47 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -0,0 +1,19 @@ +package org.openapitools.api + +import org.springframework.web.context.request.NativeWebRequest + +import jakarta.servlet.http.HttpServletResponse +import java.io.IOException + +object ApiUtil { + fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { + try { + val res = req.getNativeResponse(HttpServletResponse::class.java) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) + } catch (e: IOException) { + throw RuntimeException(e) + } + } +} diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/DefaultApi.kt b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/DefaultApi.kt new file mode 100644 index 00000000000..247310c636b --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/DefaultApi.kt @@ -0,0 +1,42 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. +*/ +package org.openapitools.api + +import org.openapitools.model.ApiError +import org.springframework.http.HttpStatus +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity + +import org.springframework.web.bind.annotation.* +import org.springframework.validation.annotation.Validated +import org.springframework.web.context.request.NativeWebRequest +import org.springframework.beans.factory.annotation.Autowired + +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +import kotlin.collections.List +import kotlin.collections.Map + +@RestController +@Validated +interface DefaultApi { + + + @RequestMapping( + method = [RequestMethod.GET], + value = ["/healthcheck"], + produces = ["application/json"] + ) + fun healthcheck(): ResponseEntity +} diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/Exceptions.kt b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/Exceptions.kt new file mode 100644 index 00000000000..117161bf65b --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/api/Exceptions.kt @@ -0,0 +1,29 @@ +package org.openapitools.api + +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.bind.annotation.ExceptionHandler +import jakarta.servlet.http.HttpServletResponse +import jakarta.validation.ConstraintViolationException + +// TODO Extend ApiException for custom exception handling, e.g. the below NotFound exception +sealed class ApiException(msg: String, val code: Int) : Exception(msg) + +class NotFoundException(msg: String, code: Int = HttpStatus.NOT_FOUND.value()) : ApiException(msg, code) + + +@ControllerAdvice +class DefaultExceptionHandler { + + @ExceptionHandler(value = [ApiException::class]) + fun onApiException(ex: ApiException, response: HttpServletResponse): Unit = + response.sendError(ex.code, ex.message) + + @ExceptionHandler(value = [NotImplementedError::class]) + fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.NOT_IMPLEMENTED.value()) + + @ExceptionHandler(value = [ConstraintViolationException::class]) + fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit = + response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message }) +} diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/model/ApiError.kt b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/model/ApiError.kt new file mode 100644 index 00000000000..781c98346dd --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/model/ApiError.kt @@ -0,0 +1,50 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +import org.openapitools.model.ReasonCode +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** + * + * @param errorCode + * @param reasonCode + */ +data class ApiError( + + @get:JsonProperty("errorCode", required = true) val errorCode: ApiError.ErrorCode, + + @field:Valid + @get:JsonProperty("reasonCode") val reasonCode: ReasonCode? = null +) { + + /** + * + * Values: OK,ERROR + */ + enum class ErrorCode(@get:JsonValue val value: kotlin.Int) { + + OK(0), + ERROR(100); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.Int): ErrorCode { + return values().first{it -> it.value == value} + } + } + } + +} + diff --git a/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/model/ReasonCode.kt b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/model/ReasonCode.kt new file mode 100644 index 00000000000..45260d39027 --- /dev/null +++ b/samples/server/petstore/kotlin-springboot-integer-enum/src/main/kotlin/org/openapitools/model/ReasonCode.kt @@ -0,0 +1,34 @@ +package org.openapitools.model + +import java.util.Objects +import com.fasterxml.jackson.annotation.JsonValue +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import jakarta.validation.constraints.DecimalMax +import jakarta.validation.constraints.DecimalMin +import jakarta.validation.constraints.Email +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size +import jakarta.validation.Valid + +/** +* +* Values: _10,_20 +*/ +enum class ReasonCode(@get:JsonValue val value: kotlin.Int) { + + _10(10), + _20(20); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.Int): ReasonCode { + return values().first{it -> it.value == value} + } + } +} + diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Order.kt index 769e664eb28..85a58b135ce 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import java.io.Serializable @@ -49,11 +50,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt index 0a9670013c7..4fa40697432 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -53,11 +54,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot-multipart-request-model/src/main/kotlin/org/openapitools/model/MultipartMixedStatus.kt b/samples/server/petstore/kotlin-springboot-multipart-request-model/src/main/kotlin/org/openapitools/model/MultipartMixedStatus.kt index ed53fb8b4b4..9f5236caf24 100644 --- a/samples/server/petstore/kotlin-springboot-multipart-request-model/src/main/kotlin/org/openapitools/model/MultipartMixedStatus.kt +++ b/samples/server/petstore/kotlin-springboot-multipart-request-model/src/main/kotlin/org/openapitools/model/MultipartMixedStatus.kt @@ -2,6 +2,7 @@ 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 @@ -18,10 +19,18 @@ import io.swagger.v3.oas.annotations.media.Schema * additional field as Enum * Values: ALLOWED,IN_PROGRESS,REJECTED */ -enum class MultipartMixedStatus(val value: kotlin.String) { +enum class MultipartMixedStatus(@get:JsonValue val value: kotlin.String) { - @JsonProperty("ALLOWED") ALLOWED("ALLOWED"), - @JsonProperty("IN_PROGRESS") IN_PROGRESS("IN_PROGRESS"), - @JsonProperty("REJECTED") REJECTED("REJECTED") + ALLOWED("ALLOWED"), + IN_PROGRESS("IN_PROGRESS"), + REJECTED("REJECTED"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): MultipartMixedStatus { + return values().first{it -> it.value == value} + } + } } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Order.kt index 128eee7f628..0d3f1978748 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import javax.validation.constraints.DecimalMax @@ -48,11 +49,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Pet.kt index cab156b8818..b16c5ecc2fa 100644 --- a/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-reactive/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -52,11 +53,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Order.kt index 14135c9174a..ce5bc44289a 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import jakarta.validation.constraints.DecimalMax @@ -48,11 +49,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Pet.kt index 4c2dbad8ccd..daa58001722 100644 --- a/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-request-cookie/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -52,11 +53,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-request/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-request/src/main/kotlin/org/openapitools/model/Order.kt index 1ffd604abeb..934a82a19cb 100644 --- a/samples/server/petstore/kotlin-springboot-request/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-request/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import jakarta.validation.constraints.DecimalMax @@ -48,11 +49,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-request/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-request/src/main/kotlin/org/openapitools/model/Pet.kt index 267ba7c318f..867ed6f4377 100644 --- a/samples/server/petstore/kotlin-springboot-request/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-request/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -52,11 +53,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } } diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Order.kt index db97db56162..b0ed69e5dd5 100644 --- a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import java.io.Serializable @@ -49,11 +50,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Pet.kt index 287bd0385d5..9a0f10f1ae4 100644 --- a/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-source-swagger1/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -53,11 +54,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Order.kt index ee8dfc62c6a..1eeebebaed2 100644 --- a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import java.io.Serializable @@ -49,11 +50,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Pet.kt index f8f0488dbcc..71e6bb48dab 100644 --- a/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-source-swagger2/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -53,11 +54,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Order.kt index db97db56162..b0ed69e5dd5 100644 --- a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import java.io.Serializable @@ -49,11 +50,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Pet.kt index 287bd0385d5..9a0f10f1ae4 100644 --- a/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot-springfox/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -53,11 +54,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt index 845f39a5b77..e88107612a1 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Order.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import java.io.Serializable @@ -42,11 +43,19 @@ data class Order( * Order Status * Values: placed,approved,delivered */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("placed") placed("placed"), - @JsonProperty("approved") approved("approved"), - @JsonProperty("delivered") delivered("delivered") + placed("placed"), + approved("approved"), + delivered("delivered"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object { diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Pet.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Pet.kt index a6dbb60fb01..1467db4160b 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Pet.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/model/Pet.kt @@ -1,6 +1,7 @@ package org.openapitools.model import java.util.Objects +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonValue import org.openapitools.model.Category @@ -46,11 +47,19 @@ data class Pet( * pet status in the store * Values: available,pending,sold */ - enum class Status(val value: kotlin.String) { + enum class Status(@get:JsonValue val value: kotlin.String) { - @JsonProperty("available") available("available"), - @JsonProperty("pending") pending("pending"), - @JsonProperty("sold") sold("sold") + available("available"), + pending("pending"), + sold("sold"); + + companion object { + @JvmStatic + @JsonCreator + fun forValue(value: kotlin.String): Status { + return values().first{it -> it.value == value} + } + } } companion object {