From 4f8d61c05cea0fb6bdbd9220b478a74e387298c1 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 27 Sep 2023 13:45:59 +0800 Subject: [PATCH] fix kotlin enum name (#16666) --- .../kotlin-client/data_class.mustache | 10 +- .../kotlin-client/enum_class.mustache | 10 +- .../kotlin/issue10591-enum-defaultValue.yaml | 78 ++++++++++ .../.openapi-generator/FILES | 2 + .../kotlin-enum-default-value/README.md | 1 + .../docs/PropertyOfDay.md | 36 +++++ .../client/infrastructure/SerializerHelper.kt | 6 + .../client/models/PropertyOfDay.kt | 135 ++++++++++++++++++ 8 files changed, 268 insertions(+), 10 deletions(-) create mode 100644 samples/client/petstore/kotlin-enum-default-value/docs/PropertyOfDay.md create mode 100644 samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/models/PropertyOfDay.kt diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache index f4f6e64d6b7..c91f42078fa 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/data_class.mustache @@ -108,20 +108,20 @@ import {{packageName}}.infrastructure.ITransformForStorage {{#enumVars}} {{^multiplatform}} {{#moshi}} - @Json(name = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} + @Json(name = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} {{/moshi}} {{#gson}} - @SerializedName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} + @SerializedName(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} {{/gson}} {{#jackson}} - @JsonProperty(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} + @JsonProperty(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} {{/jackson}} {{#kotlinx_serialization}} - @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} + @SerialName(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} {{/kotlinx_serialization}} {{/multiplatform}} {{#multiplatform}} - @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} + @SerialName(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} {{/multiplatform}} {{/enumVars}} {{/allowableValues}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache index 7d3793d57e5..a7c9a0fbe09 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache @@ -40,20 +40,20 @@ import kotlinx.serialization.* {{#allowableValues}}{{#enumVars}} {{^multiplatform}} {{#moshi}} - @Json(name = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) + @Json(name = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{/moshi}} {{#gson}} - @SerializedName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) + @SerializedName(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{/gson}} {{#jackson}} - @JsonProperty(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) + @JsonProperty(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{/jackson}} {{#kotlinx_serialization}} - @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) + @SerialName(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{/kotlinx_serialization}} {{/multiplatform}} {{#multiplatform}} - @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) + @SerialName(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{/multiplatform}} {{#isArray}} {{#isList}} diff --git a/modules/openapi-generator/src/test/resources/3_0/kotlin/issue10591-enum-defaultValue.yaml b/modules/openapi-generator/src/test/resources/3_0/kotlin/issue10591-enum-defaultValue.yaml index 73b3547c2e2..531c1d0de02 100644 --- a/modules/openapi-generator/src/test/resources/3_0/kotlin/issue10591-enum-defaultValue.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/kotlin/issue10591-enum-defaultValue.yaml @@ -24,3 +24,81 @@ components: default: VALUE enum: - VALUE + PropertyOfDay: + required: + - name + type: object + properties: + name: + type: string + description: Name of property of day + example: Monday + description: + type: string + description: Description of the property of day + example: Days family discount is available + daysOfWeek: + type: object + description: Days of week + example: + - MONDAY + - TUESDAY + enum: + - MONDAY + - TUESDAY + - WEDNESDAY + - THURSDAY + - FRIDAY + - SATURDAY + - SUNDAY + - WEEKDAYS + - WEEKEND + - EVERYDAY + monthOfYear: + type: integer + description: Month of year + format: int32 + enum: + - 1 + - 2 + - 3 + - 4 + - 5 + - 6 + - 7 + - 8 + - 9 + - 10 + - 11 + - 12 + dayOfYear: + type: integer + description: Day of year + format: int32 + holidayTypes: + type: object + description: Holiday types + example: + - NOT_HOLIDAY + - LOCAL_HOLIDAY + enum: + - NOT_HOLIDAY + - LOCAL_HOLIDAY + - NATIONAL_HOLIDAY + - ANY_HOLIDAY + - WORKING_DAY + - ANY_DAY + - NEW_YEARS_DAY + - PALM_SUNDAY + - MAUNDY_THURSDAY + - GOOD_FRIDAY + - EASTER_SUNDAY + - EASTER_MONDAY + - LABOUR_DAY + - CONSTITUTION_DAY + - ASCENSION_DAY + - WHIT_SUNDAY + - WHIT_MONDAY + - CHRISTMAS_DAY + - BOXING_DAY + description: The DayType describe during which the assignment applies diff --git a/samples/client/petstore/kotlin-enum-default-value/.openapi-generator/FILES b/samples/client/petstore/kotlin-enum-default-value/.openapi-generator/FILES index 23e025a3bba..5ae41b2e84f 100644 --- a/samples/client/petstore/kotlin-enum-default-value/.openapi-generator/FILES +++ b/samples/client/petstore/kotlin-enum-default-value/.openapi-generator/FILES @@ -2,6 +2,7 @@ README.md build.gradle docs/DefaultApi.md docs/ModelWithEnumPropertyHavingDefault.md +docs/PropertyOfDay.md gradle/wrapper/gradle-wrapper.jar gradle/wrapper/gradle-wrapper.properties gradlew @@ -27,3 +28,4 @@ src/main/kotlin/org/openapitools/client/infrastructure/SerializerHelper.kt src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt src/main/kotlin/org/openapitools/client/models/ModelWithEnumPropertyHavingDefault.kt +src/main/kotlin/org/openapitools/client/models/PropertyOfDay.kt diff --git a/samples/client/petstore/kotlin-enum-default-value/README.md b/samples/client/petstore/kotlin-enum-default-value/README.md index 8d62cff3f8c..80957d49b53 100644 --- a/samples/client/petstore/kotlin-enum-default-value/README.md +++ b/samples/client/petstore/kotlin-enum-default-value/README.md @@ -51,6 +51,7 @@ Class | Method | HTTP request | Description ## Documentation for Models - [org.openapitools.client.models.ModelWithEnumPropertyHavingDefault](docs/ModelWithEnumPropertyHavingDefault.md) + - [org.openapitools.client.models.PropertyOfDay](docs/PropertyOfDay.md) diff --git a/samples/client/petstore/kotlin-enum-default-value/docs/PropertyOfDay.md b/samples/client/petstore/kotlin-enum-default-value/docs/PropertyOfDay.md new file mode 100644 index 00000000000..1b642d0d043 --- /dev/null +++ b/samples/client/petstore/kotlin-enum-default-value/docs/PropertyOfDay.md @@ -0,0 +1,36 @@ + +# PropertyOfDay + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **kotlin.String** | Name of property of day | +**description** | **kotlin.String** | Description of the property of day | [optional] +**daysOfWeek** | [**inline**](#DaysOfWeek) | Days of week | [optional] +**monthOfYear** | [**inline**](#MonthOfYear) | Month of year | [optional] +**dayOfYear** | **kotlin.Int** | Day of year | [optional] +**holidayTypes** | [**inline**](#HolidayTypes) | Holiday types | [optional] + + + +## Enum: daysOfWeek +Name | Value +---- | ----- +daysOfWeek | MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY, WEEKDAYS, WEEKEND, EVERYDAY + + + +## Enum: monthOfYear +Name | Value +---- | ----- +monthOfYear | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 + + + +## Enum: holidayTypes +Name | Value +---- | ----- +holidayTypes | NOT_HOLIDAY, LOCAL_HOLIDAY, NATIONAL_HOLIDAY, ANY_HOLIDAY, WORKING_DAY, ANY_DAY, NEW_YEARS_DAY, PALM_SUNDAY, MAUNDY_THURSDAY, GOOD_FRIDAY, EASTER_SUNDAY, EASTER_MONDAY, LABOUR_DAY, CONSTITUTION_DAY, ASCENSION_DAY, WHIT_SUNDAY, WHIT_MONDAY, CHRISTMAS_DAY, BOXING_DAY + + + diff --git a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/SerializerHelper.kt b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/SerializerHelper.kt index d3789e4823b..22bead5fec8 100644 --- a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/SerializerHelper.kt +++ b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure/SerializerHelper.kt @@ -8,5 +8,11 @@ object SerializerHelper { return moshiBuilder .add(org.openapitools.client.models.ModelWithEnumPropertyHavingDefault.PropertyName::class.java, EnumJsonAdapter.create(org.openapitools.client.models.ModelWithEnumPropertyHavingDefault.PropertyName::class.java) .withUnknownFallback(org.openapitools.client.models.ModelWithEnumPropertyHavingDefault.PropertyName.unknownDefaultOpenApi)) + .add(org.openapitools.client.models.PropertyOfDay.DaysOfWeek::class.java, EnumJsonAdapter.create(org.openapitools.client.models.PropertyOfDay.DaysOfWeek::class.java) + .withUnknownFallback(org.openapitools.client.models.PropertyOfDay.DaysOfWeek.unknownDefaultOpenApi)) + .add(org.openapitools.client.models.PropertyOfDay.MonthOfYear::class.java, EnumJsonAdapter.create(org.openapitools.client.models.PropertyOfDay.MonthOfYear::class.java) + .withUnknownFallback(org.openapitools.client.models.PropertyOfDay.MonthOfYear.unknownDefaultOpenApi)) + .add(org.openapitools.client.models.PropertyOfDay.HolidayTypes::class.java, EnumJsonAdapter.create(org.openapitools.client.models.PropertyOfDay.HolidayTypes::class.java) + .withUnknownFallback(org.openapitools.client.models.PropertyOfDay.HolidayTypes.unknownDefaultOpenApi)) } } diff --git a/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/models/PropertyOfDay.kt b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/models/PropertyOfDay.kt new file mode 100644 index 00000000000..b00e68b7592 --- /dev/null +++ b/samples/client/petstore/kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/models/PropertyOfDay.kt @@ -0,0 +1,135 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import java.io.Serializable + +/** + * The DayType describe during which the assignment applies + * + * @param name Name of property of day + * @param description Description of the property of day + * @param daysOfWeek Days of week + * @param monthOfYear Month of year + * @param dayOfYear Day of year + * @param holidayTypes Holiday types + */ + + +data class PropertyOfDay ( + + /* Name of property of day */ + @Json(name = "name") + val name: kotlin.String, + + /* Description of the property of day */ + @Json(name = "description") + val description: kotlin.String? = null, + + /* Days of week */ + @Json(name = "daysOfWeek") + val daysOfWeek: PropertyOfDay.DaysOfWeek? = null, + + /* Month of year */ + @Json(name = "monthOfYear") + val monthOfYear: PropertyOfDay.MonthOfYear? = null, + + /* Day of year */ + @Json(name = "dayOfYear") + val dayOfYear: kotlin.Int? = null, + + /* Holiday types */ + @Json(name = "holidayTypes") + val holidayTypes: PropertyOfDay.HolidayTypes? = null + +) : Serializable { + companion object { + private const val serialVersionUID: Long = 123 + } + + /** + * Days of week + * + * Values: mONDAY,tUESDAY,wEDNESDAY,tHURSDAY,fRIDAY,sATURDAY,sUNDAY,wEEKDAYS,wEEKEND,eVERYDAY,unknownDefaultOpenApi + */ + @JsonClass(generateAdapter = false) + enum class DaysOfWeek(val value: kotlin.Any) { + @Json(name = "MONDAY") mONDAY("MONDAY"), + @Json(name = "TUESDAY") tUESDAY("TUESDAY"), + @Json(name = "WEDNESDAY") wEDNESDAY("WEDNESDAY"), + @Json(name = "THURSDAY") tHURSDAY("THURSDAY"), + @Json(name = "FRIDAY") fRIDAY("FRIDAY"), + @Json(name = "SATURDAY") sATURDAY("SATURDAY"), + @Json(name = "SUNDAY") sUNDAY("SUNDAY"), + @Json(name = "WEEKDAYS") wEEKDAYS("WEEKDAYS"), + @Json(name = "WEEKEND") wEEKEND("WEEKEND"), + @Json(name = "EVERYDAY") eVERYDAY("EVERYDAY"), + @Json(name = "11184809") unknownDefaultOpenApi("11184809"); + } + /** + * Month of year + * + * Values: _1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,unknownDefaultOpenApi + */ + @JsonClass(generateAdapter = false) + enum class MonthOfYear(val value: kotlin.Int) { + @Json(name = "1") _1(1), + @Json(name = "2") _2(2), + @Json(name = "3") _3(3), + @Json(name = "4") _4(4), + @Json(name = "5") _5(5), + @Json(name = "6") _6(6), + @Json(name = "7") _7(7), + @Json(name = "8") _8(8), + @Json(name = "9") _9(9), + @Json(name = "10") _10(10), + @Json(name = "11") _11(11), + @Json(name = "12") _12(12), + @Json(name = "11184809") unknownDefaultOpenApi(11184809); + } + /** + * Holiday types + * + * Values: nOTHOLIDAY,lOCALHOLIDAY,nATIONALHOLIDAY,aNYHOLIDAY,wORKINGDAY,aNYDAY,nEWYEARSDAY,pALMSUNDAY,mAUNDYTHURSDAY,gOODFRIDAY,eASTERSUNDAY,eASTERMONDAY,lABOURDAY,cONSTITUTIONDAY,aSCENSIONDAY,wHITSUNDAY,wHITMONDAY,cHRISTMASDAY,bOXINGDAY,unknownDefaultOpenApi + */ + @JsonClass(generateAdapter = false) + enum class HolidayTypes(val value: kotlin.Any) { + @Json(name = "NOT_HOLIDAY") nOTHOLIDAY("NOT_HOLIDAY"), + @Json(name = "LOCAL_HOLIDAY") lOCALHOLIDAY("LOCAL_HOLIDAY"), + @Json(name = "NATIONAL_HOLIDAY") nATIONALHOLIDAY("NATIONAL_HOLIDAY"), + @Json(name = "ANY_HOLIDAY") aNYHOLIDAY("ANY_HOLIDAY"), + @Json(name = "WORKING_DAY") wORKINGDAY("WORKING_DAY"), + @Json(name = "ANY_DAY") aNYDAY("ANY_DAY"), + @Json(name = "NEW_YEARS_DAY") nEWYEARSDAY("NEW_YEARS_DAY"), + @Json(name = "PALM_SUNDAY") pALMSUNDAY("PALM_SUNDAY"), + @Json(name = "MAUNDY_THURSDAY") mAUNDYTHURSDAY("MAUNDY_THURSDAY"), + @Json(name = "GOOD_FRIDAY") gOODFRIDAY("GOOD_FRIDAY"), + @Json(name = "EASTER_SUNDAY") eASTERSUNDAY("EASTER_SUNDAY"), + @Json(name = "EASTER_MONDAY") eASTERMONDAY("EASTER_MONDAY"), + @Json(name = "LABOUR_DAY") lABOURDAY("LABOUR_DAY"), + @Json(name = "CONSTITUTION_DAY") cONSTITUTIONDAY("CONSTITUTION_DAY"), + @Json(name = "ASCENSION_DAY") aSCENSIONDAY("ASCENSION_DAY"), + @Json(name = "WHIT_SUNDAY") wHITSUNDAY("WHIT_SUNDAY"), + @Json(name = "WHIT_MONDAY") wHITMONDAY("WHIT_MONDAY"), + @Json(name = "CHRISTMAS_DAY") cHRISTMASDAY("CHRISTMAS_DAY"), + @Json(name = "BOXING_DAY") bOXINGDAY("BOXING_DAY"), + @Json(name = "11184809") unknownDefaultOpenApi("11184809"); + } +} +