From d92d84bb12c33e15f27ef5206aa22eacbeeb42cb Mon Sep 17 00:00:00 2001 From: Andrew Emery Date: Mon, 28 Oct 2019 19:03:49 +1100 Subject: [PATCH] Kotlin multiplatform auth (#4284) * Includes support for the Javascript platform * Fixes enum serialization with non-string values * Updates to expose api dependencies to consumers * Uses explicit class name for Kotlin collection classes * Maps unknown object type to Kotlin String The Kotlinx serialization library uses reflectionless serialization and requires compile-time serialization declarations. As a result, unknown objects are mapped to Kotlin String instances to enable compilation where object types are not explicitly defined. * Improves support for binary objects Previously, objects that contained binary data were assigned the InputProvider data type. This was suitable for a binary input form parameter, but unsuitable for Base64 or octet binary strings. These binary strings are now assigned a more suitable object. * Includes Kotlin Multiplatform auth classes Includes support for: - api key - http basic - http bearer - oauth (partial support) https://github.com/OpenAPITools/openapi-generator/issues/4283 * Updates Kotlin samples --- .../languages/KotlinClientCodegen.java | 41 +++- .../main/resources/kotlin-client/api.mustache | 2 +- .../kotlin-client/data_class.mustache | 2 +- .../kotlin-client/enum_class.mustache | 2 +- .../ApiAbstractions.kt.mustache | 2 +- .../infrastructure/RequestConfig.kt.mustache | 2 +- .../libraries/multiplatform/api.mustache | 5 +- .../multiplatform/auth/ApiKeyAuth.kt.mustache | 16 ++ .../auth/Authentication.kt.mustache | 13 ++ .../auth/HttpBasicAuth.kt.mustache | 17 ++ .../auth/HttpBearerAuth.kt.mustache | 14 ++ .../multiplatform/auth/OAuth.kt.mustache | 10 + .../multiplatform/build.gradle.mustache | 49 +++-- ...routine.mustache => Coroutine.kt.mustache} | 0 .../infrastructure/ApiClient.kt.mustache | 105 ++++++++- .../Base64ByteArray.kt.mustache | 29 +++ .../infrastructure/Bytes.kt.mustache | 102 +++++++++ .../infrastructure/OctetByteArray.kt.mustache | 29 +++ ...routine.mustache => Coroutine.kt.mustache} | 0 .../jsTest/Coroutine.kt.mustache | 7 + ...routine.mustache => Coroutine.kt.mustache} | 0 .../kotlin-multiplatform/build.gradle | 49 +++-- .../org/openapitools/client/apis/PetApi.kt | 40 +++- .../org/openapitools/client/apis/StoreApi.kt | 20 +- .../org/openapitools/client/apis/UserApi.kt | 40 +++- .../openapitools/client/auth/ApiKeyAuth.kt | 16 ++ .../client/auth/Authentication.kt | 13 ++ .../openapitools/client/auth/HttpBasicAuth.kt | 17 ++ .../client/auth/HttpBearerAuth.kt | 14 ++ .../org/openapitools/client/auth/OAuth.kt | 10 + .../client/infrastructure/ApiAbstractions.kt | 2 +- .../client/infrastructure/ApiClient.kt | 113 ++++++++-- .../client/infrastructure/Base64ByteArray.kt | 29 +++ .../client/infrastructure/Bytes.kt | 102 +++++++++ .../client/infrastructure/OctetByteArray.kt | 29 +++ .../client/infrastructure/RequestConfig.kt | 2 +- .../org/openapitools/client/models/Order.kt | 2 +- .../org/openapitools/client/models/Pet.kt | 2 +- .../src/jsTest/kotlin/util/Coroutine.kt | 7 + .../org/openapitools/client/apis/PetApi.kt | 12 +- .../org/openapitools/client/apis/StoreApi.kt | 8 +- .../org/openapitools/client/apis/UserApi.kt | 14 +- .../client/infrastructure/ApiAbstractions.kt | 2 +- .../client/infrastructure/RequestConfig.kt | 2 +- .../org/openapitools/client/apis/PetApi.kt | 12 +- .../org/openapitools/client/apis/StoreApi.kt | 8 +- .../org/openapitools/client/apis/UserApi.kt | 14 +- .../client/infrastructure/ApiAbstractions.kt | 2 +- .../client/infrastructure/RequestConfig.kt | 2 +- .../org/openapitools/client/apis/PetApi.kt | 12 +- .../org/openapitools/client/apis/StoreApi.kt | 8 +- .../org/openapitools/client/apis/UserApi.kt | 14 +- .../client/infrastructure/ApiAbstractions.kt | 2 +- .../client/infrastructure/RequestConfig.kt | 2 +- .../org/openapitools/client/apis/PetApi.kt | 12 +- .../org/openapitools/client/apis/StoreApi.kt | 8 +- .../org/openapitools/client/apis/UserApi.kt | 14 +- .../client/infrastructure/ApiAbstractions.kt | 2 +- .../client/infrastructure/RequestConfig.kt | 2 +- .../org/openapitools/client/apis/PetApi.kt | 12 +- .../org/openapitools/client/apis/StoreApi.kt | 8 +- .../org/openapitools/client/apis/UserApi.kt | 14 +- .../client/infrastructure/ApiAbstractions.kt | 2 +- .../client/infrastructure/RequestConfig.kt | 2 +- .../.openapi-generator/VERSION | 2 +- .../kotlin-multiplatform/build.gradle | 49 +++-- .../kotlin-multiplatform/docs/FakeApi.md | 4 +- .../docs/FileSchemaTestClass.md | 4 +- .../kotlin-multiplatform/docs/FormatTest.md | 4 +- .../docs/HasOnlyReadOnly.md | 4 +- .../docs/InlineObject1.md | 2 +- .../docs/InlineObject3.md | 4 +- .../docs/InlineObject5.md | 2 +- .../kotlin-multiplatform/docs/Name.md | 4 +- .../docs/NullableClass.md | 12 +- .../docs/ReadOnlyFirst.md | 2 +- .../client/apis/AnotherFakeApi.kt | 5 +- .../openapitools/client/apis/DefaultApi.kt | 5 +- .../org/openapitools/client/apis/FakeApi.kt | 72 +++++-- .../client/apis/FakeClassnameTags123Api.kt | 5 +- .../org/openapitools/client/apis/PetApi.kt | 45 +++- .../org/openapitools/client/apis/StoreApi.kt | 20 +- .../org/openapitools/client/apis/UserApi.kt | 40 +++- .../openapitools/client/auth/ApiKeyAuth.kt | 16 ++ .../client/auth/Authentication.kt | 13 ++ .../openapitools/client/auth/HttpBasicAuth.kt | 17 ++ .../client/auth/HttpBearerAuth.kt | 14 ++ .../org/openapitools/client/auth/OAuth.kt | 10 + .../client/infrastructure/ApiAbstractions.kt | 2 +- .../client/infrastructure/ApiClient.kt | 200 +++++++++++++----- .../client/infrastructure/Base64ByteArray.kt | 29 +++ .../client/infrastructure/Bytes.kt | 102 +++++++++ .../client/infrastructure/OctetByteArray.kt | 29 +++ .../client/infrastructure/RequestConfig.kt | 2 +- .../models/AdditionalPropertiesClass.kt | 8 +- .../org/openapitools/client/models/Animal.kt | 4 +- .../openapitools/client/models/ApiResponse.kt | 4 +- .../client/models/ArrayOfArrayOfNumberOnly.kt | 6 +- .../client/models/ArrayOfNumberOnly.kt | 6 +- .../openapitools/client/models/ArrayTest.kt | 10 +- .../client/models/Capitalization.kt | 12 +- .../org/openapitools/client/models/Cat.kt | 4 +- .../openapitools/client/models/CatAllOf.kt | 4 +- .../openapitools/client/models/Category.kt | 4 +- .../openapitools/client/models/ClassModel.kt | 6 +- .../org/openapitools/client/models/Client.kt | 4 +- .../org/openapitools/client/models/Dog.kt | 4 +- .../openapitools/client/models/DogAllOf.kt | 4 +- .../openapitools/client/models/EnumArrays.kt | 21 +- .../openapitools/client/models/EnumClass.kt | 2 +- .../openapitools/client/models/EnumTest.kt | 39 +--- .../client/models/FileSchemaTestClass.kt | 8 +- .../org/openapitools/client/models/Foo.kt | 4 +- .../openapitools/client/models/FormatTest.kt | 12 +- .../client/models/HasOnlyReadOnly.kt | 4 +- .../client/models/HealthCheckResult.kt | 6 +- .../client/models/InlineObject.kt | 4 +- .../client/models/InlineObject1.kt | 6 +- .../client/models/InlineObject2.kt | 22 +- .../client/models/InlineObject3.kt | 10 +- .../client/models/InlineObject4.kt | 4 +- .../client/models/InlineObject5.kt | 6 +- .../client/models/InlineResponseDefault.kt | 4 +- .../org/openapitools/client/models/List.kt | 8 +- .../org/openapitools/client/models/MapTest.kt | 19 +- ...dPropertiesAndAdditionalPropertiesClass.kt | 4 +- .../client/models/Model200Response.kt | 6 +- .../org/openapitools/client/models/Name.kt | 10 +- .../client/models/NullableClass.kt | 28 +-- .../openapitools/client/models/NumberOnly.kt | 6 +- .../org/openapitools/client/models/Order.kt | 12 +- .../client/models/OuterComposite.kt | 10 +- .../openapitools/client/models/OuterEnum.kt | 2 +- .../client/models/OuterEnumDefaultValue.kt | 2 +- .../client/models/OuterEnumInteger.kt | 2 +- .../models/OuterEnumIntegerDefaultValue.kt | 2 +- .../org/openapitools/client/models/Pet.kt | 12 +- .../client/models/ReadOnlyFirst.kt | 4 +- .../org/openapitools/client/models/Return.kt | 8 +- .../client/models/SpecialModelname.kt | 6 +- .../org/openapitools/client/models/Tag.kt | 4 +- .../org/openapitools/client/models/User.kt | 4 +- .../src/jsTest/kotlin/util/Coroutine.kt | 7 + .../client/apis/AnotherFakeApi.kt | 2 +- .../openapitools/client/apis/DefaultApi.kt | 2 +- .../org/openapitools/client/apis/FakeApi.kt | 62 ++++-- .../client/apis/FakeClassnameTags123Api.kt | 2 +- .../org/openapitools/client/apis/PetApi.kt | 24 ++- .../org/openapitools/client/apis/StoreApi.kt | 8 +- .../org/openapitools/client/apis/UserApi.kt | 20 +- .../client/infrastructure/ApiAbstractions.kt | 2 +- .../client/infrastructure/ApiClient.kt | 14 +- .../client/infrastructure/RequestConfig.kt | 2 +- .../client/models/SpecialModelname.kt | 2 +- 154 files changed, 1858 insertions(+), 533 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/ApiKeyAuth.kt.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/Authentication.kt.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/HttpBasicAuth.kt.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/HttpBearerAuth.kt.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/OAuth.kt.mustache rename modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/commonTest/{coroutine.mustache => Coroutine.kt.mustache} (100%) create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/Base64ByteArray.kt.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/Bytes.kt.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/OctetByteArray.kt.mustache rename modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/iosTest/{coroutine.mustache => Coroutine.kt.mustache} (100%) create mode 100644 modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/jsTest/Coroutine.kt.mustache rename modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/jvmTest/{coroutine.mustache => Coroutine.kt.mustache} (100%) create mode 100644 samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt create mode 100644 samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/Authentication.kt create mode 100644 samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt create mode 100644 samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt create mode 100644 samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/OAuth.kt create mode 100644 samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt create mode 100644 samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Bytes.kt create mode 100644 samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt create mode 100644 samples/client/petstore/kotlin-multiplatform/src/jsTest/kotlin/util/Coroutine.kt create mode 100644 samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt create mode 100644 samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/Authentication.kt create mode 100644 samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt create mode 100644 samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt create mode 100644 samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/OAuth.kt create mode 100644 samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt create mode 100644 samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Bytes.kt create mode 100644 samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt create mode 100644 samples/openapi3/client/petstore/kotlin-multiplatform/src/jsTest/kotlin/util/Coroutine.kt diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java index 77156c7f827..b7e5836a8b2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java @@ -21,6 +21,7 @@ import org.openapitools.codegen.CliOption; import org.openapitools.codegen.CodegenConstants; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; +import org.openapitools.codegen.CodegenParameter; import org.openapitools.codegen.CodegenProperty; import org.openapitools.codegen.CodegenType; import org.openapitools.codegen.SupportingFile; @@ -192,29 +193,48 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen { // multiplatform default includes defaultIncludes.add("io.ktor.client.request.forms.InputProvider"); + defaultIncludes.add(packageName + ".infrastructure.Base64ByteArray"); + defaultIncludes.add(packageName + ".infrastructure.OctetByteArray"); // multiplatform type mapping typeMapping.put("number", "kotlin.Double"); - typeMapping.put("file", "InputProvider"); + typeMapping.put("file", "OctetByteArray"); + typeMapping.put("binary", "OctetByteArray"); + typeMapping.put("ByteArray", "Base64ByteArray"); + typeMapping.put("object", "kotlin.String"); // kotlin.Any not serializable // multiplatform import mapping importMapping.put("BigDecimal", "kotlin.Double"); importMapping.put("UUID", "kotlin.String"); importMapping.put("URI", "kotlin.String"); importMapping.put("InputProvider", "io.ktor.client.request.forms.InputProvider"); - importMapping.put("File", "io.ktor.client.request.forms.InputProvider"); + importMapping.put("File", packageName + ".infrastructure.OctetByteArray"); importMapping.put("Timestamp", "kotlin.String"); importMapping.put("LocalDateTime", "kotlin.String"); importMapping.put("LocalDate", "kotlin.String"); importMapping.put("LocalTime", "kotlin.String"); + importMapping.put("Base64ByteArray", packageName + ".infrastructure.Base64ByteArray"); + importMapping.put("OctetByteArray", packageName + ".infrastructure.OctetByteArray"); // multiplatform specific supporting files + supportingFiles.add(new SupportingFile("infrastructure/Base64ByteArray.kt.mustache", infrastructureFolder, "Base64ByteArray.kt")); + supportingFiles.add(new SupportingFile("infrastructure/Bytes.kt.mustache", infrastructureFolder, "Bytes.kt")); supportingFiles.add(new SupportingFile("infrastructure/HttpResponse.kt.mustache", infrastructureFolder, "HttpResponse.kt")); + supportingFiles.add(new SupportingFile("infrastructure/OctetByteArray.kt.mustache", infrastructureFolder, "OctetByteArray.kt")); + + // multiplatform specific auth + final String authFolder = (sourceFolder + File.separator + packageName + File.separator + "auth").replace(".", "/"); + supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.kt.mustache", authFolder, "ApiKeyAuth.kt")); + supportingFiles.add(new SupportingFile("auth/Authentication.kt.mustache", authFolder, "Authentication.kt")); + supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.kt.mustache", authFolder, "HttpBasicAuth.kt")); + supportingFiles.add(new SupportingFile("auth/HttpBearerAuth.kt.mustache", authFolder, "HttpBearerAuth.kt")); + supportingFiles.add(new SupportingFile("auth/OAuth.kt.mustache", authFolder, "OAuth.kt")); // multiplatform specific testing files - supportingFiles.add(new SupportingFile("commonTest/coroutine.mustache", "src/commonTest/kotlin/util", "Coroutine.kt")); - supportingFiles.add(new SupportingFile("iosTest/coroutine.mustache", "src/iosTest/kotlin/util", "Coroutine.kt")); - supportingFiles.add(new SupportingFile("jvmTest/coroutine.mustache", "src/jvmTest/kotlin/util", "Coroutine.kt")); + supportingFiles.add(new SupportingFile("commonTest/Coroutine.kt.mustache", "src/commonTest/kotlin/util", "Coroutine.kt")); + supportingFiles.add(new SupportingFile("iosTest/Coroutine.kt.mustache", "src/iosTest/kotlin/util", "Coroutine.kt")); + supportingFiles.add(new SupportingFile("jsTest/Coroutine.kt.mustache", "src/jsTest/kotlin/util", "Coroutine.kt")); + supportingFiles.add(new SupportingFile("jvmTest/Coroutine.kt.mustache", "src/jvmTest/kotlin/util", "Coroutine.kt")); // gradle wrapper supporting files supportingFiles.add(new SupportingFile("gradlew.mustache", "", "gradlew")); @@ -290,11 +310,22 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen { if (operations != null) { List ops = (List) operations.get("operation"); for (CodegenOperation operation : ops) { + + // set multipart against all relevant operations if (operation.hasConsumes == Boolean.TRUE) { if (isMultipartType(operation.consumes)) { operation.isMultipart = Boolean.TRUE; } } + + // modify the data type of binary form parameters to a more friendly type for multiplatform builds + if (MULTIPLATFORM.equals(getLibrary()) && operation.allParams != null) { + for (CodegenParameter param : operation.allParams) { + if (param.dataFormat != null && param.dataFormat.equals("binary")) { + param.baseType = param.dataType = "io.ktor.client.request.forms.InputProvider"; + } + } + } } } return operations; diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/api.mustache index 477cf9fface..0d1b2642091 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/api.mustache @@ -29,7 +29,7 @@ import {{packageName}}.infrastructure.toMultiValue @Suppress("UNCHECKED_CAST"){{/returnType}} fun {{operationId}}({{#allParams}}{{paramName}}: {{{dataType}}}{{^required}}?{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}} { val localVariableBody: kotlin.Any? = {{#hasBodyParam}}{{#bodyParams}}{{paramName}}{{/bodyParams}}{{/hasBodyParam}}{{^hasBodyParam}}{{^hasFormParams}}null{{/hasFormParams}}{{#hasFormParams}}mapOf({{#formParams}}"{{{baseName}}}" to "${{paramName}}"{{#hasMore}}, {{/hasMore}}{{/formParams}}){{/hasFormParams}}{{/hasBodyParam}} - val localVariableQuery: MultiValueMap = {{^hasQueryParams}}mapOf() + val localVariableQuery: MultiValueMap = {{^hasQueryParams}}mutableMapOf() {{/hasQueryParams}}{{#hasQueryParams}}mutableMapOf>() .apply { {{#queryParams}} 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 a0630c4fa03..d3fc818aaa7 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 @@ -71,7 +71,7 @@ import java.io.Serializable {{/allowableValues}} {{#multiplatform}} - {{#nonPublicApi}}internal {{/nonPublicApi}}object Serializer : CommonEnumSerializer<{{nameInCamelCase}}>("{{nameInCamelCase}}", values(), values().map { it.value }.toTypedArray()) + {{#nonPublicApi}}internal {{/nonPublicApi}}object Serializer : CommonEnumSerializer<{{nameInCamelCase}}>("{{nameInCamelCase}}", values(), values().map { it.value.toString() }.toTypedArray()) {{/multiplatform}} } {{/isEnum}} 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 102a2a2f939..9c848451846 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 @@ -42,6 +42,6 @@ import kotlinx.serialization.internal.CommonEnumSerializer {{/enumVars}}{{/allowableValues}} {{#multiplatform}} - {{#nonPublicApi}}internal {{/nonPublicApi}}object Serializer : CommonEnumSerializer<{{classname}}>("{{classname}}", values(), values().map { it.value }.toTypedArray()) + {{#nonPublicApi}}internal {{/nonPublicApi}}object Serializer : CommonEnumSerializer<{{classname}}>("{{classname}}", values(), values().map { it.value.toString() }.toTypedArray()) {{/multiplatform}} } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiAbstractions.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiAbstractions.kt.mustache index 7cdc8cc962e..12c0350232f 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiAbstractions.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiAbstractions.kt.mustache @@ -1,6 +1,6 @@ package {{packageName}}.infrastructure -typealias MultiValueMap = Map> +typealias MultiValueMap = MutableMap> {{#nonPublicApi}}internal {{/nonPublicApi}}fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { "csv" -> "," diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache index bac8d60f7a9..435583e9726 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/RequestConfig.kt.mustache @@ -12,5 +12,5 @@ package {{packageName}}.infrastructure val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: Map> = mapOf() + val query: MutableMap> = mutableMapOf() ) \ No newline at end of file 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 89777b14b8b..e49cc83507b 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 @@ -41,6 +41,8 @@ import kotlinx.serialization.internal.StringDescriptor {{/returnType}} suspend fun {{operationId}}({{#allParams}}{{paramName}}: {{{dataType}}}{{^required}}?{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : HttpResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}> { + val localVariableAuthNames = listOf({{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}}) + val localVariableBody = {{#hasBodyParam}}{{#bodyParam}}{{#isListContainer}}{{operationIdCamelCase}}Request({{paramName}}.asList()){{/isListContainer}}{{^isListContainer}}{{#isMapContainer}}{{operationIdCamelCase}}Request({{paramName}}){{/isMapContainer}}{{^isMapContainer}}{{paramName}}{{/isMapContainer}}{{/isListContainer}}{{/bodyParam}}{{/hasBodyParam}} {{^hasBodyParam}} {{#hasFormParams}} @@ -83,7 +85,8 @@ import kotlinx.serialization.internal.StringDescriptor return {{#hasBodyParam}}jsonRequest{{/hasBodyParam}}{{^hasBodyParam}}{{#hasFormParams}}{{#isMultipart}}multipartFormRequest{{/isMultipart}}{{^isMultipart}}urlEncodedFormRequest{{/isMultipart}}{{/hasFormParams}}{{^hasFormParams}}request{{/hasFormParams}}{{/hasBodyParam}}( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).{{#isListContainer}}wrap<{{operationIdCamelCase}}Response>().map { value.toTypedArray() }{{/isListContainer}}{{^isListContainer}}{{#isMapContainer}}wrap<{{operationIdCamelCase}}Response>().map { value }{{/isMapContainer}}{{^isMapContainer}}wrap(){{/isMapContainer}}{{/isListContainer}} } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/ApiKeyAuth.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/ApiKeyAuth.kt.mustache new file mode 100644 index 00000000000..618fd7a8890 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/ApiKeyAuth.kt.mustache @@ -0,0 +1,16 @@ +package {{packageName}}.auth + +class ApiKeyAuth(private val location: String, val paramName: String) : Authentication { + var apiKey: String? = null + var apiKeyPrefix: String? = null + + override fun apply(query: MutableMap>, headers: MutableMap) { + val key: String = apiKey ?: return + val prefix: String? = apiKeyPrefix + val value: String = if (prefix != null) "$prefix $key" else key + when (location) { + "query" -> query[paramName] = listOf(value) + "header" -> headers[paramName] = value + } + } +} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/Authentication.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/Authentication.kt.mustache new file mode 100644 index 00000000000..1aab9156d98 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/Authentication.kt.mustache @@ -0,0 +1,13 @@ +package {{packageName}}.auth + +interface Authentication { + + /** + * Apply authentication settings to header and query params. + * + * @param query Query parameters. + * @param headers Header parameters. + */ + fun apply(query: MutableMap>, headers: MutableMap) + +} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/HttpBasicAuth.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/HttpBasicAuth.kt.mustache new file mode 100644 index 00000000000..ef6c5888ae1 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/HttpBasicAuth.kt.mustache @@ -0,0 +1,17 @@ +package {{packageName}}.auth + +import io.ktor.util.InternalAPI +import io.ktor.util.encodeBase64 + +class HttpBasicAuth : Authentication { + var username: String? = null + var password: String? = null + + @InternalAPI + override fun apply(query: MutableMap>, headers: MutableMap) { + if (username == null && password == null) return + val str = (username ?: "") + ":" + (password ?: "") + val auth = str.encodeBase64() + headers["Authorization"] = "Basic $auth" + } +} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/HttpBearerAuth.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/HttpBearerAuth.kt.mustache new file mode 100644 index 00000000000..982389d0960 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/HttpBearerAuth.kt.mustache @@ -0,0 +1,14 @@ +package {{packageName}}.auth + +class HttpBearerAuth(private val scheme: String?) : Authentication { + var bearerToken: String? = null + + override fun apply(query: MutableMap>, headers: MutableMap) { + val token: String = bearerToken ?: return + headers["Authorization"] = (if (scheme != null) upperCaseBearer(scheme)!! + " " else "") + token + } + + private fun upperCaseBearer(scheme: String): String? { + return if ("bearer".equals(scheme, ignoreCase = true)) "Bearer" else scheme + } +} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/OAuth.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/OAuth.kt.mustache new file mode 100644 index 00000000000..98bb449a609 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/auth/OAuth.kt.mustache @@ -0,0 +1,10 @@ +package {{packageName}}.auth + +class OAuth : Authentication { + var accessToken: String? = null + + override fun apply(query: MutableMap>, headers: MutableMap) { + val token: String = accessToken ?: return + headers["Authorization"] = "Bearer $token" + } +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/build.gradle.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/build.gradle.mustache index 1e309cc464a..dfc6736dc6d 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/build.gradle.mustache @@ -30,6 +30,7 @@ kotlin { jvm() iosArm64() { binaries { framework { freeCompilerArgs.add("-Xobjc-generics") } } } iosX64() { binaries { framework { freeCompilerArgs.add("-Xobjc-generics") } } } + js() sourceSets { commonMain { @@ -37,9 +38,9 @@ kotlin { implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" - implementation "io.ktor:ktor-client-core:$ktor_version" - implementation "io.ktor:ktor-client-json:$ktor_version" - implementation "io.ktor:ktor-client-serialization:$ktor_version" + api "io.ktor:ktor-client-core:$ktor_version" + api "io.ktor:ktor-client-json:$ktor_version" + api "io.ktor:ktor-client-serialization:$ktor_version" } } @@ -57,9 +58,9 @@ kotlin { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version" - implementation "io.ktor:ktor-client-core-jvm:$ktor_version" - implementation "io.ktor:ktor-client-json-jvm:$ktor_version" - implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version" + api "io.ktor:ktor-client-core-jvm:$ktor_version" + api "io.ktor:ktor-client-json-jvm:$ktor_version" + api "io.ktor:ktor-client-serialization-jvm:$ktor_version" } } @@ -77,7 +78,7 @@ kotlin { dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version" - implementation "io.ktor:ktor-client-ios:$ktor_version" + api "io.ktor:ktor-client-ios:$ktor_version" } } @@ -91,9 +92,9 @@ kotlin { iosArm64().compilations.main.defaultSourceSet { dependsOn iosMain dependencies { - implementation "io.ktor:ktor-client-ios-iosarm64:$ktor_version" - implementation "io.ktor:ktor-client-json-iosarm64:$ktor_version" - implementation "io.ktor:ktor-client-serialization-iosarm64:$ktor_version" + api "io.ktor:ktor-client-ios-iosarm64:$ktor_version" + api "io.ktor:ktor-client-json-iosarm64:$ktor_version" + api "io.ktor:ktor-client-serialization-iosarm64:$ktor_version" } } @@ -104,9 +105,31 @@ kotlin { iosX64().compilations.main.defaultSourceSet { dependsOn iosMain dependencies { - implementation "io.ktor:ktor-client-ios-iosx64:$ktor_version" - implementation "io.ktor:ktor-client-json-iosx64:$ktor_version" - implementation "io.ktor:ktor-client-serialization-iosx64:$ktor_version" + api "io.ktor:ktor-client-ios-iosx64:$ktor_version" + api "io.ktor:ktor-client-json-iosx64:$ktor_version" + api "io.ktor:ktor-client-serialization-iosx64:$ktor_version" + } + } + + jsMain { + dependsOn commonMain + dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutines_version" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version" + api "io.ktor:ktor-client-js:$ktor_version" + api "io.ktor:ktor-client-json-js:$ktor_version" + api "io.ktor:ktor-client-serialization-js:$ktor_version" + } + } + + jsTest { + dependsOn commonTest + dependencies { + implementation "io.ktor:ktor-client-mock-js:$ktor_version" + implementation "io.ktor:ktor-client-js:$ktor_version" + implementation "io.ktor:ktor-client-json:$ktor_version" + implementation "io.ktor:ktor-client-serialization-js:$ktor_version" } } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/commonTest/coroutine.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/commonTest/Coroutine.kt.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/commonTest/coroutine.mustache rename to modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/commonTest/Coroutine.kt.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/ApiClient.kt.mustache index 26927bfd481..10aab1ba1b2 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/ApiClient.kt.mustache @@ -23,6 +23,7 @@ import kotlinx.serialization.json.JsonConfiguration import {{apiPackage}}.* import {{modelPackage}}.* +import {{packageName}}.auth.* {{#nonPublicApi}}internal {{/nonPublicApi}}open class ApiClient( private val baseUrl: String, @@ -46,6 +47,14 @@ import {{modelPackage}}.* httpClientEngine?.let { HttpClient(it, clientConfig) } ?: HttpClient(clientConfig) } + private val authentications: kotlin.collections.Map by lazy { + mapOf({{#authMethods}}{{#isBasic}}{{#isBasicBasic}} + "{{name}}" to HttpBasicAuth(){{/isBasicBasic}}{{^isBasicBasic}} + "{{name}}" to HttpBearerAuth("{{scheme}}"){{/isBasicBasic}}{{/isBasic}}{{#isApiKey}} + "{{name}}" to ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"){{/isApiKey}}{{#isOAuth}} + "{{name}}" to OAuth(){{/isOAuth}}{{#hasMore}}, {{/hasMore}}{{/authMethods}}) + } + {{#nonPublicApi}}internal {{/nonPublicApi}}companion object { protected val UNSAFE_HEADERS = listOf(HttpHeaders.ContentType) @@ -54,27 +63,96 @@ import {{modelPackage}}.* {{classname}}.setMappers(serializer) {{/apis}}{{/apiInfo}} {{#models}} - {{#model}}{{^isAlias}}serializer.setMapper({{classname}}::class, {{classname}}.serializer()){{/isAlias}}{{/model}} + {{#model}}{{^isAlias}}serializer.setMapper({{modelPackage}}.{{classname}}::class, {{modelPackage}}.{{classname}}.{{#isEnum}}Serializer{{/isEnum}}{{^isEnum}}serializer(){{/isEnum}}){{/isAlias}}{{/model}} {{/models}} } } - protected suspend fun multipartFormRequest(requestConfig: RequestConfig, body: List?): HttpResponse { - return request(requestConfig, MultiPartFormDataContent(body ?: listOf())) + /** + * Set the username for the first HTTP basic authentication. + * + * @param username Username + */ + fun setUsername(username: String) { + val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth? + ?: throw Exception("No HTTP basic authentication configured") + auth.username = username } - protected suspend fun urlEncodedFormRequest(requestConfig: RequestConfig, body: Parameters?): HttpResponse { - return request(requestConfig, FormDataContent(body ?: Parameters.Empty)) + /** + * Set the password for the first HTTP basic authentication. + * + * @param password Password + */ + fun setPassword(password: String) { + val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth? + ?: throw Exception("No HTTP basic authentication configured") + auth.password = password } - protected suspend fun jsonRequest(requestConfig: RequestConfig, body: Any? = null): HttpResponse { + /** + * Set the API key value for the first API key authentication. + * + * @param apiKey API key + * @param paramName The name of the API key parameter, or null or set the first key. + */ + fun setApiKey(apiKey: String, paramName: String? = null) { + val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName)} as ApiKeyAuth? + ?: throw Exception("No API key authentication configured") + auth.apiKey = apiKey + } + + /** + * Set the API key prefix for the first API key authentication. + * + * @param apiKeyPrefix API key prefix + * @param paramName The name of the API key parameter, or null or set the first key. + */ + fun setApiKeyPrefix(apiKeyPrefix: String, paramName: String? = null) { + val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName) } as ApiKeyAuth? + ?: throw Exception("No API key authentication configured") + auth.apiKeyPrefix = apiKeyPrefix + } + + /** + * Set the access token for the first OAuth2 authentication. + * + * @param accessToken Access token + */ + fun setAccessToken(accessToken: String) { + val auth = authentications.values.firstOrNull { it is OAuth } as OAuth? + ?: throw Exception("No OAuth2 authentication configured") + auth.accessToken = accessToken + } + + /** + * Set the access token for the first Bearer authentication. + * + * @param bearerToken The bearer token. + */ + fun setBearerToken(bearerToken: String) { + val auth = authentications.values.firstOrNull { it is HttpBearerAuth } as HttpBearerAuth? + ?: throw Exception("No Bearer authentication configured") + auth.bearerToken = bearerToken + } + + protected suspend fun multipartFormRequest(requestConfig: RequestConfig, body: kotlin.collections.List?, authNames: kotlin.collections.List): HttpResponse { + return request(requestConfig, MultiPartFormDataContent(body ?: listOf()), authNames) + } + + protected suspend fun urlEncodedFormRequest(requestConfig: RequestConfig, body: Parameters?, authNames: kotlin.collections.List): HttpResponse { + return request(requestConfig, FormDataContent(body ?: Parameters.Empty), authNames) + } + + protected suspend fun jsonRequest(requestConfig: RequestConfig, body: Any? = null, authNames: kotlin.collections.List): HttpResponse { val contentType = (requestConfig.headers[HttpHeaders.ContentType]?.let { ContentType.parse(it) } ?: ContentType.Application.Json) - return if (body != null) request(requestConfig, serializer.write(body, contentType)) - else request(requestConfig) + return if (body != null) request(requestConfig, serializer.write(body, contentType), authNames) + else request(requestConfig, authNames = authNames) } - protected suspend fun request(requestConfig: RequestConfig, body: OutgoingContent = EmptyContent): HttpResponse { + protected suspend fun request(requestConfig: RequestConfig, body: OutgoingContent = EmptyContent, authNames: kotlin.collections.List): HttpResponse { + requestConfig.updateForAuth(authNames) val headers = requestConfig.headers return client.call { @@ -95,7 +173,14 @@ import {{modelPackage}}.* }.response } - private fun URLBuilder.appendPath(components: List): URLBuilder = apply { + private fun RequestConfig.updateForAuth(authNames: kotlin.collections.List) { + for (authName in authNames) { + val auth = authentications[authName] ?: throw Exception("Authentication undefined: $authName") + auth.apply(query, headers) + } + } + + private fun URLBuilder.appendPath(components: kotlin.collections.List): URLBuilder = apply { encodedPath = encodedPath.trimEnd('/') + components.joinToString("/", prefix = "/") { it.encodeURLQueryComponent() } } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/Base64ByteArray.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/Base64ByteArray.kt.mustache new file mode 100644 index 00000000000..168cfc993c3 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/Base64ByteArray.kt.mustache @@ -0,0 +1,29 @@ +package {{packageName}}.infrastructure + +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor + +@Serializable +class Base64ByteArray(val value: ByteArray) { + @Serializer(Base64ByteArray::class) + companion object : KSerializer { + override val descriptor = StringDescriptor.withName("Base64ByteArray") + override fun serialize(encoder: Encoder, obj: Base64ByteArray) = encoder.encodeString(obj.value.encodeBase64()) + override fun deserialize(decoder: Decoder) = Base64ByteArray(decoder.decodeString().decodeBase64Bytes()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || this::class != other::class) return false + other as Base64ByteArray + return value.contentEquals(other.value) + } + + override fun hashCode(): Int { + return value.contentHashCode() + } + + override fun toString(): String { + return "Base64ByteArray(${hex(value)})" + } +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/Bytes.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/Bytes.kt.mustache new file mode 100644 index 00000000000..b85013e647b --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/Bytes.kt.mustache @@ -0,0 +1,102 @@ +package {{packageName}}.infrastructure + +import kotlinx.io.core.* +import kotlin.experimental.and + +private val digits = "0123456789abcdef".toCharArray() +private const val BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" +private const val BASE64_MASK: Byte = 0x3f +private const val BASE64_PAD = '=' +private val BASE64_INVERSE_ALPHABET = IntArray(256) { BASE64_ALPHABET.indexOf(it.toChar()) } + +private fun String.toCharArray(): CharArray = CharArray(length) { get(it) } +private fun ByteArray.clearFrom(from: Int) = (from until size).forEach { this[it] = 0 } +private fun Int.toBase64(): Char = BASE64_ALPHABET[this] +private fun Byte.fromBase64(): Byte = BASE64_INVERSE_ALPHABET[toInt() and 0xff].toByte() and BASE64_MASK +internal fun ByteArray.encodeBase64(): String = buildPacket { writeFully(this@encodeBase64) }.encodeBase64() +internal fun String.decodeBase64Bytes(): ByteArray = buildPacket { writeStringUtf8(dropLastWhile { it == BASE64_PAD }) }.decodeBase64Bytes().readBytes() + +/** + * Encode [bytes] as a HEX string with no spaces, newlines and `0x` prefixes. + * + * Taken from https://github.com/ktorio/ktor/blob/master/ktor-utils/common/src/io/ktor/util/Crypto.kt + */ +internal fun hex(bytes: ByteArray): String { + val result = CharArray(bytes.size * 2) + var resultIndex = 0 + val digits = digits + + for (element in bytes) { + val b = element.toInt() and 0xff + result[resultIndex++] = digits[b shr 4] + result[resultIndex++] = digits[b and 0x0f] + } + + return String(result) +} + +/** + * Decode bytes from HEX string. It should be no spaces and `0x` prefixes. + * + * Taken from https://github.com/ktorio/ktor/blob/master/ktor-utils/common/src/io/ktor/util/Crypto.kt + */ +internal fun hex(s: String): ByteArray { + val result = ByteArray(s.length / 2) + for (idx in result.indices) { + val srcIdx = idx * 2 + val high = s[srcIdx].toString().toInt(16) shl 4 + val low = s[srcIdx + 1].toString().toInt(16) + result[idx] = (high or low).toByte() + } + + return result +} + +/** + * Encode [ByteReadPacket] in base64 format. + * + * Taken from https://github.com/ktorio/ktor/blob/424d1d2cfaa3281302c60af9500f738c8c2fc846/ktor-utils/common/src/io/ktor/util/Base64.kt + */ +private fun ByteReadPacket.encodeBase64(): String = buildString { + val data = ByteArray(3) + while (remaining > 0) { + val read = readAvailable(data) + data.clearFrom(read) + + val padSize = (data.size - read) * 8 / 6 + val chunk = ((data[0].toInt() and 0xFF) shl 16) or + ((data[1].toInt() and 0xFF) shl 8) or + (data[2].toInt() and 0xFF) + + for (index in data.size downTo padSize) { + val char = (chunk shr (6 * index)) and BASE64_MASK.toInt() + append(char.toBase64()) + } + + repeat(padSize) { append(BASE64_PAD) } + } +} + +/** + * Decode [ByteReadPacket] from base64 format + * + * Taken from https://github.com/ktorio/ktor/blob/424d1d2cfaa3281302c60af9500f738c8c2fc846/ktor-utils/common/src/io/ktor/util/Base64.kt + */ +private fun ByteReadPacket.decodeBase64Bytes(): Input = buildPacket { + val data = ByteArray(4) + + while (remaining > 0) { + val read = readAvailable(data) + + val chunk = data.foldIndexed(0) { index, result, current -> + result or (current.fromBase64().toInt() shl ((3 - index) * 6)) + } + + for (index in data.size - 2 downTo (data.size - read)) { + val origin = (chunk shr (8 * index)) and 0xff + writeByte(origin.toByte()) + } + } +} + + diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/OctetByteArray.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/OctetByteArray.kt.mustache new file mode 100644 index 00000000000..c23ac3ec000 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/infrastructure/OctetByteArray.kt.mustache @@ -0,0 +1,29 @@ +package {{packageName}}.infrastructure + +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor + +@Serializable +class OctetByteArray(val value: ByteArray) { + @Serializer(OctetByteArray::class) + companion object : KSerializer { + override val descriptor = StringDescriptor.withName("OctetByteArray") + override fun serialize(encoder: Encoder, obj: OctetByteArray) = encoder.encodeString(hex(obj.value)) + override fun deserialize(decoder: Decoder) = OctetByteArray(hex(decoder.decodeString())) + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || this::class != other::class) return false + other as OctetByteArray + return value.contentEquals(other.value) + } + + override fun hashCode(): Int { + return value.contentHashCode() + } + + override fun toString(): String { + return "OctetByteArray(${hex(value)})" + } +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/iosTest/coroutine.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/iosTest/Coroutine.kt.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/iosTest/coroutine.mustache rename to modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/iosTest/Coroutine.kt.mustache diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/jsTest/Coroutine.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/jsTest/Coroutine.kt.mustache new file mode 100644 index 00000000000..2bea4861f67 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/jsTest/Coroutine.kt.mustache @@ -0,0 +1,7 @@ +package util + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.promise + +actual fun runTest(block: suspend (scope : CoroutineScope) -> T): dynamic = GlobalScope.promise { block(this) } \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/jvmTest/coroutine.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/jvmTest/Coroutine.kt.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/jvmTest/coroutine.mustache rename to modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/jvmTest/Coroutine.kt.mustache diff --git a/samples/client/petstore/kotlin-multiplatform/build.gradle b/samples/client/petstore/kotlin-multiplatform/build.gradle index c976992112f..47045bb577e 100644 --- a/samples/client/petstore/kotlin-multiplatform/build.gradle +++ b/samples/client/petstore/kotlin-multiplatform/build.gradle @@ -30,6 +30,7 @@ kotlin { jvm() iosArm64() { binaries { framework { freeCompilerArgs.add("-Xobjc-generics") } } } iosX64() { binaries { framework { freeCompilerArgs.add("-Xobjc-generics") } } } + js() sourceSets { commonMain { @@ -37,9 +38,9 @@ kotlin { implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" - implementation "io.ktor:ktor-client-core:$ktor_version" - implementation "io.ktor:ktor-client-json:$ktor_version" - implementation "io.ktor:ktor-client-serialization:$ktor_version" + api "io.ktor:ktor-client-core:$ktor_version" + api "io.ktor:ktor-client-json:$ktor_version" + api "io.ktor:ktor-client-serialization:$ktor_version" } } @@ -57,9 +58,9 @@ kotlin { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version" - implementation "io.ktor:ktor-client-core-jvm:$ktor_version" - implementation "io.ktor:ktor-client-json-jvm:$ktor_version" - implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version" + api "io.ktor:ktor-client-core-jvm:$ktor_version" + api "io.ktor:ktor-client-json-jvm:$ktor_version" + api "io.ktor:ktor-client-serialization-jvm:$ktor_version" } } @@ -77,7 +78,7 @@ kotlin { dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version" - implementation "io.ktor:ktor-client-ios:$ktor_version" + api "io.ktor:ktor-client-ios:$ktor_version" } } @@ -91,9 +92,9 @@ kotlin { iosArm64().compilations.main.defaultSourceSet { dependsOn iosMain dependencies { - implementation "io.ktor:ktor-client-ios-iosarm64:$ktor_version" - implementation "io.ktor:ktor-client-json-iosarm64:$ktor_version" - implementation "io.ktor:ktor-client-serialization-iosarm64:$ktor_version" + api "io.ktor:ktor-client-ios-iosarm64:$ktor_version" + api "io.ktor:ktor-client-json-iosarm64:$ktor_version" + api "io.ktor:ktor-client-serialization-iosarm64:$ktor_version" } } @@ -104,9 +105,31 @@ kotlin { iosX64().compilations.main.defaultSourceSet { dependsOn iosMain dependencies { - implementation "io.ktor:ktor-client-ios-iosx64:$ktor_version" - implementation "io.ktor:ktor-client-json-iosx64:$ktor_version" - implementation "io.ktor:ktor-client-serialization-iosx64:$ktor_version" + api "io.ktor:ktor-client-ios-iosx64:$ktor_version" + api "io.ktor:ktor-client-json-iosx64:$ktor_version" + api "io.ktor:ktor-client-serialization-iosx64:$ktor_version" + } + } + + jsMain { + dependsOn commonMain + dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutines_version" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version" + api "io.ktor:ktor-client-js:$ktor_version" + api "io.ktor:ktor-client-json-js:$ktor_version" + api "io.ktor:ktor-client-serialization-js:$ktor_version" + } + } + + jsTest { + dependsOn commonTest + dependencies { + implementation "io.ktor:ktor-client-mock-js:$ktor_version" + implementation "io.ktor:ktor-client-js:$ktor_version" + implementation "io.ktor:ktor-client-json:$ktor_version" + implementation "io.ktor:ktor-client-serialization-js:$ktor_version" } } 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 59c49b3efdf..aa9c34a0dca 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 @@ -46,6 +46,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun addPet(body: Pet) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = body val localVariableQuery = mutableMapOf>() @@ -61,7 +63,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -76,6 +79,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -93,7 +98,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -107,6 +113,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun findPetsByStatus(status: kotlin.Array) : HttpResponse> { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -124,7 +132,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap().map { value.toTypedArray() } } @@ -148,6 +157,8 @@ private class FindPetsByStatusResponse(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun findPetsByTags(tags: kotlin.Array) : HttpResponse> { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -165,7 +176,8 @@ private class FindPetsByStatusResponse(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap().map { value.toTypedArray() } } @@ -189,6 +201,8 @@ private class FindPetsByTagsResponse(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun getPetById(petId: kotlin.Long) : HttpResponse { + val localVariableAuthNames = listOf("api_key") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -205,7 +219,8 @@ private class FindPetsByTagsResponse(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -218,6 +233,8 @@ private class FindPetsByTagsResponse(val value: List) { */ suspend fun updatePet(body: Pet) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = body val localVariableQuery = mutableMapOf>() @@ -233,7 +250,8 @@ private class FindPetsByTagsResponse(val value: List) { return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -249,6 +267,8 @@ private class FindPetsByTagsResponse(val value: List) { */ suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = ParametersBuilder().also { name?.apply { it.append("name", name.toString()) } @@ -268,7 +288,8 @@ private class FindPetsByTagsResponse(val value: List) { return urlEncodedFormRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -284,6 +305,8 @@ private class FindPetsByTagsResponse(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: io.ktor.client.request.forms.InputProvider?) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = formData { additionalMetadata?.apply { append("additionalMetadata", additionalMetadata) } @@ -303,7 +326,8 @@ private class FindPetsByTagsResponse(val value: List) { return multipartFormRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt index 86f32c9f978..56a581d3725 100644 --- a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -45,6 +45,8 @@ class StoreApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun deleteOrder(orderId: kotlin.String) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -61,7 +63,8 @@ class StoreApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -74,6 +77,8 @@ class StoreApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun getInventory() : HttpResponse> { + val localVariableAuthNames = listOf("api_key") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -90,7 +95,8 @@ class StoreApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap().map { value } } @@ -114,6 +120,8 @@ private class GetInventoryResponse(val value: Map) { @Suppress("UNCHECKED_CAST") suspend fun getOrderById(orderId: kotlin.Long) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -130,7 +138,8 @@ private class GetInventoryResponse(val value: Map) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -144,6 +153,8 @@ private class GetInventoryResponse(val value: Map) { @Suppress("UNCHECKED_CAST") suspend fun placeOrder(body: Order) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = body val localVariableQuery = mutableMapOf>() @@ -159,7 +170,8 @@ private class GetInventoryResponse(val value: Map) { return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt index 1977979c1d9..6786d3d3f33 100644 --- a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt @@ -45,6 +45,8 @@ class UserApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun createUser(body: User) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = body val localVariableQuery = mutableMapOf>() @@ -60,7 +62,8 @@ class UserApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -74,6 +77,8 @@ class UserApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun createUsersWithArrayInput(body: kotlin.Array) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = CreateUsersWithArrayInputRequest(body.asList()) val localVariableQuery = mutableMapOf>() @@ -89,7 +94,8 @@ class UserApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -112,6 +118,8 @@ private class CreateUsersWithArrayInputRequest(val value: List) { */ suspend fun createUsersWithListInput(body: kotlin.Array) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = CreateUsersWithListInputRequest(body.asList()) val localVariableQuery = mutableMapOf>() @@ -127,7 +135,8 @@ private class CreateUsersWithArrayInputRequest(val value: List) { return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -150,6 +159,8 @@ private class CreateUsersWithListInputRequest(val value: List) { */ suspend fun deleteUser(username: kotlin.String) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -166,7 +177,8 @@ private class CreateUsersWithListInputRequest(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -180,6 +192,8 @@ private class CreateUsersWithListInputRequest(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun getUserByName(username: kotlin.String) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -196,7 +210,8 @@ private class CreateUsersWithListInputRequest(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -211,6 +226,8 @@ private class CreateUsersWithListInputRequest(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun loginUser(username: kotlin.String, password: kotlin.String) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -229,7 +246,8 @@ private class CreateUsersWithListInputRequest(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -241,6 +259,8 @@ private class CreateUsersWithListInputRequest(val value: List) { */ suspend fun logoutUser() : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -257,7 +277,8 @@ private class CreateUsersWithListInputRequest(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -271,6 +292,8 @@ private class CreateUsersWithListInputRequest(val value: List) { */ suspend fun updateUser(username: kotlin.String, body: User) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = body val localVariableQuery = mutableMapOf>() @@ -286,7 +309,8 @@ private class CreateUsersWithListInputRequest(val value: List) { return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt new file mode 100644 index 00000000000..8bd8b59a8f8 --- /dev/null +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt @@ -0,0 +1,16 @@ +package org.openapitools.client.auth + +class ApiKeyAuth(private val location: String, val paramName: String) : Authentication { + var apiKey: String? = null + var apiKeyPrefix: String? = null + + override fun apply(query: MutableMap>, headers: MutableMap) { + val key: String = apiKey ?: return + val prefix: String? = apiKeyPrefix + val value: String = if (prefix != null) "$prefix $key" else key + when (location) { + "query" -> query[paramName] = listOf(value) + "header" -> headers[paramName] = value + } + } +} diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/Authentication.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/Authentication.kt new file mode 100644 index 00000000000..2c5dfb4acc5 --- /dev/null +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/Authentication.kt @@ -0,0 +1,13 @@ +package org.openapitools.client.auth + +interface Authentication { + + /** + * Apply authentication settings to header and query params. + * + * @param query Query parameters. + * @param headers Header parameters. + */ + fun apply(query: MutableMap>, headers: MutableMap) + +} diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt new file mode 100644 index 00000000000..5f0a52c1951 --- /dev/null +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt @@ -0,0 +1,17 @@ +package org.openapitools.client.auth + +import io.ktor.util.InternalAPI +import io.ktor.util.encodeBase64 + +class HttpBasicAuth : Authentication { + var username: String? = null + var password: String? = null + + @InternalAPI + override fun apply(query: MutableMap>, headers: MutableMap) { + if (username == null && password == null) return + val str = (username ?: "") + ":" + (password ?: "") + val auth = str.encodeBase64() + headers["Authorization"] = "Basic $auth" + } +} diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt new file mode 100644 index 00000000000..a6fb285af5c --- /dev/null +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt @@ -0,0 +1,14 @@ +package org.openapitools.client.auth + +class HttpBearerAuth(private val scheme: String?) : Authentication { + var bearerToken: String? = null + + override fun apply(query: MutableMap>, headers: MutableMap) { + val token: String = bearerToken ?: return + headers["Authorization"] = (if (scheme != null) upperCaseBearer(scheme)!! + " " else "") + token + } + + private fun upperCaseBearer(scheme: String): String? { + return if ("bearer".equals(scheme, ignoreCase = true)) "Bearer" else scheme + } +} diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/OAuth.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/OAuth.kt new file mode 100644 index 00000000000..08b289c2944 --- /dev/null +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/OAuth.kt @@ -0,0 +1,10 @@ +package org.openapitools.client.auth + +class OAuth : Authentication { + var accessToken: String? = null + + override fun apply(query: MutableMap>, headers: MutableMap) { + val token: String = accessToken ?: return + headers["Authorization"] = "Bearer $token" + } +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt index f97cb88d233..30d3705e5b4 100644 --- a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -1,6 +1,6 @@ package org.openapitools.client.infrastructure -typealias MultiValueMap = Map> +typealias MultiValueMap = MutableMap> fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { "csv" -> "," diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 66a5140d254..2257d47739c 100644 --- a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -23,6 +23,7 @@ import kotlinx.serialization.json.JsonConfiguration import org.openapitools.client.apis.* import org.openapitools.client.models.* +import org.openapitools.client.auth.* open class ApiClient( private val baseUrl: String, @@ -46,6 +47,12 @@ open class ApiClient( httpClientEngine?.let { HttpClient(it, clientConfig) } ?: HttpClient(clientConfig) } + private val authentications: kotlin.collections.Map by lazy { + mapOf( + "api_key" to ApiKeyAuth("header", "api_key"), + "petstore_auth" to OAuth()) + } + companion object { protected val UNSAFE_HEADERS = listOf(HttpHeaders.ContentType) @@ -57,31 +64,100 @@ open class ApiClient( UserApi.setMappers(serializer) - serializer.setMapper(ApiResponse::class, ApiResponse.serializer()) - serializer.setMapper(Category::class, Category.serializer()) - serializer.setMapper(Order::class, Order.serializer()) - serializer.setMapper(Pet::class, Pet.serializer()) - serializer.setMapper(Tag::class, Tag.serializer()) - serializer.setMapper(User::class, User.serializer()) + serializer.setMapper(org.openapitools.client.models.ApiResponse::class, org.openapitools.client.models.ApiResponse.serializer()) + serializer.setMapper(org.openapitools.client.models.Category::class, org.openapitools.client.models.Category.serializer()) + serializer.setMapper(org.openapitools.client.models.Order::class, org.openapitools.client.models.Order.serializer()) + serializer.setMapper(org.openapitools.client.models.Pet::class, org.openapitools.client.models.Pet.serializer()) + serializer.setMapper(org.openapitools.client.models.Tag::class, org.openapitools.client.models.Tag.serializer()) + serializer.setMapper(org.openapitools.client.models.User::class, org.openapitools.client.models.User.serializer()) } } - protected suspend fun multipartFormRequest(requestConfig: RequestConfig, body: List?): HttpResponse { - return request(requestConfig, MultiPartFormDataContent(body ?: listOf())) + /** + * Set the username for the first HTTP basic authentication. + * + * @param username Username + */ + fun setUsername(username: String) { + val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth? + ?: throw Exception("No HTTP basic authentication configured") + auth.username = username } - protected suspend fun urlEncodedFormRequest(requestConfig: RequestConfig, body: Parameters?): HttpResponse { - return request(requestConfig, FormDataContent(body ?: Parameters.Empty)) + /** + * Set the password for the first HTTP basic authentication. + * + * @param password Password + */ + fun setPassword(password: String) { + val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth? + ?: throw Exception("No HTTP basic authentication configured") + auth.password = password } - protected suspend fun jsonRequest(requestConfig: RequestConfig, body: Any? = null): HttpResponse { + /** + * Set the API key value for the first API key authentication. + * + * @param apiKey API key + * @param paramName The name of the API key parameter, or null or set the first key. + */ + fun setApiKey(apiKey: String, paramName: String? = null) { + val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName)} as ApiKeyAuth? + ?: throw Exception("No API key authentication configured") + auth.apiKey = apiKey + } + + /** + * Set the API key prefix for the first API key authentication. + * + * @param apiKeyPrefix API key prefix + * @param paramName The name of the API key parameter, or null or set the first key. + */ + fun setApiKeyPrefix(apiKeyPrefix: String, paramName: String? = null) { + val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName) } as ApiKeyAuth? + ?: throw Exception("No API key authentication configured") + auth.apiKeyPrefix = apiKeyPrefix + } + + /** + * Set the access token for the first OAuth2 authentication. + * + * @param accessToken Access token + */ + fun setAccessToken(accessToken: String) { + val auth = authentications.values.firstOrNull { it is OAuth } as OAuth? + ?: throw Exception("No OAuth2 authentication configured") + auth.accessToken = accessToken + } + + /** + * Set the access token for the first Bearer authentication. + * + * @param bearerToken The bearer token. + */ + fun setBearerToken(bearerToken: String) { + val auth = authentications.values.firstOrNull { it is HttpBearerAuth } as HttpBearerAuth? + ?: throw Exception("No Bearer authentication configured") + auth.bearerToken = bearerToken + } + + protected suspend fun multipartFormRequest(requestConfig: RequestConfig, body: kotlin.collections.List?, authNames: kotlin.collections.List): HttpResponse { + return request(requestConfig, MultiPartFormDataContent(body ?: listOf()), authNames) + } + + protected suspend fun urlEncodedFormRequest(requestConfig: RequestConfig, body: Parameters?, authNames: kotlin.collections.List): HttpResponse { + return request(requestConfig, FormDataContent(body ?: Parameters.Empty), authNames) + } + + protected suspend fun jsonRequest(requestConfig: RequestConfig, body: Any? = null, authNames: kotlin.collections.List): HttpResponse { val contentType = (requestConfig.headers[HttpHeaders.ContentType]?.let { ContentType.parse(it) } ?: ContentType.Application.Json) - return if (body != null) request(requestConfig, serializer.write(body, contentType)) - else request(requestConfig) + return if (body != null) request(requestConfig, serializer.write(body, contentType), authNames) + else request(requestConfig, authNames = authNames) } - protected suspend fun request(requestConfig: RequestConfig, body: OutgoingContent = EmptyContent): HttpResponse { + protected suspend fun request(requestConfig: RequestConfig, body: OutgoingContent = EmptyContent, authNames: kotlin.collections.List): HttpResponse { + requestConfig.updateForAuth(authNames) val headers = requestConfig.headers return client.call { @@ -102,7 +178,14 @@ open class ApiClient( }.response } - private fun URLBuilder.appendPath(components: List): URLBuilder = apply { + private fun RequestConfig.updateForAuth(authNames: kotlin.collections.List) { + for (authName in authNames) { + val auth = authentications[authName] ?: throw Exception("Authentication undefined: $authName") + auth.apply(query, headers) + } + } + + private fun URLBuilder.appendPath(components: kotlin.collections.List): URLBuilder = apply { encodedPath = encodedPath.trimEnd('/') + components.joinToString("/", prefix = "/") { it.encodeURLQueryComponent() } } diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt new file mode 100644 index 00000000000..4bc1197cf00 --- /dev/null +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt @@ -0,0 +1,29 @@ +package org.openapitools.client.infrastructure + +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor + +@Serializable +class Base64ByteArray(val value: ByteArray) { + @Serializer(Base64ByteArray::class) + companion object : KSerializer { + override val descriptor = StringDescriptor.withName("Base64ByteArray") + override fun serialize(encoder: Encoder, obj: Base64ByteArray) = encoder.encodeString(obj.value.encodeBase64()) + override fun deserialize(decoder: Decoder) = Base64ByteArray(decoder.decodeString().decodeBase64Bytes()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || this::class != other::class) return false + other as Base64ByteArray + return value.contentEquals(other.value) + } + + override fun hashCode(): Int { + return value.contentHashCode() + } + + override fun toString(): String { + return "Base64ByteArray(${hex(value)})" + } +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Bytes.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Bytes.kt new file mode 100644 index 00000000000..8a222416cf2 --- /dev/null +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Bytes.kt @@ -0,0 +1,102 @@ +package org.openapitools.client.infrastructure + +import kotlinx.io.core.* +import kotlin.experimental.and + +private val digits = "0123456789abcdef".toCharArray() +private const val BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" +private const val BASE64_MASK: Byte = 0x3f +private const val BASE64_PAD = '=' +private val BASE64_INVERSE_ALPHABET = IntArray(256) { BASE64_ALPHABET.indexOf(it.toChar()) } + +private fun String.toCharArray(): CharArray = CharArray(length) { get(it) } +private fun ByteArray.clearFrom(from: Int) = (from until size).forEach { this[it] = 0 } +private fun Int.toBase64(): Char = BASE64_ALPHABET[this] +private fun Byte.fromBase64(): Byte = BASE64_INVERSE_ALPHABET[toInt() and 0xff].toByte() and BASE64_MASK +internal fun ByteArray.encodeBase64(): String = buildPacket { writeFully(this@encodeBase64) }.encodeBase64() +internal fun String.decodeBase64Bytes(): ByteArray = buildPacket { writeStringUtf8(dropLastWhile { it == BASE64_PAD }) }.decodeBase64Bytes().readBytes() + +/** + * Encode [bytes] as a HEX string with no spaces, newlines and `0x` prefixes. + * + * Taken from https://github.com/ktorio/ktor/blob/master/ktor-utils/common/src/io/ktor/util/Crypto.kt + */ +internal fun hex(bytes: ByteArray): String { + val result = CharArray(bytes.size * 2) + var resultIndex = 0 + val digits = digits + + for (element in bytes) { + val b = element.toInt() and 0xff + result[resultIndex++] = digits[b shr 4] + result[resultIndex++] = digits[b and 0x0f] + } + + return String(result) +} + +/** + * Decode bytes from HEX string. It should be no spaces and `0x` prefixes. + * + * Taken from https://github.com/ktorio/ktor/blob/master/ktor-utils/common/src/io/ktor/util/Crypto.kt + */ +internal fun hex(s: String): ByteArray { + val result = ByteArray(s.length / 2) + for (idx in result.indices) { + val srcIdx = idx * 2 + val high = s[srcIdx].toString().toInt(16) shl 4 + val low = s[srcIdx + 1].toString().toInt(16) + result[idx] = (high or low).toByte() + } + + return result +} + +/** + * Encode [ByteReadPacket] in base64 format. + * + * Taken from https://github.com/ktorio/ktor/blob/424d1d2cfaa3281302c60af9500f738c8c2fc846/ktor-utils/common/src/io/ktor/util/Base64.kt + */ +private fun ByteReadPacket.encodeBase64(): String = buildString { + val data = ByteArray(3) + while (remaining > 0) { + val read = readAvailable(data) + data.clearFrom(read) + + val padSize = (data.size - read) * 8 / 6 + val chunk = ((data[0].toInt() and 0xFF) shl 16) or + ((data[1].toInt() and 0xFF) shl 8) or + (data[2].toInt() and 0xFF) + + for (index in data.size downTo padSize) { + val char = (chunk shr (6 * index)) and BASE64_MASK.toInt() + append(char.toBase64()) + } + + repeat(padSize) { append(BASE64_PAD) } + } +} + +/** + * Decode [ByteReadPacket] from base64 format + * + * Taken from https://github.com/ktorio/ktor/blob/424d1d2cfaa3281302c60af9500f738c8c2fc846/ktor-utils/common/src/io/ktor/util/Base64.kt + */ +private fun ByteReadPacket.decodeBase64Bytes(): Input = buildPacket { + val data = ByteArray(4) + + while (remaining > 0) { + val read = readAvailable(data) + + val chunk = data.foldIndexed(0) { index, result, current -> + result or (current.fromBase64().toInt() shl ((3 - index) * 6)) + } + + for (index in data.size - 2 downTo (data.size - read)) { + val origin = (chunk shr (8 * index)) and 0xff + writeByte(origin.toByte()) + } + } +} + + diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt new file mode 100644 index 00000000000..735e4e6e3f6 --- /dev/null +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt @@ -0,0 +1,29 @@ +package org.openapitools.client.infrastructure + +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor + +@Serializable +class OctetByteArray(val value: ByteArray) { + @Serializer(OctetByteArray::class) + companion object : KSerializer { + override val descriptor = StringDescriptor.withName("OctetByteArray") + override fun serialize(encoder: Encoder, obj: OctetByteArray) = encoder.encodeString(hex(obj.value)) + override fun deserialize(decoder: Decoder) = OctetByteArray(hex(decoder.decodeString())) + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || this::class != other::class) return false + other as OctetByteArray + return value.contentEquals(other.value) + } + + override fun hashCode(): Int { + return value.contentHashCode() + } + + override fun toString(): String { + return "OctetByteArray(${hex(value)})" + } +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 53e689237d7..9c22257e223 100644 --- a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,5 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: Map> = mapOf() + val query: MutableMap> = mutableMapOf() ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt index 7cf06b85d50..e6cdd21a006 100644 --- a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt @@ -46,7 +46,7 @@ data class Order ( approved("approved"), delivered("delivered"); - object Serializer : CommonEnumSerializer("Status", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("Status", values(), values().map { it.value.toString() }.toTypedArray()) } } diff --git a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt index 180c5ff98e6..3ac5ce7bb12 100644 --- a/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt +++ b/samples/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt @@ -48,7 +48,7 @@ data class Pet ( pending("pending"), sold("sold"); - object Serializer : CommonEnumSerializer("Status", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("Status", values(), values().map { it.value.toString() }.toTypedArray()) } } diff --git a/samples/client/petstore/kotlin-multiplatform/src/jsTest/kotlin/util/Coroutine.kt b/samples/client/petstore/kotlin-multiplatform/src/jsTest/kotlin/util/Coroutine.kt new file mode 100644 index 00000000000..2bea4861f67 --- /dev/null +++ b/samples/client/petstore/kotlin-multiplatform/src/jsTest/kotlin/util/Coroutine.kt @@ -0,0 +1,7 @@ +package util + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.promise + +actual fun runTest(block: suspend (scope : CoroutineScope) -> T): dynamic = GlobalScope.promise { block(this) } \ No newline at end of file diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 1bd48689c1e..c45cb1bdfb2 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -36,7 +36,7 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") */ fun addPet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -67,7 +67,7 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") */ fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("api_key" to apiKey.toString()) val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -166,7 +166,7 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") @Suppress("UNCHECKED_CAST") fun getPetById(petId: kotlin.Long) : Pet { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -196,7 +196,7 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") */ fun updatePet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -228,7 +228,7 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") */ fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = mapOf("name" to "$name", "status" to "$status") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -261,7 +261,7 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") @Suppress("UNCHECKED_CAST") fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse { val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to "$additionalMetadata", "file" to "$file") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index e2bf37917fe..8674aac2d62 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -35,7 +35,7 @@ internal class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2 */ fun deleteOrder(orderId: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -65,7 +65,7 @@ internal class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2 @Suppress("UNCHECKED_CAST") fun getInventory() : kotlin.collections.Map { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -96,7 +96,7 @@ internal class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2 @Suppress("UNCHECKED_CAST") fun getOrderById(orderId: kotlin.Long) : Order { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -127,7 +127,7 @@ internal class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2 @Suppress("UNCHECKED_CAST") fun placeOrder(body: Order) : Order { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 6a0c0b46346..c83a633b739 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -35,7 +35,7 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" */ fun createUser(body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -65,7 +65,7 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" */ fun createUsersWithArrayInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -95,7 +95,7 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" */ fun createUsersWithListInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -125,7 +125,7 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" */ fun deleteUser(username: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -156,7 +156,7 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" @Suppress("UNCHECKED_CAST") fun getUserByName(username: kotlin.String) : User { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -221,7 +221,7 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" */ fun logoutUser() : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -252,7 +252,7 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" */ fun updateUser(username: kotlin.String, body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt index b85d18def78..ed07e5d7543 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -1,6 +1,6 @@ package org.openapitools.client.infrastructure -typealias MultiValueMap = Map> +typealias MultiValueMap = MutableMap> internal fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { "csv" -> "," diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 14b306918fc..3e87d2c30f9 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,5 @@ internal data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: Map> = mapOf() + val query: MutableMap> = mutableMapOf() ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 9501ccfdfc5..00ca029e5a0 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -36,7 +36,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun addPet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -67,7 +67,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("api_key" to apiKey.toString()) val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -166,7 +166,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli @Suppress("UNCHECKED_CAST") fun getPetById(petId: kotlin.Long) : Pet { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -196,7 +196,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun updatePet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -228,7 +228,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = mapOf("name" to "$name", "status" to "$status") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -261,7 +261,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli @Suppress("UNCHECKED_CAST") fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse { val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to "$additionalMetadata", "file" to "$file") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 90d681f8f34..a26e1096b3b 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -35,7 +35,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC */ fun deleteOrder(orderId: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -65,7 +65,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun getInventory() : kotlin.collections.Map { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -96,7 +96,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun getOrderById(orderId: kotlin.Long) : Order { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -127,7 +127,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun placeOrder(body: Order) : Order { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 6028664673b..180fd748722 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -35,7 +35,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUser(body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -65,7 +65,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUsersWithArrayInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -95,7 +95,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUsersWithListInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -125,7 +125,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun deleteUser(username: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -156,7 +156,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl @Suppress("UNCHECKED_CAST") fun getUserByName(username: kotlin.String) : User { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -221,7 +221,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun logoutUser() : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -252,7 +252,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun updateUser(username: kotlin.String, body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt index f97cb88d233..30d3705e5b4 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -1,6 +1,6 @@ package org.openapitools.client.infrastructure -typealias MultiValueMap = Map> +typealias MultiValueMap = MutableMap> fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { "csv" -> "," diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 53e689237d7..9c22257e223 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,5 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: Map> = mapOf() + val query: MutableMap> = mutableMapOf() ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 9501ccfdfc5..00ca029e5a0 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -36,7 +36,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun addPet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -67,7 +67,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("api_key" to apiKey.toString()) val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -166,7 +166,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli @Suppress("UNCHECKED_CAST") fun getPetById(petId: kotlin.Long) : Pet { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -196,7 +196,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun updatePet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -228,7 +228,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = mapOf("name" to "$name", "status" to "$status") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -261,7 +261,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli @Suppress("UNCHECKED_CAST") fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse { val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to "$additionalMetadata", "file" to "$file") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 90d681f8f34..a26e1096b3b 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -35,7 +35,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC */ fun deleteOrder(orderId: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -65,7 +65,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun getInventory() : kotlin.collections.Map { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -96,7 +96,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun getOrderById(orderId: kotlin.Long) : Order { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -127,7 +127,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun placeOrder(body: Order) : Order { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 6028664673b..180fd748722 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -35,7 +35,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUser(body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -65,7 +65,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUsersWithArrayInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -95,7 +95,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUsersWithListInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -125,7 +125,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun deleteUser(username: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -156,7 +156,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl @Suppress("UNCHECKED_CAST") fun getUserByName(username: kotlin.String) : User { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -221,7 +221,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun logoutUser() : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -252,7 +252,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun updateUser(username: kotlin.String, body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt index f97cb88d233..30d3705e5b4 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -1,6 +1,6 @@ package org.openapitools.client.infrastructure -typealias MultiValueMap = Map> +typealias MultiValueMap = MutableMap> fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { "csv" -> "," diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 53e689237d7..9c22257e223 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,5 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: Map> = mapOf() + val query: MutableMap> = mutableMapOf() ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 9501ccfdfc5..00ca029e5a0 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -36,7 +36,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun addPet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -67,7 +67,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("api_key" to apiKey.toString()) val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -166,7 +166,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli @Suppress("UNCHECKED_CAST") fun getPetById(petId: kotlin.Long) : Pet { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -196,7 +196,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun updatePet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -228,7 +228,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = mapOf("name" to "$name", "status" to "$status") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -261,7 +261,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli @Suppress("UNCHECKED_CAST") fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse { val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to "$additionalMetadata", "file" to "$file") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 90d681f8f34..a26e1096b3b 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -35,7 +35,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC */ fun deleteOrder(orderId: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -65,7 +65,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun getInventory() : kotlin.collections.Map { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -96,7 +96,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun getOrderById(orderId: kotlin.Long) : Order { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -127,7 +127,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun placeOrder(body: Order) : Order { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 6028664673b..180fd748722 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -35,7 +35,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUser(body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -65,7 +65,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUsersWithArrayInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -95,7 +95,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUsersWithListInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -125,7 +125,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun deleteUser(username: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -156,7 +156,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl @Suppress("UNCHECKED_CAST") fun getUserByName(username: kotlin.String) : User { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -221,7 +221,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun logoutUser() : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -252,7 +252,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun updateUser(username: kotlin.String, body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt index f97cb88d233..30d3705e5b4 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -1,6 +1,6 @@ package org.openapitools.client.infrastructure -typealias MultiValueMap = Map> +typealias MultiValueMap = MutableMap> fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { "csv" -> "," diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 53e689237d7..9c22257e223 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,5 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: Map> = mapOf() + val query: MutableMap> = mutableMapOf() ) \ No newline at end of file diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 9501ccfdfc5..00ca029e5a0 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -36,7 +36,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun addPet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -67,7 +67,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("api_key" to apiKey.toString()) val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -166,7 +166,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli @Suppress("UNCHECKED_CAST") fun getPetById(petId: kotlin.Long) : Pet { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -196,7 +196,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun updatePet(body: Pet) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -228,7 +228,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli */ fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = mapOf("name" to "$name", "status" to "$status") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -261,7 +261,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli @Suppress("UNCHECKED_CAST") fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse { val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to "$additionalMetadata", "file" to "$file") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 90d681f8f34..a26e1096b3b 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -35,7 +35,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC */ fun deleteOrder(orderId: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -65,7 +65,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun getInventory() : kotlin.collections.Map { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -96,7 +96,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun getOrderById(orderId: kotlin.Long) : Order { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -127,7 +127,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC @Suppress("UNCHECKED_CAST") fun placeOrder(body: Order) : Order { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 6028664673b..180fd748722 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -35,7 +35,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUser(body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -65,7 +65,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUsersWithArrayInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -95,7 +95,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun createUsersWithListInput(body: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -125,7 +125,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun deleteUser(username: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -156,7 +156,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl @Suppress("UNCHECKED_CAST") fun getUserByName(username: kotlin.String) : User { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -221,7 +221,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun logoutUser() : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -252,7 +252,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl */ fun updateUser(username: kotlin.String, body: User) : Unit { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt index f97cb88d233..30d3705e5b4 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -1,6 +1,6 @@ package org.openapitools.client.infrastructure -typealias MultiValueMap = Map> +typealias MultiValueMap = MutableMap> fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { "csv" -> "," diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 53e689237d7..9c22257e223 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,5 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: Map> = mapOf() + val query: MutableMap> = mutableMapOf() ) \ No newline at end of file diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/.openapi-generator/VERSION b/samples/openapi3/client/petstore/kotlin-multiplatform/.openapi-generator/VERSION index 0e97bd19efb..c3a2c7076fa 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/.openapi-generator/VERSION +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/.openapi-generator/VERSION @@ -1 +1 @@ -4.1.3-SNAPSHOT \ No newline at end of file +4.2.0-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/build.gradle b/samples/openapi3/client/petstore/kotlin-multiplatform/build.gradle index c976992112f..47045bb577e 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/build.gradle +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/build.gradle @@ -30,6 +30,7 @@ kotlin { jvm() iosArm64() { binaries { framework { freeCompilerArgs.add("-Xobjc-generics") } } } iosX64() { binaries { framework { freeCompilerArgs.add("-Xobjc-generics") } } } + js() sourceSets { commonMain { @@ -37,9 +38,9 @@ kotlin { implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" - implementation "io.ktor:ktor-client-core:$ktor_version" - implementation "io.ktor:ktor-client-json:$ktor_version" - implementation "io.ktor:ktor-client-serialization:$ktor_version" + api "io.ktor:ktor-client-core:$ktor_version" + api "io.ktor:ktor-client-json:$ktor_version" + api "io.ktor:ktor-client-serialization:$ktor_version" } } @@ -57,9 +58,9 @@ kotlin { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version" - implementation "io.ktor:ktor-client-core-jvm:$ktor_version" - implementation "io.ktor:ktor-client-json-jvm:$ktor_version" - implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version" + api "io.ktor:ktor-client-core-jvm:$ktor_version" + api "io.ktor:ktor-client-json-jvm:$ktor_version" + api "io.ktor:ktor-client-serialization-jvm:$ktor_version" } } @@ -77,7 +78,7 @@ kotlin { dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version" - implementation "io.ktor:ktor-client-ios:$ktor_version" + api "io.ktor:ktor-client-ios:$ktor_version" } } @@ -91,9 +92,9 @@ kotlin { iosArm64().compilations.main.defaultSourceSet { dependsOn iosMain dependencies { - implementation "io.ktor:ktor-client-ios-iosarm64:$ktor_version" - implementation "io.ktor:ktor-client-json-iosarm64:$ktor_version" - implementation "io.ktor:ktor-client-serialization-iosarm64:$ktor_version" + api "io.ktor:ktor-client-ios-iosarm64:$ktor_version" + api "io.ktor:ktor-client-json-iosarm64:$ktor_version" + api "io.ktor:ktor-client-serialization-iosarm64:$ktor_version" } } @@ -104,9 +105,31 @@ kotlin { iosX64().compilations.main.defaultSourceSet { dependsOn iosMain dependencies { - implementation "io.ktor:ktor-client-ios-iosx64:$ktor_version" - implementation "io.ktor:ktor-client-json-iosx64:$ktor_version" - implementation "io.ktor:ktor-client-serialization-iosx64:$ktor_version" + api "io.ktor:ktor-client-ios-iosx64:$ktor_version" + api "io.ktor:ktor-client-json-iosx64:$ktor_version" + api "io.ktor:ktor-client-serialization-iosx64:$ktor_version" + } + } + + jsMain { + dependsOn commonMain + dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutines_version" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version" + api "io.ktor:ktor-client-js:$ktor_version" + api "io.ktor:ktor-client-json-js:$ktor_version" + api "io.ktor:ktor-client-serialization-js:$ktor_version" + } + } + + jsTest { + dependsOn commonTest + dependencies { + implementation "io.ktor:ktor-client-mock-js:$ktor_version" + implementation "io.ktor:ktor-client-js:$ktor_version" + implementation "io.ktor:ktor-client-json:$ktor_version" + implementation "io.ktor:ktor-client-serialization-js:$ktor_version" } } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FakeApi.md b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FakeApi.md index 88394442015..02154eac112 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FakeApi.md @@ -406,7 +406,7 @@ val apiInstance = FakeApi() val number : kotlin.Double = 8.14 // kotlin.Double | None val double : kotlin.Double = 1.2 // kotlin.Double | None val patternWithoutDelimiter : kotlin.String = patternWithoutDelimiter_example // kotlin.String | None -val byte : kotlin.ByteArray = BYTE_ARRAY_DATA_HERE // kotlin.ByteArray | None +val byte : org.openapitools.client.infrastructure.Base64ByteArray = BYTE_ARRAY_DATA_HERE // org.openapitools.client.infrastructure.Base64ByteArray | None val integer : kotlin.Int = 56 // kotlin.Int | None val int32 : kotlin.Int = 56 // kotlin.Int | None val int64 : kotlin.Long = 789 // kotlin.Long | None @@ -435,7 +435,7 @@ Name | Type | Description | Notes **number** | **kotlin.Double**| None | **double** | **kotlin.Double**| None | **patternWithoutDelimiter** | **kotlin.String**| None | - **byte** | **kotlin.ByteArray**| None | + **byte** | **org.openapitools.client.infrastructure.Base64ByteArray**| None | **integer** | **kotlin.Int**| None | [optional] **int32** | **kotlin.Int**| None | [optional] **int64** | **kotlin.Long**| None | [optional] diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FileSchemaTestClass.md b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FileSchemaTestClass.md index 86b89d253d6..d49a2b6e445 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FileSchemaTestClass.md +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FileSchemaTestClass.md @@ -4,8 +4,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**file** | [**io.ktor.client.request.forms.InputProvider**](io.ktor.client.request.forms.InputProvider.md) | | [optional] -**files** | [**kotlin.Array<io.ktor.client.request.forms.InputProvider>**](io.ktor.client.request.forms.InputProvider.md) | | [optional] +**file** | [**org.openapitools.client.infrastructure.OctetByteArray**](org.openapitools.client.infrastructure.OctetByteArray.md) | | [optional] +**files** | [**kotlin.Array<org.openapitools.client.infrastructure.OctetByteArray>**](org.openapitools.client.infrastructure.OctetByteArray.md) | | [optional] diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FormatTest.md b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FormatTest.md index f973a49e095..7f3aec255b4 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FormatTest.md +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/FormatTest.md @@ -11,8 +11,8 @@ Name | Type | Description | Notes **float** | **kotlin.Float** | | [optional] **double** | **kotlin.Double** | | [optional] **string** | **kotlin.String** | | [optional] -**byte** | **kotlin.ByteArray** | | -**binary** | [**io.ktor.client.request.forms.InputProvider**](io.ktor.client.request.forms.InputProvider.md) | | [optional] +**byte** | [**org.openapitools.client.infrastructure.Base64ByteArray**](org.openapitools.client.infrastructure.Base64ByteArray.md) | | +**binary** | [**org.openapitools.client.infrastructure.OctetByteArray**](org.openapitools.client.infrastructure.OctetByteArray.md) | | [optional] **date** | **kotlin.String** | | **dateTime** | **kotlin.String** | | [optional] **uuid** | **kotlin.String** | | [optional] diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/HasOnlyReadOnly.md b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/HasOnlyReadOnly.md index 22f5ebf5170..ed3e4750f44 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/HasOnlyReadOnly.md +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/HasOnlyReadOnly.md @@ -4,8 +4,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**bar** | **kotlin.String** | | [optional] -**foo** | **kotlin.String** | | [optional] +**bar** | **kotlin.String** | | [optional] [readonly] +**foo** | **kotlin.String** | | [optional] [readonly] diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject1.md b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject1.md index 43c5b5f742c..a1e2ddc92c9 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject1.md +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject1.md @@ -5,7 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **additionalMetadata** | **kotlin.String** | Additional data to pass to server | [optional] -**file** | [**io.ktor.client.request.forms.InputProvider**](io.ktor.client.request.forms.InputProvider.md) | file to upload | [optional] +**file** | [**org.openapitools.client.infrastructure.OctetByteArray**](org.openapitools.client.infrastructure.OctetByteArray.md) | file to upload | [optional] diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject3.md b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject3.md index 82bf6d182b6..92279bc2976 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject3.md +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject3.md @@ -12,8 +12,8 @@ Name | Type | Description | Notes **double** | **kotlin.Double** | None | **string** | **kotlin.String** | None | [optional] **patternWithoutDelimiter** | **kotlin.String** | None | -**byte** | **kotlin.ByteArray** | None | -**binary** | [**io.ktor.client.request.forms.InputProvider**](io.ktor.client.request.forms.InputProvider.md) | None | [optional] +**byte** | [**org.openapitools.client.infrastructure.Base64ByteArray**](org.openapitools.client.infrastructure.Base64ByteArray.md) | None | +**binary** | [**org.openapitools.client.infrastructure.OctetByteArray**](org.openapitools.client.infrastructure.OctetByteArray.md) | None | [optional] **date** | **kotlin.String** | None | [optional] **dateTime** | **kotlin.String** | None | [optional] **password** | **kotlin.String** | None | [optional] diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject5.md b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject5.md index 9e7765c3aa6..fd2cee485c1 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject5.md +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/InlineObject5.md @@ -5,7 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **additionalMetadata** | **kotlin.String** | Additional data to pass to server | [optional] -**requiredFile** | [**io.ktor.client.request.forms.InputProvider**](io.ktor.client.request.forms.InputProvider.md) | file to upload | +**requiredFile** | [**org.openapitools.client.infrastructure.OctetByteArray**](org.openapitools.client.infrastructure.OctetByteArray.md) | file to upload | diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/Name.md b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/Name.md index 7eb6f21121e..343700533c7 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/Name.md +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/Name.md @@ -5,9 +5,9 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | **kotlin.Int** | | -**snakeCase** | **kotlin.Int** | | [optional] +**snakeCase** | **kotlin.Int** | | [optional] [readonly] **property** | **kotlin.String** | | [optional] -**`123number`** | **kotlin.Int** | | [optional] +**`123number`** | **kotlin.Int** | | [optional] [readonly] diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/NullableClass.md b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/NullableClass.md index 7461cacac88..c2813940f14 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/NullableClass.md @@ -10,12 +10,12 @@ Name | Type | Description | Notes **stringProp** | **kotlin.String** | | [optional] **dateProp** | **kotlin.String** | | [optional] **datetimeProp** | **kotlin.String** | | [optional] -**arrayNullableProp** | [**kotlin.Array<kotlin.Any>**](kotlin.Any.md) | | [optional] -**arrayAndItemsNullableProp** | [**kotlin.Array<kotlin.Any>**](kotlin.Any.md) | | [optional] -**arrayItemsNullable** | [**kotlin.Array<kotlin.Any>**](kotlin.Any.md) | | [optional] -**objectNullableProp** | [**kotlin.collections.Map<kotlin.String, kotlin.Any>**](kotlin.Any.md) | | [optional] -**objectAndItemsNullableProp** | [**kotlin.collections.Map<kotlin.String, kotlin.Any>**](kotlin.Any.md) | | [optional] -**objectItemsNullable** | [**kotlin.collections.Map<kotlin.String, kotlin.Any>**](kotlin.Any.md) | | [optional] +**arrayNullableProp** | **kotlin.Array<kotlin.String>** | | [optional] +**arrayAndItemsNullableProp** | **kotlin.Array<kotlin.String>** | | [optional] +**arrayItemsNullable** | **kotlin.Array<kotlin.String>** | | [optional] +**objectNullableProp** | **kotlin.collections.Map<kotlin.String, kotlin.String>** | | [optional] +**objectAndItemsNullableProp** | **kotlin.collections.Map<kotlin.String, kotlin.String>** | | [optional] +**objectItemsNullable** | **kotlin.collections.Map<kotlin.String, kotlin.String>** | | [optional] diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/ReadOnlyFirst.md b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/ReadOnlyFirst.md index 26aa9f3ac4d..825f613f090 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/docs/ReadOnlyFirst.md +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/docs/ReadOnlyFirst.md @@ -4,7 +4,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**bar** | **kotlin.String** | | [optional] +**bar** | **kotlin.String** | | [optional] [readonly] **baz** | **kotlin.String** | | [optional] diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/AnotherFakeApi.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/AnotherFakeApi.kt index 7d72ccb712b..23f6e27e489 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/AnotherFakeApi.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/AnotherFakeApi.kt @@ -46,6 +46,8 @@ class AnotherFakeApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun call123testSpecialTags(client: Client) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = client val localVariableQuery = mutableMapOf>() @@ -61,7 +63,8 @@ class AnotherFakeApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/DefaultApi.kt index 49da05cc1e5..6b0bae98cfb 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -45,6 +45,8 @@ class DefaultApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun fooGet() : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -61,7 +63,8 @@ class DefaultApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/FakeApi.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/FakeApi.kt index e7a28b7e291..4675fdc4b84 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/FakeApi.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/FakeApi.kt @@ -49,6 +49,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun fakeHealthGet() : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -65,7 +67,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -79,6 +82,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun fakeOuterBooleanSerialize(body: kotlin.Boolean?) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = body val localVariableQuery = mutableMapOf>() @@ -94,7 +99,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -109,6 +115,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun fakeOuterCompositeSerialize(outerComposite: OuterComposite?) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = outerComposite val localVariableQuery = mutableMapOf>() @@ -124,7 +132,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -139,6 +148,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun fakeOuterNumberSerialize(body: kotlin.Double?) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = body val localVariableQuery = mutableMapOf>() @@ -154,7 +165,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -169,6 +181,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun fakeOuterStringSerialize(body: kotlin.String?) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = body val localVariableQuery = mutableMapOf>() @@ -184,7 +198,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -198,6 +213,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun testBodyWithFileSchema(fileSchemaTestClass: FileSchemaTestClass) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = fileSchemaTestClass val localVariableQuery = mutableMapOf>() @@ -213,7 +230,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -228,6 +246,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun testBodyWithQueryParams(query: kotlin.String, user: User) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = user val localVariableQuery = mutableMapOf>() @@ -244,7 +264,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -259,6 +280,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun testClientModel(client: Client) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = client val localVariableQuery = mutableMapOf>() @@ -274,7 +297,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -299,7 +323,9 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( * @param paramCallback None (optional) * @return void */ - suspend fun testEndpointParameters(number: kotlin.Double, double: kotlin.Double, patternWithoutDelimiter: kotlin.String, byte: kotlin.ByteArray, integer: kotlin.Int?, int32: kotlin.Int?, int64: kotlin.Long?, float: kotlin.Float?, string: kotlin.String?, binary: io.ktor.client.request.forms.InputProvider?, date: kotlin.String?, dateTime: kotlin.String?, password: kotlin.String?, paramCallback: kotlin.String?) : HttpResponse { + suspend fun testEndpointParameters(number: kotlin.Double, double: kotlin.Double, patternWithoutDelimiter: kotlin.String, byte: org.openapitools.client.infrastructure.Base64ByteArray, integer: kotlin.Int?, int32: kotlin.Int?, int64: kotlin.Long?, float: kotlin.Float?, string: kotlin.String?, binary: io.ktor.client.request.forms.InputProvider?, date: kotlin.String?, dateTime: kotlin.String?, password: kotlin.String?, paramCallback: kotlin.String?) : HttpResponse { + + val localVariableAuthNames = listOf("http_basic_test") val localVariableBody = ParametersBuilder().also { @@ -332,7 +358,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return urlEncodedFormRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -352,6 +379,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun testEnumParameters(enumHeaderStringArray: kotlin.Array?, enumHeaderString: kotlin.String?, enumQueryStringArray: kotlin.Array?, enumQueryString: kotlin.String?, enumQueryInteger: kotlin.Int?, enumQueryDouble: kotlin.Double?, enumFormStringArray: kotlin.Array?, enumFormString: kotlin.String?) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = ParametersBuilder().also { enumFormStringArray?.apply { it.append("enum_form_string_array", enumFormStringArray.toString()) } @@ -377,7 +406,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return urlEncodedFormRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -395,6 +425,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun testGroupParameters(requiredStringGroup: kotlin.Int, requiredBooleanGroup: kotlin.Boolean, requiredInt64Group: kotlin.Long, stringGroup: kotlin.Int?, booleanGroup: kotlin.Boolean?, int64Group: kotlin.Long?) : HttpResponse { + val localVariableAuthNames = listOf("bearer_test") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -417,7 +449,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -430,6 +463,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun testInlineAdditionalProperties(requestBody: kotlin.collections.Map) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = TestInlineAdditionalPropertiesRequest(requestBody) val localVariableQuery = mutableMapOf>() @@ -445,7 +480,8 @@ class FakeApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -469,6 +505,8 @@ private class TestInlineAdditionalPropertiesRequest(val value: Map { + val localVariableAuthNames = listOf() + val localVariableBody = ParametersBuilder().also { param?.apply { it.append("param", param.toString()) } @@ -488,7 +526,8 @@ private class TestInlineAdditionalPropertiesRequest(val value: Map, ioutil: kotlin.Array, http: kotlin.Array, url: kotlin.Array, context: kotlin.Array) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -526,7 +567,8 @@ private class TestInlineAdditionalPropertiesRequest(val value: Map { + val localVariableAuthNames = listOf("api_key_query") + val localVariableBody = client val localVariableQuery = mutableMapOf>() @@ -61,7 +63,8 @@ class FakeClassnameTags123Api @UseExperimental(UnstableDefault::class) construct return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt index dd85a10282c..19afc14b59e 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/PetApi.kt @@ -46,6 +46,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun addPet(pet: Pet) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = pet val localVariableQuery = mutableMapOf>() @@ -61,7 +63,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -76,6 +79,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -93,7 +98,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -107,6 +113,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun findPetsByStatus(status: kotlin.Array) : HttpResponse> { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -124,7 +132,8 @@ class PetApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap().map { value.toTypedArray() } } @@ -148,6 +157,8 @@ private class FindPetsByStatusResponse(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun findPetsByTags(tags: kotlin.Array) : HttpResponse> { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -165,7 +176,8 @@ private class FindPetsByStatusResponse(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap().map { value.toTypedArray() } } @@ -189,6 +201,8 @@ private class FindPetsByTagsResponse(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun getPetById(petId: kotlin.Long) : HttpResponse { + val localVariableAuthNames = listOf("api_key") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -205,7 +219,8 @@ private class FindPetsByTagsResponse(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -218,6 +233,8 @@ private class FindPetsByTagsResponse(val value: List) { */ suspend fun updatePet(pet: Pet) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = pet val localVariableQuery = mutableMapOf>() @@ -233,7 +250,8 @@ private class FindPetsByTagsResponse(val value: List) { return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -249,6 +267,8 @@ private class FindPetsByTagsResponse(val value: List) { */ suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = ParametersBuilder().also { name?.apply { it.append("name", name.toString()) } @@ -268,7 +288,8 @@ private class FindPetsByTagsResponse(val value: List) { return urlEncodedFormRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -284,6 +305,8 @@ private class FindPetsByTagsResponse(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: io.ktor.client.request.forms.InputProvider?) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = formData { additionalMetadata?.apply { append("additionalMetadata", additionalMetadata) } @@ -303,7 +326,8 @@ private class FindPetsByTagsResponse(val value: List) { return multipartFormRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -319,6 +343,8 @@ private class FindPetsByTagsResponse(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun uploadFileWithRequiredFile(petId: kotlin.Long, requiredFile: io.ktor.client.request.forms.InputProvider, additionalMetadata: kotlin.String?) : HttpResponse { + val localVariableAuthNames = listOf("petstore_auth") + val localVariableBody = formData { additionalMetadata?.apply { append("additionalMetadata", additionalMetadata) } @@ -338,7 +364,8 @@ private class FindPetsByTagsResponse(val value: List) { return multipartFormRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt index 734883da99d..5085e5f42fd 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -45,6 +45,8 @@ class StoreApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun deleteOrder(orderId: kotlin.String) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -61,7 +63,8 @@ class StoreApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -74,6 +77,8 @@ class StoreApi @UseExperimental(UnstableDefault::class) constructor( @Suppress("UNCHECKED_CAST") suspend fun getInventory() : HttpResponse> { + val localVariableAuthNames = listOf("api_key") + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -90,7 +95,8 @@ class StoreApi @UseExperimental(UnstableDefault::class) constructor( return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap().map { value } } @@ -114,6 +120,8 @@ private class GetInventoryResponse(val value: Map) { @Suppress("UNCHECKED_CAST") suspend fun getOrderById(orderId: kotlin.Long) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -130,7 +138,8 @@ private class GetInventoryResponse(val value: Map) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -144,6 +153,8 @@ private class GetInventoryResponse(val value: Map) { @Suppress("UNCHECKED_CAST") suspend fun placeOrder(order: Order) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = order val localVariableQuery = mutableMapOf>() @@ -159,7 +170,8 @@ private class GetInventoryResponse(val value: Map) { return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt index 266689874c9..877dc28b230 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/apis/UserApi.kt @@ -45,6 +45,8 @@ class UserApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun createUser(user: User) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = user val localVariableQuery = mutableMapOf>() @@ -60,7 +62,8 @@ class UserApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -74,6 +77,8 @@ class UserApi @UseExperimental(UnstableDefault::class) constructor( */ suspend fun createUsersWithArrayInput(user: kotlin.Array) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = CreateUsersWithArrayInputRequest(user.asList()) val localVariableQuery = mutableMapOf>() @@ -89,7 +94,8 @@ class UserApi @UseExperimental(UnstableDefault::class) constructor( return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -112,6 +118,8 @@ private class CreateUsersWithArrayInputRequest(val value: List) { */ suspend fun createUsersWithListInput(user: kotlin.Array) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = CreateUsersWithListInputRequest(user.asList()) val localVariableQuery = mutableMapOf>() @@ -127,7 +135,8 @@ private class CreateUsersWithArrayInputRequest(val value: List) { return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -150,6 +159,8 @@ private class CreateUsersWithListInputRequest(val value: List) { */ suspend fun deleteUser(username: kotlin.String) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -166,7 +177,8 @@ private class CreateUsersWithListInputRequest(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -180,6 +192,8 @@ private class CreateUsersWithListInputRequest(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun getUserByName(username: kotlin.String) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -196,7 +210,8 @@ private class CreateUsersWithListInputRequest(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -211,6 +226,8 @@ private class CreateUsersWithListInputRequest(val value: List) { @Suppress("UNCHECKED_CAST") suspend fun loginUser(username: kotlin.String, password: kotlin.String) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -229,7 +246,8 @@ private class CreateUsersWithListInputRequest(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -241,6 +259,8 @@ private class CreateUsersWithListInputRequest(val value: List) { */ suspend fun logoutUser() : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = io.ktor.client.utils.EmptyContent @@ -257,7 +277,8 @@ private class CreateUsersWithListInputRequest(val value: List) { return request( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } @@ -271,6 +292,8 @@ private class CreateUsersWithListInputRequest(val value: List) { */ suspend fun updateUser(username: kotlin.String, user: User) : HttpResponse { + val localVariableAuthNames = listOf() + val localVariableBody = user val localVariableQuery = mutableMapOf>() @@ -286,7 +309,8 @@ private class CreateUsersWithListInputRequest(val value: List) { return jsonRequest( localVariableConfig, - localVariableBody + localVariableBody, + localVariableAuthNames ).wrap() } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt new file mode 100644 index 00000000000..8bd8b59a8f8 --- /dev/null +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt @@ -0,0 +1,16 @@ +package org.openapitools.client.auth + +class ApiKeyAuth(private val location: String, val paramName: String) : Authentication { + var apiKey: String? = null + var apiKeyPrefix: String? = null + + override fun apply(query: MutableMap>, headers: MutableMap) { + val key: String = apiKey ?: return + val prefix: String? = apiKeyPrefix + val value: String = if (prefix != null) "$prefix $key" else key + when (location) { + "query" -> query[paramName] = listOf(value) + "header" -> headers[paramName] = value + } + } +} diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/Authentication.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/Authentication.kt new file mode 100644 index 00000000000..2c5dfb4acc5 --- /dev/null +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/Authentication.kt @@ -0,0 +1,13 @@ +package org.openapitools.client.auth + +interface Authentication { + + /** + * Apply authentication settings to header and query params. + * + * @param query Query parameters. + * @param headers Header parameters. + */ + fun apply(query: MutableMap>, headers: MutableMap) + +} diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt new file mode 100644 index 00000000000..5f0a52c1951 --- /dev/null +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt @@ -0,0 +1,17 @@ +package org.openapitools.client.auth + +import io.ktor.util.InternalAPI +import io.ktor.util.encodeBase64 + +class HttpBasicAuth : Authentication { + var username: String? = null + var password: String? = null + + @InternalAPI + override fun apply(query: MutableMap>, headers: MutableMap) { + if (username == null && password == null) return + val str = (username ?: "") + ":" + (password ?: "") + val auth = str.encodeBase64() + headers["Authorization"] = "Basic $auth" + } +} diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt new file mode 100644 index 00000000000..a6fb285af5c --- /dev/null +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt @@ -0,0 +1,14 @@ +package org.openapitools.client.auth + +class HttpBearerAuth(private val scheme: String?) : Authentication { + var bearerToken: String? = null + + override fun apply(query: MutableMap>, headers: MutableMap) { + val token: String = bearerToken ?: return + headers["Authorization"] = (if (scheme != null) upperCaseBearer(scheme)!! + " " else "") + token + } + + private fun upperCaseBearer(scheme: String): String? { + return if ("bearer".equals(scheme, ignoreCase = true)) "Bearer" else scheme + } +} diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/OAuth.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/OAuth.kt new file mode 100644 index 00000000000..08b289c2944 --- /dev/null +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/auth/OAuth.kt @@ -0,0 +1,10 @@ +package org.openapitools.client.auth + +class OAuth : Authentication { + var accessToken: String? = null + + override fun apply(query: MutableMap>, headers: MutableMap) { + val token: String = accessToken ?: return + headers["Authorization"] = "Bearer $token" + } +} \ No newline at end of file diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt index f97cb88d233..30d3705e5b4 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -1,6 +1,6 @@ package org.openapitools.client.infrastructure -typealias MultiValueMap = Map> +typealias MultiValueMap = MutableMap> fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { "csv" -> "," diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index e87eecb1b88..f689b9d234e 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -23,6 +23,7 @@ import kotlinx.serialization.json.JsonConfiguration import org.openapitools.client.apis.* import org.openapitools.client.models.* +import org.openapitools.client.auth.* open class ApiClient( private val baseUrl: String, @@ -46,6 +47,15 @@ open class ApiClient( httpClientEngine?.let { HttpClient(it, clientConfig) } ?: HttpClient(clientConfig) } + private val authentications: kotlin.collections.Map by lazy { + mapOf( + "api_key" to ApiKeyAuth("header", "api_key"), + "api_key_query" to ApiKeyAuth("query", "api_key_query"), + "bearer_test" to HttpBearerAuth("bearer"), + "http_basic_test" to HttpBasicAuth(), + "petstore_auth" to OAuth()) + } + companion object { protected val UNSAFE_HEADERS = listOf(HttpHeaders.ContentType) @@ -65,73 +75,142 @@ open class ApiClient( UserApi.setMappers(serializer) - serializer.setMapper(AdditionalPropertiesClass::class, AdditionalPropertiesClass.serializer()) - serializer.setMapper(Animal::class, Animal.serializer()) - serializer.setMapper(ApiResponse::class, ApiResponse.serializer()) - serializer.setMapper(ArrayOfArrayOfNumberOnly::class, ArrayOfArrayOfNumberOnly.serializer()) - serializer.setMapper(ArrayOfNumberOnly::class, ArrayOfNumberOnly.serializer()) - serializer.setMapper(ArrayTest::class, ArrayTest.serializer()) - serializer.setMapper(Capitalization::class, Capitalization.serializer()) - serializer.setMapper(Cat::class, Cat.serializer()) - serializer.setMapper(CatAllOf::class, CatAllOf.serializer()) - serializer.setMapper(Category::class, Category.serializer()) - serializer.setMapper(ClassModel::class, ClassModel.serializer()) - serializer.setMapper(Client::class, Client.serializer()) - serializer.setMapper(Dog::class, Dog.serializer()) - serializer.setMapper(DogAllOf::class, DogAllOf.serializer()) - serializer.setMapper(EnumArrays::class, EnumArrays.serializer()) - serializer.setMapper(EnumClass::class, EnumClass.serializer()) - serializer.setMapper(EnumTest::class, EnumTest.serializer()) - serializer.setMapper(FileSchemaTestClass::class, FileSchemaTestClass.serializer()) - serializer.setMapper(Foo::class, Foo.serializer()) - serializer.setMapper(FormatTest::class, FormatTest.serializer()) - serializer.setMapper(HasOnlyReadOnly::class, HasOnlyReadOnly.serializer()) - serializer.setMapper(HealthCheckResult::class, HealthCheckResult.serializer()) - serializer.setMapper(InlineObject::class, InlineObject.serializer()) - serializer.setMapper(InlineObject1::class, InlineObject1.serializer()) - serializer.setMapper(InlineObject2::class, InlineObject2.serializer()) - serializer.setMapper(InlineObject3::class, InlineObject3.serializer()) - serializer.setMapper(InlineObject4::class, InlineObject4.serializer()) - serializer.setMapper(InlineObject5::class, InlineObject5.serializer()) - serializer.setMapper(InlineResponseDefault::class, InlineResponseDefault.serializer()) - serializer.setMapper(List::class, List.serializer()) - serializer.setMapper(MapTest::class, MapTest.serializer()) - serializer.setMapper(MixedPropertiesAndAdditionalPropertiesClass::class, MixedPropertiesAndAdditionalPropertiesClass.serializer()) - serializer.setMapper(Model200Response::class, Model200Response.serializer()) - serializer.setMapper(Name::class, Name.serializer()) - serializer.setMapper(NullableClass::class, NullableClass.serializer()) - serializer.setMapper(NumberOnly::class, NumberOnly.serializer()) - serializer.setMapper(Order::class, Order.serializer()) - serializer.setMapper(OuterComposite::class, OuterComposite.serializer()) - serializer.setMapper(OuterEnum::class, OuterEnum.serializer()) - serializer.setMapper(OuterEnumDefaultValue::class, OuterEnumDefaultValue.serializer()) - serializer.setMapper(OuterEnumInteger::class, OuterEnumInteger.serializer()) - serializer.setMapper(OuterEnumIntegerDefaultValue::class, OuterEnumIntegerDefaultValue.serializer()) - serializer.setMapper(Pet::class, Pet.serializer()) - serializer.setMapper(ReadOnlyFirst::class, ReadOnlyFirst.serializer()) - serializer.setMapper(Return::class, Return.serializer()) - serializer.setMapper(SpecialModelname::class, SpecialModelname.serializer()) - serializer.setMapper(Tag::class, Tag.serializer()) - serializer.setMapper(User::class, User.serializer()) + serializer.setMapper(org.openapitools.client.models.AdditionalPropertiesClass::class, org.openapitools.client.models.AdditionalPropertiesClass.serializer()) + serializer.setMapper(org.openapitools.client.models.Animal::class, org.openapitools.client.models.Animal.serializer()) + serializer.setMapper(org.openapitools.client.models.ApiResponse::class, org.openapitools.client.models.ApiResponse.serializer()) + serializer.setMapper(org.openapitools.client.models.ArrayOfArrayOfNumberOnly::class, org.openapitools.client.models.ArrayOfArrayOfNumberOnly.serializer()) + serializer.setMapper(org.openapitools.client.models.ArrayOfNumberOnly::class, org.openapitools.client.models.ArrayOfNumberOnly.serializer()) + serializer.setMapper(org.openapitools.client.models.ArrayTest::class, org.openapitools.client.models.ArrayTest.serializer()) + serializer.setMapper(org.openapitools.client.models.Capitalization::class, org.openapitools.client.models.Capitalization.serializer()) + serializer.setMapper(org.openapitools.client.models.Cat::class, org.openapitools.client.models.Cat.serializer()) + serializer.setMapper(org.openapitools.client.models.CatAllOf::class, org.openapitools.client.models.CatAllOf.serializer()) + serializer.setMapper(org.openapitools.client.models.Category::class, org.openapitools.client.models.Category.serializer()) + serializer.setMapper(org.openapitools.client.models.ClassModel::class, org.openapitools.client.models.ClassModel.serializer()) + serializer.setMapper(org.openapitools.client.models.Client::class, org.openapitools.client.models.Client.serializer()) + serializer.setMapper(org.openapitools.client.models.Dog::class, org.openapitools.client.models.Dog.serializer()) + serializer.setMapper(org.openapitools.client.models.DogAllOf::class, org.openapitools.client.models.DogAllOf.serializer()) + serializer.setMapper(org.openapitools.client.models.EnumArrays::class, org.openapitools.client.models.EnumArrays.serializer()) + serializer.setMapper(org.openapitools.client.models.EnumClass::class, org.openapitools.client.models.EnumClass.Serializer) + serializer.setMapper(org.openapitools.client.models.EnumTest::class, org.openapitools.client.models.EnumTest.serializer()) + serializer.setMapper(org.openapitools.client.models.FileSchemaTestClass::class, org.openapitools.client.models.FileSchemaTestClass.serializer()) + serializer.setMapper(org.openapitools.client.models.Foo::class, org.openapitools.client.models.Foo.serializer()) + serializer.setMapper(org.openapitools.client.models.FormatTest::class, org.openapitools.client.models.FormatTest.serializer()) + serializer.setMapper(org.openapitools.client.models.HasOnlyReadOnly::class, org.openapitools.client.models.HasOnlyReadOnly.serializer()) + serializer.setMapper(org.openapitools.client.models.HealthCheckResult::class, org.openapitools.client.models.HealthCheckResult.serializer()) + serializer.setMapper(org.openapitools.client.models.InlineObject::class, org.openapitools.client.models.InlineObject.serializer()) + serializer.setMapper(org.openapitools.client.models.InlineObject1::class, org.openapitools.client.models.InlineObject1.serializer()) + serializer.setMapper(org.openapitools.client.models.InlineObject2::class, org.openapitools.client.models.InlineObject2.serializer()) + serializer.setMapper(org.openapitools.client.models.InlineObject3::class, org.openapitools.client.models.InlineObject3.serializer()) + serializer.setMapper(org.openapitools.client.models.InlineObject4::class, org.openapitools.client.models.InlineObject4.serializer()) + serializer.setMapper(org.openapitools.client.models.InlineObject5::class, org.openapitools.client.models.InlineObject5.serializer()) + serializer.setMapper(org.openapitools.client.models.InlineResponseDefault::class, org.openapitools.client.models.InlineResponseDefault.serializer()) + serializer.setMapper(org.openapitools.client.models.List::class, org.openapitools.client.models.List.serializer()) + serializer.setMapper(org.openapitools.client.models.MapTest::class, org.openapitools.client.models.MapTest.serializer()) + serializer.setMapper(org.openapitools.client.models.MixedPropertiesAndAdditionalPropertiesClass::class, org.openapitools.client.models.MixedPropertiesAndAdditionalPropertiesClass.serializer()) + serializer.setMapper(org.openapitools.client.models.Model200Response::class, org.openapitools.client.models.Model200Response.serializer()) + serializer.setMapper(org.openapitools.client.models.Name::class, org.openapitools.client.models.Name.serializer()) + serializer.setMapper(org.openapitools.client.models.NullableClass::class, org.openapitools.client.models.NullableClass.serializer()) + serializer.setMapper(org.openapitools.client.models.NumberOnly::class, org.openapitools.client.models.NumberOnly.serializer()) + serializer.setMapper(org.openapitools.client.models.Order::class, org.openapitools.client.models.Order.serializer()) + serializer.setMapper(org.openapitools.client.models.OuterComposite::class, org.openapitools.client.models.OuterComposite.serializer()) + serializer.setMapper(org.openapitools.client.models.OuterEnum::class, org.openapitools.client.models.OuterEnum.Serializer) + serializer.setMapper(org.openapitools.client.models.OuterEnumDefaultValue::class, org.openapitools.client.models.OuterEnumDefaultValue.Serializer) + serializer.setMapper(org.openapitools.client.models.OuterEnumInteger::class, org.openapitools.client.models.OuterEnumInteger.Serializer) + serializer.setMapper(org.openapitools.client.models.OuterEnumIntegerDefaultValue::class, org.openapitools.client.models.OuterEnumIntegerDefaultValue.Serializer) + serializer.setMapper(org.openapitools.client.models.Pet::class, org.openapitools.client.models.Pet.serializer()) + serializer.setMapper(org.openapitools.client.models.ReadOnlyFirst::class, org.openapitools.client.models.ReadOnlyFirst.serializer()) + serializer.setMapper(org.openapitools.client.models.Return::class, org.openapitools.client.models.Return.serializer()) + serializer.setMapper(org.openapitools.client.models.SpecialModelname::class, org.openapitools.client.models.SpecialModelname.serializer()) + serializer.setMapper(org.openapitools.client.models.Tag::class, org.openapitools.client.models.Tag.serializer()) + serializer.setMapper(org.openapitools.client.models.User::class, org.openapitools.client.models.User.serializer()) } } - protected suspend fun multipartFormRequest(requestConfig: RequestConfig, body: List?): HttpResponse { - return request(requestConfig, MultiPartFormDataContent(body ?: listOf())) + /** + * Set the username for the first HTTP basic authentication. + * + * @param username Username + */ + fun setUsername(username: String) { + val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth? + ?: throw Exception("No HTTP basic authentication configured") + auth.username = username } - protected suspend fun urlEncodedFormRequest(requestConfig: RequestConfig, body: Parameters?): HttpResponse { - return request(requestConfig, FormDataContent(body ?: Parameters.Empty)) + /** + * Set the password for the first HTTP basic authentication. + * + * @param password Password + */ + fun setPassword(password: String) { + val auth = authentications.values.firstOrNull { it is HttpBasicAuth } as HttpBasicAuth? + ?: throw Exception("No HTTP basic authentication configured") + auth.password = password } - protected suspend fun jsonRequest(requestConfig: RequestConfig, body: Any? = null): HttpResponse { + /** + * Set the API key value for the first API key authentication. + * + * @param apiKey API key + * @param paramName The name of the API key parameter, or null or set the first key. + */ + fun setApiKey(apiKey: String, paramName: String? = null) { + val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName)} as ApiKeyAuth? + ?: throw Exception("No API key authentication configured") + auth.apiKey = apiKey + } + + /** + * Set the API key prefix for the first API key authentication. + * + * @param apiKeyPrefix API key prefix + * @param paramName The name of the API key parameter, or null or set the first key. + */ + fun setApiKeyPrefix(apiKeyPrefix: String, paramName: String? = null) { + val auth = authentications.values.firstOrNull { it is ApiKeyAuth && (paramName == null || paramName == it.paramName) } as ApiKeyAuth? + ?: throw Exception("No API key authentication configured") + auth.apiKeyPrefix = apiKeyPrefix + } + + /** + * Set the access token for the first OAuth2 authentication. + * + * @param accessToken Access token + */ + fun setAccessToken(accessToken: String) { + val auth = authentications.values.firstOrNull { it is OAuth } as OAuth? + ?: throw Exception("No OAuth2 authentication configured") + auth.accessToken = accessToken + } + + /** + * Set the access token for the first Bearer authentication. + * + * @param bearerToken The bearer token. + */ + fun setBearerToken(bearerToken: String) { + val auth = authentications.values.firstOrNull { it is HttpBearerAuth } as HttpBearerAuth? + ?: throw Exception("No Bearer authentication configured") + auth.bearerToken = bearerToken + } + + protected suspend fun multipartFormRequest(requestConfig: RequestConfig, body: kotlin.collections.List?, authNames: kotlin.collections.List): HttpResponse { + return request(requestConfig, MultiPartFormDataContent(body ?: listOf()), authNames) + } + + protected suspend fun urlEncodedFormRequest(requestConfig: RequestConfig, body: Parameters?, authNames: kotlin.collections.List): HttpResponse { + return request(requestConfig, FormDataContent(body ?: Parameters.Empty), authNames) + } + + protected suspend fun jsonRequest(requestConfig: RequestConfig, body: Any? = null, authNames: kotlin.collections.List): HttpResponse { val contentType = (requestConfig.headers[HttpHeaders.ContentType]?.let { ContentType.parse(it) } ?: ContentType.Application.Json) - return if (body != null) request(requestConfig, serializer.write(body, contentType)) - else request(requestConfig) + return if (body != null) request(requestConfig, serializer.write(body, contentType), authNames) + else request(requestConfig, authNames = authNames) } - protected suspend fun request(requestConfig: RequestConfig, body: OutgoingContent = EmptyContent): HttpResponse { + protected suspend fun request(requestConfig: RequestConfig, body: OutgoingContent = EmptyContent, authNames: kotlin.collections.List): HttpResponse { + requestConfig.updateForAuth(authNames) val headers = requestConfig.headers return client.call { @@ -152,7 +231,14 @@ open class ApiClient( }.response } - private fun URLBuilder.appendPath(components: List): URLBuilder = apply { + private fun RequestConfig.updateForAuth(authNames: kotlin.collections.List) { + for (authName in authNames) { + val auth = authentications[authName] ?: throw Exception("Authentication undefined: $authName") + auth.apply(query, headers) + } + } + + private fun URLBuilder.appendPath(components: kotlin.collections.List): URLBuilder = apply { encodedPath = encodedPath.trimEnd('/') + components.joinToString("/", prefix = "/") { it.encodeURLQueryComponent() } } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt new file mode 100644 index 00000000000..4bc1197cf00 --- /dev/null +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt @@ -0,0 +1,29 @@ +package org.openapitools.client.infrastructure + +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor + +@Serializable +class Base64ByteArray(val value: ByteArray) { + @Serializer(Base64ByteArray::class) + companion object : KSerializer { + override val descriptor = StringDescriptor.withName("Base64ByteArray") + override fun serialize(encoder: Encoder, obj: Base64ByteArray) = encoder.encodeString(obj.value.encodeBase64()) + override fun deserialize(decoder: Decoder) = Base64ByteArray(decoder.decodeString().decodeBase64Bytes()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || this::class != other::class) return false + other as Base64ByteArray + return value.contentEquals(other.value) + } + + override fun hashCode(): Int { + return value.contentHashCode() + } + + override fun toString(): String { + return "Base64ByteArray(${hex(value)})" + } +} \ No newline at end of file diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Bytes.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Bytes.kt new file mode 100644 index 00000000000..8a222416cf2 --- /dev/null +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/Bytes.kt @@ -0,0 +1,102 @@ +package org.openapitools.client.infrastructure + +import kotlinx.io.core.* +import kotlin.experimental.and + +private val digits = "0123456789abcdef".toCharArray() +private const val BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" +private const val BASE64_MASK: Byte = 0x3f +private const val BASE64_PAD = '=' +private val BASE64_INVERSE_ALPHABET = IntArray(256) { BASE64_ALPHABET.indexOf(it.toChar()) } + +private fun String.toCharArray(): CharArray = CharArray(length) { get(it) } +private fun ByteArray.clearFrom(from: Int) = (from until size).forEach { this[it] = 0 } +private fun Int.toBase64(): Char = BASE64_ALPHABET[this] +private fun Byte.fromBase64(): Byte = BASE64_INVERSE_ALPHABET[toInt() and 0xff].toByte() and BASE64_MASK +internal fun ByteArray.encodeBase64(): String = buildPacket { writeFully(this@encodeBase64) }.encodeBase64() +internal fun String.decodeBase64Bytes(): ByteArray = buildPacket { writeStringUtf8(dropLastWhile { it == BASE64_PAD }) }.decodeBase64Bytes().readBytes() + +/** + * Encode [bytes] as a HEX string with no spaces, newlines and `0x` prefixes. + * + * Taken from https://github.com/ktorio/ktor/blob/master/ktor-utils/common/src/io/ktor/util/Crypto.kt + */ +internal fun hex(bytes: ByteArray): String { + val result = CharArray(bytes.size * 2) + var resultIndex = 0 + val digits = digits + + for (element in bytes) { + val b = element.toInt() and 0xff + result[resultIndex++] = digits[b shr 4] + result[resultIndex++] = digits[b and 0x0f] + } + + return String(result) +} + +/** + * Decode bytes from HEX string. It should be no spaces and `0x` prefixes. + * + * Taken from https://github.com/ktorio/ktor/blob/master/ktor-utils/common/src/io/ktor/util/Crypto.kt + */ +internal fun hex(s: String): ByteArray { + val result = ByteArray(s.length / 2) + for (idx in result.indices) { + val srcIdx = idx * 2 + val high = s[srcIdx].toString().toInt(16) shl 4 + val low = s[srcIdx + 1].toString().toInt(16) + result[idx] = (high or low).toByte() + } + + return result +} + +/** + * Encode [ByteReadPacket] in base64 format. + * + * Taken from https://github.com/ktorio/ktor/blob/424d1d2cfaa3281302c60af9500f738c8c2fc846/ktor-utils/common/src/io/ktor/util/Base64.kt + */ +private fun ByteReadPacket.encodeBase64(): String = buildString { + val data = ByteArray(3) + while (remaining > 0) { + val read = readAvailable(data) + data.clearFrom(read) + + val padSize = (data.size - read) * 8 / 6 + val chunk = ((data[0].toInt() and 0xFF) shl 16) or + ((data[1].toInt() and 0xFF) shl 8) or + (data[2].toInt() and 0xFF) + + for (index in data.size downTo padSize) { + val char = (chunk shr (6 * index)) and BASE64_MASK.toInt() + append(char.toBase64()) + } + + repeat(padSize) { append(BASE64_PAD) } + } +} + +/** + * Decode [ByteReadPacket] from base64 format + * + * Taken from https://github.com/ktorio/ktor/blob/424d1d2cfaa3281302c60af9500f738c8c2fc846/ktor-utils/common/src/io/ktor/util/Base64.kt + */ +private fun ByteReadPacket.decodeBase64Bytes(): Input = buildPacket { + val data = ByteArray(4) + + while (remaining > 0) { + val read = readAvailable(data) + + val chunk = data.foldIndexed(0) { index, result, current -> + result or (current.fromBase64().toInt() shl ((3 - index) * 6)) + } + + for (index in data.size - 2 downTo (data.size - read)) { + val origin = (chunk shr (8 * index)) and 0xff + writeByte(origin.toByte()) + } + } +} + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt new file mode 100644 index 00000000000..735e4e6e3f6 --- /dev/null +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt @@ -0,0 +1,29 @@ +package org.openapitools.client.infrastructure + +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor + +@Serializable +class OctetByteArray(val value: ByteArray) { + @Serializer(OctetByteArray::class) + companion object : KSerializer { + override val descriptor = StringDescriptor.withName("OctetByteArray") + override fun serialize(encoder: Encoder, obj: OctetByteArray) = encoder.encodeString(hex(obj.value)) + override fun deserialize(decoder: Decoder) = OctetByteArray(hex(decoder.decodeString())) + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || this::class != other::class) return false + other as OctetByteArray + return value.contentEquals(other.value) + } + + override fun hashCode(): Int { + return value.contentHashCode() + } + + override fun toString(): String { + return "OctetByteArray(${hex(value)})" + } +} \ No newline at end of file diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 53e689237d7..9c22257e223 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,5 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: Map> = mapOf() + val query: MutableMap> = mutableMapOf() ) \ No newline at end of file diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/AdditionalPropertiesClass.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/AdditionalPropertiesClass.kt index 5aaa7a106de..3ea85247a2f 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/AdditionalPropertiesClass.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/AdditionalPropertiesClass.kt @@ -21,7 +21,9 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class AdditionalPropertiesClass ( - @SerialName(value = "mapProperty") val mapProperty: kotlin.collections.Map? = null, - @SerialName(value = "mapOfMapProperty") val mapOfMapProperty: kotlin.collections.Map>? = null -) + @SerialName(value = "map_property") val mapProperty: kotlin.collections.Map? = null, + @SerialName(value = "map_of_map_property") val mapOfMapProperty: kotlin.collections.Map>? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Animal.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Animal.kt index 5e9cd111633..a4a0aedb9da 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Animal.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Animal.kt @@ -23,5 +23,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer data class Animal ( @SerialName(value = "className") @Required val className: kotlin.String, @SerialName(value = "color") val color: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ApiResponse.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ApiResponse.kt index 805244a3762..eadb9198bd6 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ApiResponse.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ApiResponse.kt @@ -25,5 +25,7 @@ data class ApiResponse ( @SerialName(value = "code") val code: kotlin.Int? = null, @SerialName(value = "type") val type: kotlin.String? = null, @SerialName(value = "message") val message: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayOfArrayOfNumberOnly.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayOfArrayOfNumberOnly.kt index df7774515f4..af74669d896 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayOfArrayOfNumberOnly.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayOfArrayOfNumberOnly.kt @@ -20,6 +20,8 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class ArrayOfArrayOfNumberOnly ( - @SerialName(value = "arrayArrayNumber") val arrayArrayNumber: kotlin.Array>? = null -) + @SerialName(value = "ArrayArrayNumber") val arrayArrayNumber: kotlin.Array>? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayOfNumberOnly.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayOfNumberOnly.kt index 36f32d28a2c..d495abee8ef 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayOfNumberOnly.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayOfNumberOnly.kt @@ -20,6 +20,8 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class ArrayOfNumberOnly ( - @SerialName(value = "arrayNumber") val arrayNumber: kotlin.Array? = null -) + @SerialName(value = "ArrayNumber") val arrayNumber: kotlin.Array? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayTest.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayTest.kt index 6c142356cc7..cc1e251cbbf 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayTest.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ArrayTest.kt @@ -23,8 +23,10 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class ArrayTest ( - @SerialName(value = "arrayOfString") val arrayOfString: kotlin.Array? = null, - @SerialName(value = "arrayArrayOfInteger") val arrayArrayOfInteger: kotlin.Array>? = null, - @SerialName(value = "arrayArrayOfModel") val arrayArrayOfModel: kotlin.Array>? = null -) + @SerialName(value = "array_of_string") val arrayOfString: kotlin.Array? = null, + @SerialName(value = "array_array_of_integer") val arrayArrayOfInteger: kotlin.Array>? = null, + @SerialName(value = "array_array_of_model") val arrayArrayOfModel: kotlin.Array>? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Capitalization.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Capitalization.kt index 2f28e4dcabb..be08fe9356b 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Capitalization.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Capitalization.kt @@ -26,11 +26,13 @@ import kotlinx.serialization.internal.CommonEnumSerializer @Serializable data class Capitalization ( @SerialName(value = "smallCamel") val smallCamel: kotlin.String? = null, - @SerialName(value = "capitalCamel") val capitalCamel: kotlin.String? = null, - @SerialName(value = "smallSnake") val smallSnake: kotlin.String? = null, - @SerialName(value = "capitalSnake") val capitalSnake: kotlin.String? = null, - @SerialName(value = "scAETHFlowPoints") val scAETHFlowPoints: kotlin.String? = null, + @SerialName(value = "CapitalCamel") val capitalCamel: kotlin.String? = null, + @SerialName(value = "small_Snake") val smallSnake: kotlin.String? = null, + @SerialName(value = "Capital_Snake") val capitalSnake: kotlin.String? = null, + @SerialName(value = "SCA_ETH_Flow_Points") val scAETHFlowPoints: kotlin.String? = null, /* Name of the pet */ @SerialName(value = "ATT_NAME") val ATT_NAME: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Cat.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Cat.kt index 99b024d1ce1..d4934706822 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Cat.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Cat.kt @@ -25,5 +25,7 @@ data class Cat ( @SerialName(value = "className") @Required val className: kotlin.String, @SerialName(value = "declawed") val declawed: kotlin.Boolean? = null, @SerialName(value = "color") val color: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/CatAllOf.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/CatAllOf.kt index d7a72badbcd..daa6ccbd65b 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/CatAllOf.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/CatAllOf.kt @@ -21,5 +21,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer @Serializable data class CatAllOf ( @SerialName(value = "declawed") val declawed: kotlin.Boolean? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Category.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Category.kt index da08e8cca65..c260a3d2cf1 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Category.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Category.kt @@ -23,5 +23,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer data class Category ( @SerialName(value = "name") @Required val name: kotlin.String, @SerialName(value = "id") val id: kotlin.Long? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ClassModel.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ClassModel.kt index dff4f30ec63..5944f0f4f0f 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ClassModel.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ClassModel.kt @@ -20,6 +20,8 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class ClassModel ( - @SerialName(value = "propertyClass") val propertyClass: kotlin.String? = null -) + @SerialName(value = "_class") val propertyClass: kotlin.String? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Client.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Client.kt index 30d316bd706..a7e37fa2d36 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Client.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Client.kt @@ -21,5 +21,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer @Serializable data class Client ( @SerialName(value = "client") val client: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Dog.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Dog.kt index e7e905cf434..c9dada25891 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Dog.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Dog.kt @@ -25,5 +25,7 @@ data class Dog ( @SerialName(value = "className") @Required val className: kotlin.String, @SerialName(value = "breed") val breed: kotlin.String? = null, @SerialName(value = "color") val color: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/DogAllOf.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/DogAllOf.kt index 6e18a5729e2..335066a664c 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/DogAllOf.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/DogAllOf.kt @@ -21,5 +21,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer @Serializable data class DogAllOf ( @SerialName(value = "breed") val breed: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumArrays.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumArrays.kt index b3e8f49905f..24712541204 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumArrays.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumArrays.kt @@ -21,40 +21,33 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class EnumArrays ( - @SerialName(value = "justSymbol") val justSymbol: EnumArrays.JustSymbol? = null, - @SerialName(value = "arrayEnum") val arrayEnum: kotlin.Array? = null -) -{ + @SerialName(value = "just_symbol") val justSymbol: EnumArrays.JustSymbol? = null, + @SerialName(value = "array_enum") val arrayEnum: kotlin.Array? = null +) + +{ /** * * Values: greaterThanEqual,dollar */ @Serializable(with = JustSymbol.Serializer::class) enum class JustSymbol(val value: kotlin.String){ - greaterThanEqual(">="), - dollar("$"); - - object Serializer : CommonEnumSerializer("JustSymbol", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("JustSymbol", values(), values().map { it.value.toString() }.toTypedArray()) } - /** * * Values: fish,crab */ @Serializable(with = ArrayEnum.Serializer::class) enum class ArrayEnum(val value: kotlin.String){ - fish("fish"), - crab("crab"); - - object Serializer : CommonEnumSerializer("ArrayEnum", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("ArrayEnum", values(), values().map { it.value.toString() }.toTypedArray()) } - } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumClass.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumClass.kt index ad529883550..5028c4e1656 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumClass.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumClass.kt @@ -33,6 +33,6 @@ enum class EnumClass(val value: kotlin.String){ - object Serializer : CommonEnumSerializer("EnumClass", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("EnumClass", values(), values().map { it.value.toString() }.toTypedArray()) } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumTest.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumTest.kt index 9490d63cafc..e8118469105 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumTest.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/EnumTest.kt @@ -31,80 +31,63 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class EnumTest ( - @SerialName(value = "enumStringRequired") @Required val enumStringRequired: EnumTest.EnumStringRequired, - @SerialName(value = "enumString") val enumString: EnumTest.EnumString? = null, - @SerialName(value = "enumInteger") val enumInteger: EnumTest.EnumInteger? = null, - @SerialName(value = "enumNumber") val enumNumber: EnumTest.EnumNumber? = null, + @SerialName(value = "enum_string_required") @Required val enumStringRequired: EnumTest.EnumStringRequired, + @SerialName(value = "enum_string") val enumString: EnumTest.EnumString? = null, + @SerialName(value = "enum_integer") val enumInteger: EnumTest.EnumInteger? = null, + @SerialName(value = "enum_number") val enumNumber: EnumTest.EnumNumber? = null, @SerialName(value = "outerEnum") val outerEnum: OuterEnum? = null, @SerialName(value = "outerEnumInteger") val outerEnumInteger: OuterEnumInteger? = null, @SerialName(value = "outerEnumDefaultValue") val outerEnumDefaultValue: OuterEnumDefaultValue? = null, @SerialName(value = "outerEnumIntegerDefaultValue") val outerEnumIntegerDefaultValue: OuterEnumIntegerDefaultValue? = null -) -{ +) + +{ /** * * Values: uPPER,lower,eMPTY */ @Serializable(with = EnumString.Serializer::class) enum class EnumString(val value: kotlin.String){ - uPPER("UPPER"), - lower("lower"), - eMPTY(""); - - object Serializer : CommonEnumSerializer("EnumString", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("EnumString", values(), values().map { it.value.toString() }.toTypedArray()) } - /** * * Values: uPPER,lower,eMPTY */ @Serializable(with = EnumStringRequired.Serializer::class) enum class EnumStringRequired(val value: kotlin.String){ - uPPER("UPPER"), - lower("lower"), - eMPTY(""); - - object Serializer : CommonEnumSerializer("EnumStringRequired", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("EnumStringRequired", values(), values().map { it.value.toString() }.toTypedArray()) } - /** * * Values: _1,minus1 */ @Serializable(with = EnumInteger.Serializer::class) enum class EnumInteger(val value: kotlin.Int){ - _1(1), - minus1(-1); - - object Serializer : CommonEnumSerializer("EnumInteger", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("EnumInteger", values(), values().map { it.value.toString() }.toTypedArray()) } - /** * * Values: _1period1,minus1Period2 */ @Serializable(with = EnumNumber.Serializer::class) enum class EnumNumber(val value: kotlin.Double){ - _1period1(1.1), - minus1Period2(-1.2); - - object Serializer : CommonEnumSerializer("EnumNumber", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("EnumNumber", values(), values().map { it.value.toString() }.toTypedArray()) } - } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/FileSchemaTestClass.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/FileSchemaTestClass.kt index 3ec73e7f41b..f33eeffe62e 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/FileSchemaTestClass.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/FileSchemaTestClass.kt @@ -21,7 +21,9 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class FileSchemaTestClass ( - @SerialName(value = "file") val file: io.ktor.client.request.forms.InputProvider? = null, - @SerialName(value = "files") val files: kotlin.Array? = null -) + @SerialName(value = "file") val file: org.openapitools.client.infrastructure.OctetByteArray? = null, + @SerialName(value = "files") val files: kotlin.Array? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Foo.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Foo.kt index f208e3add1d..16666d74e54 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Foo.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Foo.kt @@ -21,5 +21,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer @Serializable data class Foo ( @SerialName(value = "bar") val bar: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/FormatTest.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/FormatTest.kt index 8f1d98714aa..728b0d485a7 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/FormatTest.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/FormatTest.kt @@ -35,7 +35,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer @Serializable data class FormatTest ( @SerialName(value = "number") @Required val number: kotlin.Double, - @SerialName(value = "byte") @Required val byte: kotlin.ByteArray, + @SerialName(value = "byte") @Required val byte: org.openapitools.client.infrastructure.Base64ByteArray, @SerialName(value = "date") @Required val date: kotlin.String, @SerialName(value = "password") @Required val password: kotlin.String, @SerialName(value = "integer") val integer: kotlin.Int? = null, @@ -44,12 +44,14 @@ data class FormatTest ( @SerialName(value = "float") val float: kotlin.Float? = null, @SerialName(value = "double") val double: kotlin.Double? = null, @SerialName(value = "string") val string: kotlin.String? = null, - @SerialName(value = "binary") val binary: io.ktor.client.request.forms.InputProvider? = null, + @SerialName(value = "binary") val binary: org.openapitools.client.infrastructure.OctetByteArray? = null, @SerialName(value = "dateTime") val dateTime: kotlin.String? = null, @SerialName(value = "uuid") val uuid: kotlin.String? = null, /* A string that is a 10 digit number. Can have leading zeros. */ - @SerialName(value = "patternWithDigits") val patternWithDigits: kotlin.String? = null, + @SerialName(value = "pattern_with_digits") val patternWithDigits: kotlin.String? = null, /* A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. */ - @SerialName(value = "patternWithDigitsAndDelimiter") val patternWithDigitsAndDelimiter: kotlin.String? = null -) + @SerialName(value = "pattern_with_digits_and_delimiter") val patternWithDigitsAndDelimiter: kotlin.String? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/HasOnlyReadOnly.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/HasOnlyReadOnly.kt index 617c8a98b84..42e50350bbe 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/HasOnlyReadOnly.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/HasOnlyReadOnly.kt @@ -23,5 +23,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer data class HasOnlyReadOnly ( @SerialName(value = "bar") val bar: kotlin.String? = null, @SerialName(value = "foo") val foo: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/HealthCheckResult.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/HealthCheckResult.kt index 9b9298c87a3..25c1eb1a2a0 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/HealthCheckResult.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/HealthCheckResult.kt @@ -20,6 +20,8 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class HealthCheckResult ( - @SerialName(value = "nullableMessage") val nullableMessage: kotlin.String? = null -) + @SerialName(value = "NullableMessage") val nullableMessage: kotlin.String? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject.kt index 787f859549f..f16618c66fb 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject.kt @@ -25,5 +25,7 @@ data class InlineObject ( @SerialName(value = "name") val name: kotlin.String? = null, /* Updated status of the pet */ @SerialName(value = "status") val status: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject1.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject1.kt index b56396d37e5..8a8f4b48eb6 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject1.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject1.kt @@ -24,6 +24,8 @@ data class InlineObject1 ( /* Additional data to pass to server */ @SerialName(value = "additionalMetadata") val additionalMetadata: kotlin.String? = null, /* file to upload */ - @SerialName(value = "file") val file: io.ktor.client.request.forms.InputProvider? = null -) + @SerialName(value = "file") val file: org.openapitools.client.infrastructure.OctetByteArray? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject2.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject2.kt index 887c7456ee5..b43c611730f 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject2.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject2.kt @@ -22,43 +22,35 @@ import kotlinx.serialization.internal.CommonEnumSerializer @Serializable data class InlineObject2 ( /* Form parameter enum test (string array) */ - @SerialName(value = "enumFormStringArray") val enumFormStringArray: kotlin.Array? = null, + @SerialName(value = "enum_form_string_array") val enumFormStringArray: kotlin.Array? = null, /* Form parameter enum test (string) */ - @SerialName(value = "enumFormString") val enumFormString: InlineObject2.EnumFormString? = null -) -{ + @SerialName(value = "enum_form_string") val enumFormString: InlineObject2.EnumFormString? = null +) + +{ /** * Form parameter enum test (string array) * Values: greaterThan,dollar */ @Serializable(with = EnumFormStringArray.Serializer::class) enum class EnumFormStringArray(val value: kotlin.String){ - greaterThan(">"), - dollar("$"); - - object Serializer : CommonEnumSerializer("EnumFormStringArray", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("EnumFormStringArray", values(), values().map { it.value.toString() }.toTypedArray()) } - /** * Form parameter enum test (string) * Values: abc,minusEfg,leftParenthesisXyzRightParenthesis */ @Serializable(with = EnumFormString.Serializer::class) enum class EnumFormString(val value: kotlin.String){ - abc("_abc"), - minusEfg("-efg"), - leftParenthesisXyzRightParenthesis("(xyz)"); - - object Serializer : CommonEnumSerializer("EnumFormString", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("EnumFormString", values(), values().map { it.value.toString() }.toTypedArray()) } - } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject3.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject3.kt index a67b8dc50c0..a85b872c57e 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject3.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject3.kt @@ -38,9 +38,9 @@ data class InlineObject3 ( /* None */ @SerialName(value = "double") @Required val double: kotlin.Double, /* None */ - @SerialName(value = "patternWithoutDelimiter") @Required val patternWithoutDelimiter: kotlin.String, + @SerialName(value = "pattern_without_delimiter") @Required val patternWithoutDelimiter: kotlin.String, /* None */ - @SerialName(value = "byte") @Required val byte: kotlin.ByteArray, + @SerialName(value = "byte") @Required val byte: org.openapitools.client.infrastructure.Base64ByteArray, /* None */ @SerialName(value = "integer") val integer: kotlin.Int? = null, /* None */ @@ -52,7 +52,7 @@ data class InlineObject3 ( /* None */ @SerialName(value = "string") val string: kotlin.String? = null, /* None */ - @SerialName(value = "binary") val binary: io.ktor.client.request.forms.InputProvider? = null, + @SerialName(value = "binary") val binary: org.openapitools.client.infrastructure.OctetByteArray? = null, /* None */ @SerialName(value = "date") val date: kotlin.String? = null, /* None */ @@ -61,5 +61,7 @@ data class InlineObject3 ( @SerialName(value = "password") val password: kotlin.String? = null, /* None */ @SerialName(value = "callback") val callback: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject4.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject4.kt index 4a1f2f2ecc5..cd4cb2cd700 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject4.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject4.kt @@ -25,5 +25,7 @@ data class InlineObject4 ( @SerialName(value = "param") @Required val param: kotlin.String, /* field2 */ @SerialName(value = "param2") @Required val param2: kotlin.String -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject5.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject5.kt index 238d357f26a..39d77eeb570 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject5.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineObject5.kt @@ -22,8 +22,10 @@ import kotlinx.serialization.internal.CommonEnumSerializer @Serializable data class InlineObject5 ( /* file to upload */ - @SerialName(value = "requiredFile") @Required val requiredFile: io.ktor.client.request.forms.InputProvider, + @SerialName(value = "requiredFile") @Required val requiredFile: org.openapitools.client.infrastructure.OctetByteArray, /* Additional data to pass to server */ @SerialName(value = "additionalMetadata") val additionalMetadata: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineResponseDefault.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineResponseDefault.kt index 42564057946..8bcddc6c1b7 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineResponseDefault.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/InlineResponseDefault.kt @@ -22,5 +22,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer @Serializable data class InlineResponseDefault ( @SerialName(value = "string") val string: Foo? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/List.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/List.kt index 915b5d25acb..3b63af8f2a4 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/List.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/List.kt @@ -16,10 +16,12 @@ import kotlinx.serialization.* import kotlinx.serialization.internal.CommonEnumSerializer /** * - * @param ``123minusList`` + * @param `123minusList` */ @Serializable data class List ( - @SerialName(value = "`123minusList`") val ``123minusList``: kotlin.String? = null -) + @SerialName(value = "123-list") val `123minusList`: kotlin.String? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/MapTest.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/MapTest.kt index f66127a71db..e376dc68237 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/MapTest.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/MapTest.kt @@ -23,27 +23,24 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class MapTest ( - @SerialName(value = "mapMapOfString") val mapMapOfString: kotlin.collections.Map>? = null, - @SerialName(value = "mapOfEnumString") val mapOfEnumString: MapTest.MapOfEnumString? = null, - @SerialName(value = "directMap") val directMap: kotlin.collections.Map? = null, - @SerialName(value = "indirectMap") val indirectMap: kotlin.collections.Map? = null -) -{ + @SerialName(value = "map_map_of_string") val mapMapOfString: kotlin.collections.Map>? = null, + @SerialName(value = "map_of_enum_string") val mapOfEnumString: MapTest.MapOfEnumString? = null, + @SerialName(value = "direct_map") val directMap: kotlin.collections.Map? = null, + @SerialName(value = "indirect_map") val indirectMap: kotlin.collections.Map? = null +) + +{ /** * * Values: uPPER,lower */ @Serializable(with = MapOfEnumString.Serializer::class) enum class MapOfEnumString(val value: kotlin.collections.Map){ - uPPER("UPPER"), - lower("lower"); - - object Serializer : CommonEnumSerializer("MapOfEnumString", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("MapOfEnumString", values(), values().map { it.value.toString() }.toTypedArray()) } - } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/MixedPropertiesAndAdditionalPropertiesClass.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/MixedPropertiesAndAdditionalPropertiesClass.kt index 73b632b52a6..20923138ee2 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/MixedPropertiesAndAdditionalPropertiesClass.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/MixedPropertiesAndAdditionalPropertiesClass.kt @@ -26,5 +26,7 @@ data class MixedPropertiesAndAdditionalPropertiesClass ( @SerialName(value = "uuid") val uuid: kotlin.String? = null, @SerialName(value = "dateTime") val dateTime: kotlin.String? = null, @SerialName(value = "map") val map: kotlin.collections.Map? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Model200Response.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Model200Response.kt index 235b9ddfa15..2090e911b9c 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Model200Response.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Model200Response.kt @@ -22,6 +22,8 @@ import kotlinx.serialization.internal.CommonEnumSerializer @Serializable data class Model200Response ( @SerialName(value = "name") val name: kotlin.Int? = null, - @SerialName(value = "propertyClass") val propertyClass: kotlin.String? = null -) + @SerialName(value = "class") val propertyClass: kotlin.String? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Name.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Name.kt index ff47fb3d80b..3a720f71d4e 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Name.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Name.kt @@ -19,13 +19,15 @@ import kotlinx.serialization.internal.CommonEnumSerializer * @param name * @param snakeCase * @param property - * @param ``123number`` + * @param `123number` */ @Serializable data class Name ( @SerialName(value = "name") @Required val name: kotlin.Int, - @SerialName(value = "snakeCase") val snakeCase: kotlin.Int? = null, + @SerialName(value = "snake_case") val snakeCase: kotlin.Int? = null, @SerialName(value = "property") val property: kotlin.String? = null, - @SerialName(value = "`123number`") val ``123number``: kotlin.Int? = null -) + @SerialName(value = "123Number") val `123number`: kotlin.Int? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/NullableClass.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/NullableClass.kt index 35c112aad32..a325662a355 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/NullableClass.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/NullableClass.kt @@ -31,17 +31,19 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class NullableClass ( - @SerialName(value = "integerProp") val integerProp: kotlin.Int? = null, - @SerialName(value = "numberProp") val numberProp: kotlin.Double? = null, - @SerialName(value = "booleanProp") val booleanProp: kotlin.Boolean? = null, - @SerialName(value = "stringProp") val stringProp: kotlin.String? = null, - @SerialName(value = "dateProp") val dateProp: kotlin.String? = null, - @SerialName(value = "datetimeProp") val datetimeProp: kotlin.String? = null, - @SerialName(value = "arrayNullableProp") val arrayNullableProp: kotlin.Array? = null, - @SerialName(value = "arrayAndItemsNullableProp") val arrayAndItemsNullableProp: kotlin.Array? = null, - @SerialName(value = "arrayItemsNullable") val arrayItemsNullable: kotlin.Array? = null, - @SerialName(value = "objectNullableProp") val objectNullableProp: kotlin.collections.Map? = null, - @SerialName(value = "objectAndItemsNullableProp") val objectAndItemsNullableProp: kotlin.collections.Map? = null, - @SerialName(value = "objectItemsNullable") val objectItemsNullable: kotlin.collections.Map? = null -) + @SerialName(value = "integer_prop") val integerProp: kotlin.Int? = null, + @SerialName(value = "number_prop") val numberProp: kotlin.Double? = null, + @SerialName(value = "boolean_prop") val booleanProp: kotlin.Boolean? = null, + @SerialName(value = "string_prop") val stringProp: kotlin.String? = null, + @SerialName(value = "date_prop") val dateProp: kotlin.String? = null, + @SerialName(value = "datetime_prop") val datetimeProp: kotlin.String? = null, + @SerialName(value = "array_nullable_prop") val arrayNullableProp: kotlin.Array? = null, + @SerialName(value = "array_and_items_nullable_prop") val arrayAndItemsNullableProp: kotlin.Array? = null, + @SerialName(value = "array_items_nullable") val arrayItemsNullable: kotlin.Array? = null, + @SerialName(value = "object_nullable_prop") val objectNullableProp: kotlin.collections.Map? = null, + @SerialName(value = "object_and_items_nullable_prop") val objectAndItemsNullableProp: kotlin.collections.Map? = null, + @SerialName(value = "object_items_nullable") val objectItemsNullable: kotlin.collections.Map? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/NumberOnly.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/NumberOnly.kt index 2fea0a41fae..b8a3f824f9e 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/NumberOnly.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/NumberOnly.kt @@ -20,6 +20,8 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class NumberOnly ( - @SerialName(value = "justNumber") val justNumber: kotlin.Double? = null -) + @SerialName(value = "JustNumber") val justNumber: kotlin.Double? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt index 77175821789..daf7ab61d12 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Order.kt @@ -32,25 +32,21 @@ data class Order ( /* Order Status */ @SerialName(value = "status") val status: Order.Status? = null, @SerialName(value = "complete") val complete: kotlin.Boolean? = null -) -{ +) + +{ /** * Order Status * Values: placed,approved,delivered */ @Serializable(with = Status.Serializer::class) enum class Status(val value: kotlin.String){ - placed("placed"), - approved("approved"), - delivered("delivered"); - - object Serializer : CommonEnumSerializer("Status", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("Status", values(), values().map { it.value.toString() }.toTypedArray()) } - } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterComposite.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterComposite.kt index ddd95c1837c..5eb2ff16e16 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterComposite.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterComposite.kt @@ -22,8 +22,10 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class OuterComposite ( - @SerialName(value = "myNumber") val myNumber: kotlin.Double? = null, - @SerialName(value = "myString") val myString: kotlin.String? = null, - @SerialName(value = "myBoolean") val myBoolean: kotlin.Boolean? = null -) + @SerialName(value = "my_number") val myNumber: kotlin.Double? = null, + @SerialName(value = "my_string") val myString: kotlin.String? = null, + @SerialName(value = "my_boolean") val myBoolean: kotlin.Boolean? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnum.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnum.kt index 51e77cc5ac6..7d03994603a 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnum.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnum.kt @@ -33,6 +33,6 @@ enum class OuterEnum(val value: kotlin.String){ - object Serializer : CommonEnumSerializer("OuterEnum", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("OuterEnum", values(), values().map { it.value.toString() }.toTypedArray()) } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumDefaultValue.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumDefaultValue.kt index 0380a542738..e819231a373 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumDefaultValue.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumDefaultValue.kt @@ -33,6 +33,6 @@ enum class OuterEnumDefaultValue(val value: kotlin.String){ - object Serializer : CommonEnumSerializer("OuterEnumDefaultValue", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("OuterEnumDefaultValue", values(), values().map { it.value.toString() }.toTypedArray()) } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumInteger.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumInteger.kt index 70389422113..0f73f3da8c4 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumInteger.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumInteger.kt @@ -33,6 +33,6 @@ enum class OuterEnumInteger(val value: kotlin.Int){ - object Serializer : CommonEnumSerializer("OuterEnumInteger", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("OuterEnumInteger", values(), values().map { it.value.toString() }.toTypedArray()) } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumIntegerDefaultValue.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumIntegerDefaultValue.kt index d80ab91475a..497d8f1b12c 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumIntegerDefaultValue.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/OuterEnumIntegerDefaultValue.kt @@ -33,6 +33,6 @@ enum class OuterEnumIntegerDefaultValue(val value: kotlin.Int){ - object Serializer : CommonEnumSerializer("OuterEnumIntegerDefaultValue", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("OuterEnumIntegerDefaultValue", values(), values().map { it.value.toString() }.toTypedArray()) } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt index 5dc530bb7c4..bca3e142602 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Pet.kt @@ -34,25 +34,21 @@ data class Pet ( @SerialName(value = "tags") val tags: kotlin.Array? = null, /* pet status in the store */ @SerialName(value = "status") val status: Pet.Status? = null -) -{ +) + +{ /** * pet status in the store * Values: available,pending,sold */ @Serializable(with = Status.Serializer::class) enum class Status(val value: kotlin.String){ - available("available"), - pending("pending"), - sold("sold"); - - object Serializer : CommonEnumSerializer("Status", values(), values().map { it.value }.toTypedArray()) + object Serializer : CommonEnumSerializer("Status", values(), values().map { it.value.toString() }.toTypedArray()) } - } diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ReadOnlyFirst.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ReadOnlyFirst.kt index 4d99ea7a9a2..77e15e87cf7 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ReadOnlyFirst.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/ReadOnlyFirst.kt @@ -23,5 +23,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer data class ReadOnlyFirst ( @SerialName(value = "bar") val bar: kotlin.String? = null, @SerialName(value = "baz") val baz: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Return.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Return.kt index f1b7a03573c..a6f2bf313c9 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Return.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Return.kt @@ -16,10 +16,12 @@ import kotlinx.serialization.* import kotlinx.serialization.internal.CommonEnumSerializer /** * Model for testing reserved words - * @param ``return`` + * @param `return` */ @Serializable data class Return ( - @SerialName(value = "`return`") val ``return``: kotlin.Int? = null -) + @SerialName(value = "return") val `return`: kotlin.Int? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/SpecialModelname.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/SpecialModelname.kt index 185cc542abf..eb395fbe570 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/SpecialModelname.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/SpecialModelname.kt @@ -20,6 +20,8 @@ import kotlinx.serialization.internal.CommonEnumSerializer */ @Serializable data class SpecialModelname ( - @SerialName(value = "dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket") val dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket: kotlin.Long? = null -) + @SerialName(value = "\$special[property.name]") val dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket: kotlin.Long? = null +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Tag.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Tag.kt index 0b3f202ad51..d0b206966f1 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Tag.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/Tag.kt @@ -23,5 +23,7 @@ import kotlinx.serialization.internal.CommonEnumSerializer data class Tag ( @SerialName(value = "id") val id: kotlin.Long? = null, @SerialName(value = "name") val name: kotlin.String? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/User.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/User.kt index 47ad0a9f282..71d86c975ff 100644 --- a/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/User.kt +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client/models/User.kt @@ -36,5 +36,7 @@ data class User ( @SerialName(value = "phone") val phone: kotlin.String? = null, /* User Status */ @SerialName(value = "userStatus") val userStatus: kotlin.Int? = null -) +) + + diff --git a/samples/openapi3/client/petstore/kotlin-multiplatform/src/jsTest/kotlin/util/Coroutine.kt b/samples/openapi3/client/petstore/kotlin-multiplatform/src/jsTest/kotlin/util/Coroutine.kt new file mode 100644 index 00000000000..2bea4861f67 --- /dev/null +++ b/samples/openapi3/client/petstore/kotlin-multiplatform/src/jsTest/kotlin/util/Coroutine.kt @@ -0,0 +1,7 @@ +package util + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.promise + +actual fun runTest(block: suspend (scope : CoroutineScope) -> T): dynamic = GlobalScope.promise { block(this) } \ No newline at end of file diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/AnotherFakeApi.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/AnotherFakeApi.kt index ae9aed9232a..d72e5dbdab0 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/AnotherFakeApi.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/AnotherFakeApi.kt @@ -36,7 +36,7 @@ class AnotherFakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2 @Suppress("UNCHECKED_CAST") fun call123testSpecialTags(client: Client) : Client { val localVariableBody: kotlin.Any? = client - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PATCH, diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 457573efef8..6715f892def 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -35,7 +35,7 @@ class DefaultApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : @Suppress("UNCHECKED_CAST") fun fooGet() : InlineResponseDefault { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt index 49c4f77616f..55e337e9ac9 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt @@ -39,7 +39,7 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap @Suppress("UNCHECKED_CAST") fun fakeHealthGet() : HealthCheckResult { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -70,7 +70,7 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap @Suppress("UNCHECKED_CAST") fun fakeOuterBooleanSerialize(body: kotlin.Boolean?) : kotlin.Boolean { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -101,7 +101,7 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap @Suppress("UNCHECKED_CAST") fun fakeOuterCompositeSerialize(outerComposite: OuterComposite?) : OuterComposite { val localVariableBody: kotlin.Any? = outerComposite - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -132,7 +132,7 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap @Suppress("UNCHECKED_CAST") fun fakeOuterNumberSerialize(body: java.math.BigDecimal?) : java.math.BigDecimal { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -163,7 +163,7 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap @Suppress("UNCHECKED_CAST") fun fakeOuterStringSerialize(body: kotlin.String?) : kotlin.String { val localVariableBody: kotlin.Any? = body - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -193,7 +193,7 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun testBodyWithFileSchema(fileSchemaTestClass: FileSchemaTestClass) : Unit { val localVariableBody: kotlin.Any? = fileSchemaTestClass - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -224,7 +224,10 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun testBodyWithQueryParams(query: kotlin.String, user: User) : Unit { val localVariableBody: kotlin.Any? = user - val localVariableQuery: MultiValueMap = mapOf("query" to listOf("$query")) + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("query", listOf(query.toString())) + } val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -255,7 +258,7 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap @Suppress("UNCHECKED_CAST") fun testClientModel(client: Client) : Client { val localVariableBody: kotlin.Any? = client - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PATCH, @@ -298,7 +301,7 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun testEndpointParameters(number: java.math.BigDecimal, double: kotlin.Double, patternWithoutDelimiter: kotlin.String, byte: kotlin.ByteArray, integer: kotlin.Int?, int32: kotlin.Int?, int64: kotlin.Long?, float: kotlin.Float?, string: kotlin.String?, binary: java.io.File?, date: java.time.LocalDate?, dateTime: java.time.LocalDateTime?, password: kotlin.String?, paramCallback: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = mapOf("integer" to "$integer", "int32" to "$int32", "int64" to "$int64", "number" to "$number", "float" to "$float", "double" to "$double", "string" to "$string", "pattern_without_delimiter" to "$patternWithoutDelimiter", "byte" to "$byte", "binary" to "$binary", "date" to "$date", "dateTime" to "$dateTime", "password" to "$password", "callback" to "$paramCallback") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -335,7 +338,21 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun testEnumParameters(enumHeaderStringArray: kotlin.Array?, enumHeaderString: kotlin.String?, enumQueryStringArray: kotlin.Array?, enumQueryString: kotlin.String?, enumQueryInteger: kotlin.Int?, enumQueryDouble: kotlin.Double?, enumFormStringArray: kotlin.Array?, enumFormString: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = mapOf("enum_form_string_array" to "$enumFormStringArray", "enum_form_string" to "$enumFormString") - val localVariableQuery: MultiValueMap = mapOf("enumQueryStringArray" to toMultiValue(enumQueryStringArray.toList(), "multi"), "enumQueryString" to listOf("$enumQueryString"), "enumQueryInteger" to listOf("$enumQueryInteger"), "enumQueryDouble" to listOf("$enumQueryDouble")) + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + if (enumQueryStringArray != null) { + put("enumQueryStringArray", toMultiValue(enumQueryStringArray.toList(), "multi")) + } + if (enumQueryString != null) { + put("enumQueryString", listOf(enumQueryString.toString())) + } + if (enumQueryInteger != null) { + put("enumQueryInteger", listOf(enumQueryInteger.toString())) + } + if (enumQueryDouble != null) { + put("enumQueryDouble", listOf(enumQueryDouble.toString())) + } + } val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "", "enum_header_string_array" to enumHeaderStringArray.joinToString(separator = collectionDelimiter("csv")), "enum_header_string" to enumHeaderString.toString()) val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -370,7 +387,17 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun testGroupParameters(requiredStringGroup: kotlin.Int, requiredBooleanGroup: kotlin.Boolean, requiredInt64Group: kotlin.Long, stringGroup: kotlin.Int?, booleanGroup: kotlin.Boolean?, int64Group: kotlin.Long?) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf("requiredStringGroup" to listOf("$requiredStringGroup"), "requiredInt64Group" to listOf("$requiredInt64Group"), "stringGroup" to listOf("$stringGroup"), "int64Group" to listOf("$int64Group")) + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("requiredStringGroup", listOf(requiredStringGroup.toString())) + put("requiredInt64Group", listOf(requiredInt64Group.toString())) + if (stringGroup != null) { + put("stringGroup", listOf(stringGroup.toString())) + } + if (int64Group != null) { + put("int64Group", listOf(int64Group.toString())) + } + } val localVariableHeaders: MutableMap = mutableMapOf("required_boolean_group" to requiredBooleanGroup.toString(), "boolean_group" to booleanGroup.toString()) val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -400,7 +427,7 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun testInlineAdditionalProperties(requestBody: kotlin.collections.Map) : Unit { val localVariableBody: kotlin.Any? = requestBody - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -431,7 +458,7 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun testJsonFormData(param: kotlin.String, param2: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = mapOf("param" to "$param", "param2" to "$param2") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -465,7 +492,14 @@ class FakeApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun testQueryParameterCollectionFormat(pipe: kotlin.Array, ioutil: kotlin.Array, http: kotlin.Array, url: kotlin.Array, context: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf("pipe" to toMultiValue(pipe.toList(), "multi"), "ioutil" to toMultiValue(ioutil.toList(), "csv"), "http" to toMultiValue(http.toList(), "space"), "url" to toMultiValue(url.toList(), "csv"), "context" to toMultiValue(context.toList(), "multi")) + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("pipe", toMultiValue(pipe.toList(), "multi")) + put("ioutil", toMultiValue(ioutil.toList(), "csv")) + put("http", toMultiValue(http.toList(), "space")) + put("url", toMultiValue(url.toList(), "csv")) + put("context", toMultiValue(context.toList(), "multi")) + } val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeClassnameTags123Api.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeClassnameTags123Api.kt index 1d9dcaef220..b29b2d2d4dc 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeClassnameTags123Api.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeClassnameTags123Api.kt @@ -36,7 +36,7 @@ class FakeClassnameTags123Api(basePath: kotlin.String = "http://petstore.swagger @Suppress("UNCHECKED_CAST") fun testClassname(client: Client) : Client { val localVariableBody: kotlin.Any? = client - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PATCH, diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 041c54baad8..76c993796ef 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -36,7 +36,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api */ fun addPet(pet: Pet) : Unit { val localVariableBody: kotlin.Any? = pet - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -67,7 +67,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api */ fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("api_key" to apiKey.toString()) val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -98,7 +98,10 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api @Suppress("UNCHECKED_CAST") fun findPetsByStatus(status: kotlin.Array) : kotlin.Array { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf("status" to toMultiValue(status.toList(), "csv")) + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("status", toMultiValue(status.toList(), "csv")) + } val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -129,7 +132,10 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api @Suppress("UNCHECKED_CAST") fun findPetsByTags(tags: kotlin.Array) : kotlin.Array { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf("tags" to toMultiValue(tags.toList(), "csv")) + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("tags", toMultiValue(tags.toList(), "csv")) + } val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -160,7 +166,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api @Suppress("UNCHECKED_CAST") fun getPetById(petId: kotlin.Long) : Pet { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -190,7 +196,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api */ fun updatePet(pet: Pet) : Unit { val localVariableBody: kotlin.Any? = pet - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, @@ -222,7 +228,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api */ fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?) : Unit { val localVariableBody: kotlin.Any? = mapOf("name" to "$name", "status" to "$status") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -255,7 +261,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api @Suppress("UNCHECKED_CAST") fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: java.io.File?) : ApiResponse { val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to "$additionalMetadata", "file" to "$file") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -288,7 +294,7 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Api @Suppress("UNCHECKED_CAST") fun uploadFileWithRequiredFile(petId: kotlin.Long, requiredFile: java.io.File, additionalMetadata: kotlin.String?) : ApiResponse { val localVariableBody: kotlin.Any? = mapOf("additionalMetadata" to "$additionalMetadata", "requiredFile" to "$requiredFile") - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "") val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 413cfbb0728..260158983ef 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -35,7 +35,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : A */ fun deleteOrder(orderId: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -65,7 +65,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : A @Suppress("UNCHECKED_CAST") fun getInventory() : kotlin.collections.Map { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -96,7 +96,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : A @Suppress("UNCHECKED_CAST") fun getOrderById(orderId: kotlin.Long) : Order { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -127,7 +127,7 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : A @Suppress("UNCHECKED_CAST") fun placeOrder(order: Order) : Order { val localVariableBody: kotlin.Any? = order - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index bb4d53269c2..60c86640975 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -35,7 +35,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun createUser(user: User) : Unit { val localVariableBody: kotlin.Any? = user - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -65,7 +65,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun createUsersWithArrayInput(user: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = user - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -95,7 +95,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun createUsersWithListInput(user: kotlin.Array) : Unit { val localVariableBody: kotlin.Any? = user - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.POST, @@ -125,7 +125,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun deleteUser(username: kotlin.String) : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.DELETE, @@ -156,7 +156,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap @Suppress("UNCHECKED_CAST") fun getUserByName(username: kotlin.String) : User { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -188,7 +188,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap @Suppress("UNCHECKED_CAST") fun loginUser(username: kotlin.String, password: kotlin.String) : kotlin.String { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf("username" to listOf("$username"), "password" to listOf("$password")) + val localVariableQuery: MultiValueMap = mutableMapOf>() + .apply { + put("username", listOf(username.toString())) + put("password", listOf(password.toString())) + } val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -217,7 +221,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun logoutUser() : Unit { val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.GET, @@ -248,7 +252,7 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io:80/v2") : Ap */ fun updateUser(username: kotlin.String, user: User) : Unit { val localVariableBody: kotlin.Any? = user - val localVariableQuery: MultiValueMap = mapOf() + val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() val localVariableConfig = RequestConfig( RequestMethod.PUT, diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt index f97cb88d233..30d3705e5b4 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -1,6 +1,6 @@ package org.openapitools.client.infrastructure -typealias MultiValueMap = Map> +typealias MultiValueMap = MutableMap> fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { "csv" -> "," diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 77b46b9f28f..d5f717b61aa 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -92,13 +92,21 @@ open class ApiClient(val baseUrl: String) { } } if (requestConfig.headers[Authorization].isNullOrEmpty()) { - requestConfig.headers[Authorization] = "Bearer " + accessToken + accessToken?.let { accessToken -> + requestConfig.headers[Authorization] = "Bearer " + accessToken + } } if (requestConfig.headers[Authorization].isNullOrEmpty()) { - requestConfig.headers[Authorization] = Credentials.basic(username, password) + username?.let { username -> + password?.let { password -> + requestConfig.headers[Authorization] = Credentials.basic(username, password) + } + } } if (requestConfig.headers[Authorization].isNullOrEmpty()) { - requestConfig.headers[Authorization] = "Bearer " + accessToken + accessToken?.let { accessToken -> + requestConfig.headers[Authorization] = "Bearer " + accessToken + } } } diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt index 53e689237d7..9c22257e223 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -12,5 +12,5 @@ data class RequestConfig( val method: RequestMethod, val path: String, val headers: MutableMap = mutableMapOf(), - val query: Map> = mapOf() + val query: MutableMap> = mutableMapOf() ) \ No newline at end of file diff --git a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/SpecialModelname.kt b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/SpecialModelname.kt index b6161bcfd65..2f1e0dea5a4 100644 --- a/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/SpecialModelname.kt +++ b/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/SpecialModelname.kt @@ -20,7 +20,7 @@ import java.io.Serializable */ data class SpecialModelname ( - @Json(name = "$special[property.name]") + @Json(name = "\$special[property.name]") val dollarSpecialLeftSquareBracketPropertyPeriodNameRightSquareBracket: kotlin.Long? = null ) : Serializable