From 2e17653ae85b8f2f6a270015c3e7a71661591799 Mon Sep 17 00:00:00 2001 From: YusukeOba <43848363+YusukeOba@users.noreply.github.com> Date: Tue, 15 Aug 2023 18:10:26 +0900 Subject: [PATCH] [kotlin-client][multiplatform] Added support enum query parameter (#16327) * [kotlin-multiplatform] add enum parameter support * [kotlin-multiplatform] update generated samples --- .../libraries/multiplatform/api.mustache | 26 ++++++++++++++++++- .../org/openapitools/client/apis/PetApi.kt | 20 +++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/api.mustache index ddbf59451046..a1c2bf2771ee 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/api.mustache @@ -23,6 +23,30 @@ import kotlinx.serialization.encoding.* ) : ApiClient(baseUrl, httpClientEngine, httpClientConfig, jsonSerializer) { {{#operation}} + {{#allParams}} + {{#isEnum}} + + /** + * enum for parameter {{paramName}} + */ + @Serializable + {{#nonPublicApi}}internal {{/nonPublicApi}}enum class {{enumName}}{{operationIdCamelCase}}(val value: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}kotlin.String{{/isContainer}}) { + {{^enumUnknownDefaultCase}} + {{#allowableValues}}{{#enumVars}} + @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) + {{&name}}({{{value}}}){{^-last}},{{/-last}} + {{/enumVars}}{{/allowableValues}} + {{/enumUnknownDefaultCase}} + {{#enumUnknownDefaultCase}} + {{#allowableValues}}{{#enumVars}}{{^-last}} + @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) + {{&name}}({{{value}}}), + {{/-last}}{{/enumVars}}{{/allowableValues}} + {{/enumUnknownDefaultCase}} + } + + {{/isEnum}} + {{/allParams}} /** * {{summary}} * {{notes}} @@ -32,7 +56,7 @@ import kotlinx.serialization.encoding.* {{#returnType}} @Suppress("UNCHECKED_CAST") {{/returnType}} - open suspend fun {{operationId}}({{#allParams}}{{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{defaultValue}}}.toDouble(){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{defaultValue}}}.toDouble(){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): HttpResponse<{{{returnType}}}{{^returnType}}Unit{{/returnType}}> { + open suspend fun {{operationId}}({{#allParams}}{{{paramName}}}: {{#isEnum}}{{#isContainer}}kotlin.collections.List<{{enumName}}{{operationIdCamelCase}}>{{/isContainer}}{{^isContainer}}{{enumName}}{{operationIdCamelCase}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{#isEnum}}{{enumName}}{{operationIdCamelCase}}.{{enumDefaultValue}}{{/isEnum}}{{^isEnum}}{{{defaultValue}}}{{/isEnum}}{{/isNumber}}{{#isNumber}}{{{defaultValue}}}.toDouble(){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{#isEnum}}{{enumName}}{{operationIdCamelCase}}.{{enumDefaultValue}}{{/isEnum}}{{^isEnum}}{{{defaultValue}}}{{/isEnum}}{{/isNumber}}{{#isNumber}}{{{defaultValue}}}.toDouble(){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): HttpResponse<{{{returnType}}}{{^returnType}}Unit{{/returnType}}> { val localVariableAuthNames = listOf({{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}}) diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt index 0520d03d8e18..4eccd57c8aa3 100644 --- a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt @@ -101,6 +101,24 @@ open class PetApi( } + + /** + * enum for parameter status + */ + @Serializable + enum class StatusFindPetsByStatus(val value: kotlin.String) { + + @SerialName(value = "available") + available("available"), + + @SerialName(value = "pending") + pending("pending"), + + @SerialName(value = "sold") + sold("sold") + + } + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -108,7 +126,7 @@ open class PetApi( * @return kotlin.collections.List */ @Suppress("UNCHECKED_CAST") - open suspend fun findPetsByStatus(status: kotlin.collections.List): HttpResponse> { + open suspend fun findPetsByStatus(status: kotlin.collections.List): HttpResponse> { val localVariableAuthNames = listOf("petstore_auth")