diff --git a/.github/workflows/samples-kotlin-client.yaml b/.github/workflows/samples-kotlin-client.yaml index 3840c1e8309..c1f1bfa441f 100644 --- a/.github/workflows/samples-kotlin-client.yaml +++ b/.github/workflows/samples-kotlin-client.yaml @@ -38,13 +38,17 @@ jobs: - samples/client/petstore/kotlin-string - samples/client/petstore/kotlin-threetenbp - samples/client/petstore/kotlin-uppercase-enum - - samples/client/petstore/kotlin-array-simple-string - - samples/client/petstore/kotlin-bigdecimal-default - samples/client/petstore/kotlin-default-values-jvm-okhttp3 - samples/client/petstore/kotlin-default-values-jvm-okhttp4 - samples/client/petstore/kotlin-default-values-jvm-retrofit2 - samples/client/petstore/kotlin-default-values-jvm-volley - samples/client/petstore/kotlin-default-values-multiplatform + - samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3 + - samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4 + - samples/client/petstore/kotlin-array-simple-string-jvm-volley + - samples/client/petstore/kotlin-array-simple-string-multiplatform + - samples/client/petstore/kotlin-bigdecimal-default-multiplatform + - samples/client/petstore/kotlin-bigdecimal-default-okhttp4 - samples/client/petstore/kotlin-jvm-ktor-jackson - samples/client/petstore/kotlin-jvm-ktor-gson steps: diff --git a/bin/configs/kotlin-array-simple-string.yaml b/bin/configs/kotlin-array-simple-string-jvm-okhttp3.yaml similarity index 58% rename from bin/configs/kotlin-array-simple-string.yaml rename to bin/configs/kotlin-array-simple-string-jvm-okhttp3.yaml index 68cbd8c42ff..d24f50303a1 100644 --- a/bin/configs/kotlin-array-simple-string.yaml +++ b/bin/configs/kotlin-array-simple-string-jvm-okhttp3.yaml @@ -1,6 +1,7 @@ generatorName: kotlin -outputDir: samples/client/petstore/kotlin-array-simple-string +outputDir: samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3 inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_7199_array_simple_string.yaml templateDir: modules/openapi-generator/src/main/resources/kotlin-client additionalProperties: - artifactId: kotlin-array-simple-string + artifactId: kotlin-array-simple-string-jvm-okhttp3 + library: jvm-okhttp3 diff --git a/bin/configs/kotlin-array-simple-string-jvm-okhttp4.yaml b/bin/configs/kotlin-array-simple-string-jvm-okhttp4.yaml new file mode 100644 index 00000000000..53e16ff7c1f --- /dev/null +++ b/bin/configs/kotlin-array-simple-string-jvm-okhttp4.yaml @@ -0,0 +1,7 @@ +generatorName: kotlin +outputDir: samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4 +inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_7199_array_simple_string.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-client +additionalProperties: + artifactId: kotlin-array-simple-string-jvm-okhttp4 + library: jvm-okhttp4 diff --git a/bin/configs/kotlin-array-simple-string-jvm-volley.yaml b/bin/configs/kotlin-array-simple-string-jvm-volley.yaml new file mode 100644 index 00000000000..88f6304907c --- /dev/null +++ b/bin/configs/kotlin-array-simple-string-jvm-volley.yaml @@ -0,0 +1,9 @@ +generatorName: kotlin +outputDir: samples/client/petstore/kotlin-array-simple-string-jvm-volley +inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_7199_array_simple_string.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-client +additionalProperties: + artifactId: kotlin-array-simple-string-jvm-volley + library: jvm-volley + serializationLibrary: gson + generateRoomModels: false diff --git a/bin/configs/kotlin-array-simple-string-multiplatform.yaml b/bin/configs/kotlin-array-simple-string-multiplatform.yaml new file mode 100644 index 00000000000..8c880a67971 --- /dev/null +++ b/bin/configs/kotlin-array-simple-string-multiplatform.yaml @@ -0,0 +1,7 @@ +generatorName: kotlin +outputDir: samples/client/petstore/kotlin-array-simple-string-multiplatform +inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_7199_array_simple_string.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-client +additionalProperties: + artifactId: kotlin-array-simple-string-multiplatform + library: multiplatform diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache index 904e3289497..57edf2ef143 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache @@ -66,20 +66,20 @@ import {{packageName}}.infrastructure.toMultiValue {{#enumVars}} {{^multiplatform}} {{#moshi}} - @Json(name = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}), + @Json(name = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}} {{/moshi}} {{#gson}} - @SerializedName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}), + @SerializedName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}} {{/gson}} {{#jackson}} - @JsonProperty(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}), + @JsonProperty(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}} {{/jackson}} {{#kotlinx_serialization}} - @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}), + @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}} {{/kotlinx_serialization}} {{/multiplatform}} {{#multiplatform}} - @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}), + @SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}}) {{&name}}({{{value}}}){{^-last}},{{/-last}} {{/multiplatform}} {{/enumVars}} {{/allowableValues}} @@ -109,7 +109,6 @@ import {{packageName}}.infrastructure.toMultiValue {{/enumVars}} {{/allowableValues}} {{/enumUnknownDefaultCase}} - ; } {{/isEnum}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache index 9ed23005e65..afc245c8f69 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/api.mustache @@ -25,14 +25,14 @@ import rx.Observable import io.reactivex.Single {{/useRxJava2}} {{#useRxJava3}} -import io.reactivex.rxjava3.core.Single; +import io.reactivex.rxjava3.core.Single {{/useRxJava3}} {{^returnType}} {{#useRxJava2}} import io.reactivex.Completable {{/useRxJava2}} {{#useRxJava3}} -import io.reactivex.rxjava3.core.Completable; +import io.reactivex.rxjava3.core.Completable {{/useRxJava3}} {{/returnType}} {{/doNotUseRxAndCoroutines}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/auth/OAuth.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/auth/OAuth.kt.mustache index bf7264e85e1..8063b6c7186 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/auth/OAuth.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/auth/OAuth.kt.mustache @@ -50,8 +50,8 @@ class OAuth( ) : this( OAuthClientRequest.tokenLocation(tokenUrl).setScope(scopes) ) { - setFlow(flow); - authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl); + setFlow(flow) + authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl) } fun setFlow(flow: OAuthFlow) { @@ -146,6 +146,6 @@ class OAuth( throw IOException(e) } } - return true; + return true } } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache index 248dc3718a4..4146c154b2d 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache @@ -100,13 +100,9 @@ import okhttp3.MediaType.Companion.toMediaType private val defaultClientBuilder: OkHttpClient.Builder by lazy { OkHttpClient() .newBuilder() - .addInterceptor(HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { - override fun log(message: String) { - logger?.invoke(message) - } - }).apply { - level = HttpLoggingInterceptor.Level.BODY - }) + .addInterceptor(HttpLoggingInterceptor { message -> logger?.invoke(message) } + .apply { level = HttpLoggingInterceptor.Level.BODY } + ) } init { @@ -125,7 +121,7 @@ import okhttp3.MediaType.Companion.toMediaType {{#authMethods}}"{{name}}" -> {{#isBasic}}{{#isBasicBasic}}HttpBasicAuth(){{/isBasicBasic}}{{#isBasicBearer}}HttpBearerAuth("{{scheme}}"){{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{#isKeyInQuery}}"query"{{/isKeyInQuery}}{{#isKeyInCookie}}"cookie"{{/isKeyInCookie}}, "{{keyParamName}}"){{/isApiKey}}{{#isOAuth}}OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{^-last}}, {{/-last}}{{/scopes}}"){{/isOAuth}}{{/authMethods}} else -> throw RuntimeException("auth name $authName not found in available auth names") } - addAuthorization(authName, auth); + addAuthorization(authName, auth) } } @@ -182,7 +178,7 @@ import okhttp3.MediaType.Companion.toMediaType {{#isBasicBasic}} fun setCredentials(username: String, password: String): ApiClient { apiAuthorizations.values.runOnFirst { - setCredentials(username, password); + setCredentials(username, password) } {{#hasOAuthMethods}} apiAuthorizations.values.runOnFirst { @@ -269,7 +265,7 @@ import okhttp3.MediaType.Companion.toMediaType ?.setClientId(clientId) ?.setRedirectURI(redirectURI) } - return this; + return this } /** @@ -281,7 +277,7 @@ import okhttp3.MediaType.Companion.toMediaType apiAuthorizations.values.runOnFirst { registerAccessTokenListener(accessTokenListener) } - return this; + return this } {{/hasOAuthMethods}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/api.mustache index 3caeebc83f0..515c3c6efba 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/api.mustache @@ -7,7 +7,7 @@ import com.android.volley.RequestQueue import com.android.volley.Response import com.android.volley.toolbox.BaseHttpStack import com.android.volley.toolbox.Volley -import java.util.*; +import java.util.* import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine @@ -52,47 +52,34 @@ class {{classname}} ( {{^bodyParam}} val body: Any? = null {{/bodyParam}} - {{#allParams}} - {{#required}} - // verify the required parameter '{{paramName}}' is set - // This is probably taken care of by non-null types anyway - requireNotNull({{paramName}}) - {{/required}} - {{/allParams}} val contentTypes : Array = arrayOf({{#consumes}}"{{{mediaType}}}"{{^-last}},{{/-last}}{{/consumes}}) val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "{{{path}}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", IRequestFactory.escapeString({{{paramName}}}.toString())){{/pathParams}}; + val path = "{{{path}}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", {{#isContainer}}{{paramName}}.joinToString(","){{/isContainer}}{{^isContainer}}IRequestFactory.escapeString({{{paramName}}}.toString()){{/isContainer}}){{/pathParams}} - // form params - val formParams = mapOf( - {{#formParams}} - "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}), - {{/formParams}} - ) + val formParams = mapOf({{^formParams}}){{/formParams}}{{#formParams}} + "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}){{^-last}},{{/-last}}{{#-last}} + ){{/-last}}{{/formParams}} // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - {{#queryParams}} - "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}), - {{/queryParams}} - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf({{^queryParams}}){{/queryParams}}{{#queryParams}} + "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}){{^-last}},{{/-last}}{{#-last}} + ){{/-last}}{{/queryParams}} + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - {{#headerParams}} - "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}), - {{/headerParams}} - ) + val headerParams: Map = mapOf({{^headerParams}}){{/headerParams}}{{#headerParams}} + "{{baseName}}" to IRequestFactory.parameterToString({{paramName}}){{^-last}},{{/-last}}{{#-last}} + ){{/-last}}{{/headerParams}} return suspendCoroutine { continuation -> val responseListener = Response.Listener<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}> { response -> @@ -119,7 +106,7 @@ class {{classname}} ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/build.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/build.mustache index e12ca8c4c73..3b15fd5dfa1 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/build.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/build.mustache @@ -6,17 +6,11 @@ project.version = '{{artifactVersion}}' buildscript { ext.kotlin_version = '1.5.10' - ext.swagger_annotations_version = "1.6.2" - ext.gson_version = "2.8.6" - ext.volley_version = "1.2.0" - ext.junit_version = "4.13.2" - ext.robolectric_version = "4.5.1" - ext.concurrent_unit_version = "0.4.6" repositories { diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/gradle.properties.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/gradle.properties.mustache index 8cbe6270192..f7a5f347d68 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/gradle.properties.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-volley/gradle.properties.mustache @@ -1,4 +1,4 @@ -{{#generateRoomModels}} android.useAndroidX=true +{{#generateRoomModels}} android.enableJetifier=true {{/generateRoomModels}} \ 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 b7af1ddddc2..be8b3164406 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 @@ -60,19 +60,14 @@ import kotlinx.serialization.encoding.* {{/hasFormParams}} {{/hasBodyParam}} - val localVariableQuery = mutableMapOf>() - {{#queryParams}} - {{{paramName}}}?.apply { localVariableQuery["{{baseName}}"] = {{#isContainer}}toMultiValue(this, "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf("${{{paramName}}}"){{/isContainer}} } - {{/queryParams}} - - val localVariableHeaders = mutableMapOf() - {{#headerParams}} - {{{paramName}}}?.apply { localVariableHeaders["{{baseName}}"] = {{#isContainer}}this.joinToString(separator = collectionDelimiter("{{collectionFormat}}")){{/isContainer}}{{^isContainer}}this.toString(){{/isContainer}} } - {{/headerParams}} + val localVariableQuery = mutableMapOf>(){{#queryParams}} + {{{paramName}}}?.apply { localVariableQuery["{{baseName}}"] = {{#isContainer}}toMultiValue(this, "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf("${{{paramName}}}"){{/isContainer}} }{{/queryParams}} + val localVariableHeaders = mutableMapOf(){{#headerParams}} + {{{paramName}}}?.apply { localVariableHeaders["{{baseName}}"] = {{#isContainer}}this.joinToString(separator = collectionDelimiter("{{collectionFormat}}")){{/isContainer}}{{^isContainer}}this.toString(){{/isContainer}} }{{/headerParams}} val localVariableConfig = RequestConfig( RequestMethod.{{httpMethod}}, - "{{path}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", "${{{paramName}}}"){{/pathParams}}, + "{{path}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", {{#isContainer}}{{paramName}}.joinToString(","){{/isContainer}}{{^isContainer}}"${{{paramName}}}"{{/isContainer}}){{/pathParams}}, query = localVariableQuery, headers = localVariableHeaders ) diff --git a/samples/client/petstore/kotlin-array-simple-string/.openapi-generator-ignore b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/.openapi-generator-ignore similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/.openapi-generator-ignore rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/.openapi-generator-ignore diff --git a/samples/client/petstore/kotlin-array-simple-string/.openapi-generator/FILES b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/.openapi-generator/FILES similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/.openapi-generator/FILES rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/.openapi-generator/FILES diff --git a/samples/client/petstore/kotlin-array-simple-string/.openapi-generator/VERSION b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/.openapi-generator/VERSION similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/.openapi-generator/VERSION rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/.openapi-generator/VERSION diff --git a/samples/client/petstore/kotlin-array-simple-string/README.md b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/README.md similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/README.md rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/README.md diff --git a/samples/client/petstore/kotlin-bigdecimal-default/build.gradle b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/build.gradle similarity index 94% rename from samples/client/petstore/kotlin-bigdecimal-default/build.gradle rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/build.gradle index 3de8b45b135..b19a3b3873d 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default/build.gradle +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/build.gradle @@ -32,6 +32,6 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "com.squareup.moshi:moshi-kotlin:1.12.0" implementation "com.squareup.moshi:moshi-adapters:1.12.0" - implementation "com.squareup.okhttp3:okhttp:4.9.1" + implementation "com.squareup.okhttp3:okhttp:3.12.13" testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" } diff --git a/samples/client/petstore/kotlin-array-simple-string/docs/DefaultApi.md b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/docs/DefaultApi.md similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/docs/DefaultApi.md rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/docs/DefaultApi.md diff --git a/samples/client/petstore/kotlin-array-simple-string/gradle/wrapper/gradle-wrapper.jar b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/gradle/wrapper/gradle-wrapper.jar rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/gradle/wrapper/gradle-wrapper.jar diff --git a/samples/client/petstore/kotlin-array-simple-string/gradle/wrapper/gradle-wrapper.properties b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/gradle/wrapper/gradle-wrapper.properties rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/gradle/wrapper/gradle-wrapper.properties diff --git a/samples/client/petstore/kotlin-array-simple-string/gradlew b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/gradlew similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/gradlew rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/gradlew diff --git a/samples/client/petstore/kotlin-array-simple-string/gradlew.bat b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/gradlew.bat similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/gradlew.bat rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/gradlew.bat diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/settings.gradle b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/settings.gradle new file mode 100644 index 00000000000..f5905696550 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/settings.gradle @@ -0,0 +1,2 @@ + +rootProject.name = 'kotlin-array-simple-string-jvm-okhttp3' \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt similarity index 87% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index c3639b96e1c..8a0b3979c26 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -2,20 +2,17 @@ package org.openapitools.client.infrastructure import okhttp3.OkHttpClient import okhttp3.RequestBody -import okhttp3.RequestBody.Companion.asRequestBody -import okhttp3.RequestBody.Companion.toRequestBody +import okhttp3.MediaType import okhttp3.FormBody -import okhttp3.HttpUrl.Companion.toHttpUrlOrNull +import okhttp3.HttpUrl import okhttp3.ResponseBody -import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.Request import okhttp3.Headers -import okhttp3.Headers.Companion.toHeaders import okhttp3.MultipartBody import okhttp3.Call import okhttp3.Callback import okhttp3.Response -import okhttp3.internal.EMPTY_REQUEST +import okhttp3.internal.Util.EMPTY_REQUEST import java.io.BufferedWriter import java.io.File import java.io.FileWriter @@ -80,7 +77,7 @@ open class ApiClient(val baseUrl: String) { bodies.forEach { body -> val headers = part.headers.toMutableMap() + ("Content-Disposition" to "form-data; name=\"$name\"" + if (body is File) "; filename=\"${body.name}\"" else "") - addPart(headers.toHeaders(), + addPart(Headers.of(headers), requestSingleBody(body, contentType)) } } @@ -90,7 +87,7 @@ open class ApiClient(val baseUrl: String) { protected inline fun requestSingleBody(content: T, mediaType: String?): RequestBody = when { - content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) + content is File -> RequestBody.create(MediaType.parse(mediaType ?: guessContentTypeFromFile(content)), content) mediaType == FormUrlEncMediaType -> { FormBody.Builder().apply { // content's type *must* be Map> @@ -104,8 +101,9 @@ open class ApiClient(val baseUrl: String) { if (content == null) { EMPTY_REQUEST } else { - Serializer.moshi.adapter(T::class.java).toJson(content) - .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + RequestBody.create( + MediaType.parse(mediaType ?: JsonMediaType), Serializer.moshi.adapter(T::class.java).toJson(content) + ) } mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") // TODO: this should be extended with other serializers @@ -138,7 +136,7 @@ open class ApiClient(val baseUrl: String) { protected inline fun request(requestConfig: RequestConfig): ApiResponse { - val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") + val httpUrl = HttpUrl.parse(baseUrl) ?: throw IllegalStateException("baseUrl is invalid.") val url = httpUrl.newBuilder() .addPathSegments(requestConfig.path.trimStart('/')) @@ -189,30 +187,30 @@ open class ApiClient(val baseUrl: String) { // TODO: handle specific mapping types. e.g. Map> return when { response.isRedirect -> Redirection( - response.code, - response.headers.toMultimap() + response.code(), + response.headers().toMultimap() ) response.isInformational -> Informational( - response.message, - response.code, - response.headers.toMultimap() + response.message(), + response.code(), + response.headers().toMultimap() ) response.isSuccessful -> Success( - responseBody(response.body, accept), - response.code, - response.headers.toMultimap() + responseBody(response.body(), accept), + response.code(), + response.headers().toMultimap() ) response.isClientError -> ClientError( - response.message, - response.body?.string(), - response.code, - response.headers.toMultimap() + response.message(), + response.body()?.string(), + response.code(), + response.headers().toMultimap() ) else -> ServerError( - response.message, - response.body?.string(), - response.code, - response.headers.toMultimap() + response.message(), + response.body()?.string(), + response.code(), + response.headers().toMultimap() ) } } diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt similarity index 63% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt index 9bd2790dc14..037fedbd18b 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt @@ -5,20 +5,20 @@ import okhttp3.Response /** * Provides an extension to evaluation whether the response is a 1xx code */ -val Response.isInformational : Boolean get() = this.code in 100..199 +val Response.isInformational : Boolean get() = this.code() in 100..199 /** * Provides an extension to evaluation whether the response is a 3xx code */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") -val Response.isRedirect : Boolean get() = this.code in 300..399 +val Response.isRedirect : Boolean get() = this.code() in 300..399 /** * Provides an extension to evaluation whether the response is a 4xx code */ -val Response.isClientError : Boolean get() = this.code in 400..499 +val Response.isClientError : Boolean get() = this.code() in 400..499 /** * Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code */ -val Response.isServerError : Boolean get() = this.code in 500..999 +val Response.isServerError : Boolean get() = this.code() in 500..999 diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/.openapi-generator-ignore b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/.openapi-generator-ignore similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/.openapi-generator-ignore rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/.openapi-generator-ignore diff --git a/samples/client/petstore/kotlin-bigdecimal-default/.openapi-generator/FILES b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/.openapi-generator/FILES similarity index 95% rename from samples/client/petstore/kotlin-bigdecimal-default/.openapi-generator/FILES rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/.openapi-generator/FILES index e3526d4a11c..2d00928eb93 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default/.openapi-generator/FILES +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/.openapi-generator/FILES @@ -1,6 +1,5 @@ README.md build.gradle -docs/Apa.md docs/DefaultApi.md gradle/wrapper/gradle-wrapper.jar gradle/wrapper/gradle-wrapper.properties @@ -25,4 +24,3 @@ src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt -src/main/kotlin/org/openapitools/client/models/Apa.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/.openapi-generator/VERSION b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/.openapi-generator/VERSION similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/.openapi-generator/VERSION rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/.openapi-generator/VERSION diff --git a/samples/client/petstore/kotlin-bigdecimal-default/README.md b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/README.md similarity index 89% rename from samples/client/petstore/kotlin-bigdecimal-default/README.md rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/README.md index 5928098211e..833e3ab254f 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default/README.md +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/README.md @@ -35,13 +35,12 @@ All URIs are relative to *http://localhost* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*DefaultApi* | [**testPost**](docs/DefaultApi.md#testpost) | **POST** /test | +*DefaultApi* | [**idsGet**](docs/DefaultApi.md#idsget) | **GET** /{ids} | ## Documentation for Models - - [org.openapitools.client.models.Apa](docs/Apa.md) diff --git a/samples/client/petstore/kotlin-array-simple-string/build.gradle b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/build.gradle similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/build.gradle rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/build.gradle diff --git a/samples/client/petstore/kotlin-bigdecimal-default/docs/DefaultApi.md b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/docs/DefaultApi.md similarity index 60% rename from samples/client/petstore/kotlin-bigdecimal-default/docs/DefaultApi.md rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/docs/DefaultApi.md index 4bc4c342267..45b43113f19 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default/docs/DefaultApi.md +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/docs/DefaultApi.md @@ -4,12 +4,12 @@ All URIs are relative to *http://localhost* Method | HTTP request | Description ------------- | ------------- | ------------- -[**testPost**](DefaultApi.md#testPost) | **POST** /test | +[**idsGet**](DefaultApi.md#idsGet) | **GET** /{ids} | - -# **testPost** -> testPost(apa) + +# **idsGet** +> idsGet(ids) @@ -20,14 +20,14 @@ Method | HTTP request | Description //import org.openapitools.client.models.* val apiInstance = DefaultApi() -val apa : Apa = // Apa | +val ids : kotlin.collections.List = // kotlin.collections.List | try { - apiInstance.testPost(apa) + apiInstance.idsGet(ids) } catch (e: ClientException) { - println("4xx response calling DefaultApi#testPost") + println("4xx response calling DefaultApi#idsGet") e.printStackTrace() } catch (e: ServerException) { - println("5xx response calling DefaultApi#testPost") + println("5xx response calling DefaultApi#idsGet") e.printStackTrace() } ``` @@ -36,7 +36,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **apa** | [**Apa**](Apa.md)| | + **ids** | [**kotlin.collections.List<kotlin.String>**](kotlin.String.md)| | ### Return type @@ -48,6 +48,6 @@ No authorization required ### HTTP request headers - - **Content-Type**: application/json + - **Content-Type**: Not defined - **Accept**: Not defined diff --git a/samples/client/petstore/kotlin-bigdecimal-default/gradle/wrapper/gradle-wrapper.jar b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/gradle/wrapper/gradle-wrapper.jar rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/gradle/wrapper/gradle-wrapper.jar diff --git a/samples/client/petstore/kotlin-bigdecimal-default/gradle/wrapper/gradle-wrapper.properties b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/gradle/wrapper/gradle-wrapper.properties rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/gradle/wrapper/gradle-wrapper.properties diff --git a/samples/client/petstore/kotlin-bigdecimal-default/gradlew b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/gradlew similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/gradlew rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/gradlew diff --git a/samples/client/petstore/kotlin-bigdecimal-default/gradlew.bat b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/gradlew.bat similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/gradlew.bat rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/gradlew.bat diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/settings.gradle b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/settings.gradle new file mode 100644 index 00000000000..5aec294e35c --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/settings.gradle @@ -0,0 +1,2 @@ + +rootProject.name = 'kotlin-array-simple-string-jvm-okhttp4' \ No newline at end of file diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt similarity index 69% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 5cef90d59da..3f5af3cfb42 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -22,7 +22,6 @@ package org.openapitools.client.apis import java.io.IOException -import org.openapitools.client.models.Apa import com.squareup.moshi.Json @@ -49,19 +48,19 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath } /** - * - * - * @param apa - * @return void - * @throws IllegalStateException If the request is not correctly configured - * @throws IOException Rethrows the OkHttp execute method exception - * @throws UnsupportedOperationException If the API returns an informational or redirection response - * @throws ClientException If the API returns a client error response - * @throws ServerException If the API returns a server error response - */ + * + * + * @param ids + * @return void + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) - fun testPost(apa: Apa) : Unit { - val localVarResponse = testPostWithHttpInfo(apa = apa) + fun idsGet(ids: kotlin.collections.List) : Unit { + val localVarResponse = idsGetWithHttpInfo(ids = ids) return when (localVarResponse.responseType) { ResponseType.Success -> Unit @@ -79,37 +78,36 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath } /** - * - * - * @param apa - * @return ApiResponse - * @throws IllegalStateException If the request is not correctly configured - * @throws IOException Rethrows the OkHttp execute method exception - */ + * + * + * @param ids + * @return ApiResponse + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + */ @Throws(IllegalStateException::class, IOException::class) - fun testPostWithHttpInfo(apa: Apa) : ApiResponse { - val localVariableConfig = testPostRequestConfig(apa = apa) + fun idsGetWithHttpInfo(ids: kotlin.collections.List) : ApiResponse { + val localVariableConfig = idsGetRequestConfig(ids = ids) - return request( + return request( localVariableConfig ) } /** - * To obtain the request config of the operation testPost - * - * @param apa - * @return RequestConfig - */ - fun testPostRequestConfig(apa: Apa) : RequestConfig { - val localVariableBody = apa + * To obtain the request config of the operation idsGet + * + * @param ids + * @return RequestConfig + */ + fun idsGetRequestConfig(ids: kotlin.collections.List) : RequestConfig { + val localVariableBody = null val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf() - localVariableHeaders["Content-Type"] = "application/json" return RequestConfig( - method = RequestMethod.POST, - path = "/test", + method = RequestMethod.GET, + path = "/{ids}".replace("{"+"ids"+"}", ids.joinToString(",")), query = localVariableQuery, headers = localVariableHeaders, body = localVariableBody diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt diff --git a/samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt similarity index 100% rename from samples/client/petstore/kotlin-array-simple-string/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt similarity index 100% rename from samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt rename to samples/client/petstore/kotlin-array-simple-string-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/.openapi-generator-ignore b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/.openapi-generator/FILES b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/.openapi-generator/FILES new file mode 100644 index 00000000000..af9115f572e --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/.openapi-generator/FILES @@ -0,0 +1,21 @@ +README.md +build.gradle +docs/DefaultApi.md +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +settings.gradle +src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/CollectionFormats.kt +src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/ResponseExt.kt +src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/.openapi-generator/VERSION b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/.openapi-generator/VERSION new file mode 100644 index 00000000000..5f68295fc19 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/README.md b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/README.md new file mode 100644 index 00000000000..b425658ca6e --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/README.md @@ -0,0 +1,49 @@ +# org.openapitools.client - Kotlin client library for Demo + +## Requires + +* Kotlin 1.4.30 +* Gradle 6.8.3 + +## Build + +First, create the gradle wrapper script: + +``` +gradle wrapper +``` + +Then, run: + +``` +./gradlew check assemble +``` + +This runs all tests and packages the library. + +## Features/Implementation Notes + +* Supports JSON inputs/outputs, File inputs, and Form inputs. +* Supports collection formats for query parameters: csv, tsv, ssv, pipes. +* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions. +* Implementation of ApiClient is intended to reduce method counts, specifically to benefit Android targets. + + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**idsGet**](docs/DefaultApi.md#idsget) | **GET** {ids} | + + + +## Documentation for Models + + + + +## Documentation for Authorization + +All endpoints do not require authorization. diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/build.gradle b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/build.gradle new file mode 100644 index 00000000000..e094b704418 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/build.gradle @@ -0,0 +1,41 @@ +group 'org.openapitools' +version '1.0.0' + +wrapper { + gradleVersion = '6.8.3' + distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" +} + +buildscript { + ext.kotlin_version = '1.5.10' + ext.retrofitVersion = '2.9.0' + + repositories { + maven { url "https://repo1.maven.org/maven2" } + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' + +repositories { + maven { url "https://repo1.maven.org/maven2" } +} + +test { + useJUnitPlatform() +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" + implementation "com.squareup.moshi:moshi-kotlin:1.12.0" + implementation "com.squareup.moshi:moshi-adapters:1.12.0" + implementation "com.squareup.okhttp3:logging-interceptor:4.9.1" + implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" + implementation "com.squareup.retrofit2:converter-moshi:$retrofitVersion" + implementation "com.squareup.retrofit2:converter-scalars:$retrofitVersion" + testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/docs/DefaultApi.md b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/docs/DefaultApi.md new file mode 100644 index 00000000000..71d965ba0bb --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/docs/DefaultApi.md @@ -0,0 +1,45 @@ +# DefaultApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**idsGet**](DefaultApi.md#idsGet) | **GET** {ids} | + + + + + +### Example +```kotlin +// Import classes: +//import org.openapitools.client.* +//import org.openapitools.client.infrastructure.* +//import org.openapitools.client.models.* + +val apiClient = ApiClient() +val webService = apiClient.createWebservice(DefaultApi::class.java) +val ids : kotlin.collections.List = // kotlin.collections.List | + +webService.idsGet(ids) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **ids** | [**kotlin.collections.List<kotlin.String>**](kotlin.String.md)| | + +### Return type + +null (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradle/wrapper/gradle-wrapper.jar b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..e708b1c023e Binary files /dev/null and b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradle/wrapper/gradle-wrapper.properties b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..8cf6eb5ad22 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradlew b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradlew new file mode 100644 index 00000000000..4f906e0c811 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradlew.bat b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradlew.bat new file mode 100644 index 00000000000..107acd32c4e --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/settings.gradle b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/settings.gradle new file mode 100644 index 00000000000..e4e39687f2e --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/settings.gradle @@ -0,0 +1,2 @@ + +rootProject.name = 'kotlin-array-simple-string-jvm-retrofit2' \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt new file mode 100644 index 00000000000..543895d21ed --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -0,0 +1,22 @@ +package org.openapitools.client.apis + +import org.openapitools.client.infrastructure.CollectionFormats.* +import retrofit2.http.* +import retrofit2.Call +import okhttp3.RequestBody + + +interface DefaultApi { + /** + * + * + * Responses: + * - 200: Successful operation + * + * @param ids + * @return [Call]<[Unit]> + */ + @GET("{ids}") + fun idsGet(@Path("ids") ids: kotlin.collections.List): Call + +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt new file mode 100644 index 00000000000..66d79abe35a --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -0,0 +1,102 @@ +package org.openapitools.client.infrastructure + + +import okhttp3.Call +import okhttp3.Interceptor +import okhttp3.OkHttpClient +import retrofit2.Retrofit +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Converter +import retrofit2.converter.scalars.ScalarsConverterFactory +import com.squareup.moshi.Moshi +import retrofit2.converter.moshi.MoshiConverterFactory + + +class ApiClient( + private var baseUrl: String = defaultBasePath, + private val okHttpClientBuilder: OkHttpClient.Builder? = null, + private val serializerBuilder: Moshi.Builder = Serializer.moshiBuilder, + private val callFactory : Call.Factory? = null, + private val converterFactory: Converter.Factory? = null, +) { + private val apiAuthorizations = mutableMapOf() + var logger: ((String) -> Unit)? = null + + private val retrofitBuilder: Retrofit.Builder by lazy { + Retrofit.Builder() + .baseUrl(baseUrl) + .addConverterFactory(ScalarsConverterFactory.create()) + .addConverterFactory(MoshiConverterFactory.create(serializerBuilder.build())) + .apply { + if (converterFactory != null) { + addConverterFactory(converterFactory) + } + } + } + + private val clientBuilder: OkHttpClient.Builder by lazy { + okHttpClientBuilder ?: defaultClientBuilder + } + + private val defaultClientBuilder: OkHttpClient.Builder by lazy { + OkHttpClient() + .newBuilder() + .addInterceptor(HttpLoggingInterceptor { message -> logger?.invoke(message) } + .apply { level = HttpLoggingInterceptor.Level.BODY } + ) + } + + init { + normalizeBaseUrl() + } + + /** + * Adds an authorization to be used by the client + * @param authName Authentication name + * @param authorization Authorization interceptor + * @return ApiClient + */ + fun addAuthorization(authName: String, authorization: Interceptor): ApiClient { + if (apiAuthorizations.containsKey(authName)) { + throw RuntimeException("auth name $authName already in api authorizations") + } + apiAuthorizations[authName] = authorization + clientBuilder.addInterceptor(authorization) + return this + } + + fun setLogger(logger: (String) -> Unit): ApiClient { + this.logger = logger + return this + } + + fun createService(serviceClass: Class): S { + val usedCallFactory = this.callFactory ?: clientBuilder.build() + return retrofitBuilder.callFactory(usedCallFactory).build().create(serviceClass) + } + + private fun normalizeBaseUrl() { + if (!baseUrl.endsWith("/")) { + baseUrl += "/" + } + } + + private inline fun Iterable.runOnFirst(callback: U.() -> Unit) { + for (element in this) { + if (element is U) { + callback.invoke(element) + break + } + } + } + + companion object { + @JvmStatic + protected val baseUrlKey = "org.openapitools.client.baseUrl" + + @JvmStatic + val defaultBasePath: String by lazy { + System.getProperties().getProperty(baseUrlKey, "http://localhost") + } + } +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt new file mode 100644 index 00000000000..fb2c972cf8d --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt @@ -0,0 +1,17 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.math.BigDecimal + +class BigDecimalAdapter { + @ToJson + fun toJson(value: BigDecimal): String { + return value.toPlainString() + } + + @FromJson + fun fromJson(value: String): BigDecimal { + return BigDecimal(value) + } +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt new file mode 100644 index 00000000000..4b6963110c9 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt @@ -0,0 +1,17 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.math.BigInteger + +class BigIntegerAdapter { + @ToJson + fun toJson(value: BigInteger): String { + return value.toString() + } + + @FromJson + fun fromJson(value: String): BigInteger { + return BigInteger(value) + } +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt new file mode 100644 index 00000000000..ff5e2a81ee8 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt @@ -0,0 +1,12 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson + +class ByteArrayAdapter { + @ToJson + fun toJson(data: ByteArray): String = String(data) + + @FromJson + fun fromJson(data: String): ByteArray = data.toByteArray() +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/CollectionFormats.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/CollectionFormats.kt new file mode 100644 index 00000000000..001e99325d2 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/CollectionFormats.kt @@ -0,0 +1,56 @@ +package org.openapitools.client.infrastructure + +class CollectionFormats { + + open class CSVParams { + + var params: List + + constructor(params: List) { + this.params = params + } + + constructor(vararg params: String) { + this.params = listOf(*params) + } + + override fun toString(): String { + return params.joinToString(",") + } + } + + open class SSVParams : CSVParams { + + constructor(params: List) : super(params) + + constructor(vararg params: String) : super(*params) + + override fun toString(): String { + return params.joinToString(" ") + } + } + + class TSVParams : CSVParams { + + constructor(params: List) : super(params) + + constructor(vararg params: String) : super(*params) + + override fun toString(): String { + return params.joinToString("\t") + } + } + + class PIPESParams : CSVParams { + + constructor(params: List) : super(params) + + constructor(vararg params: String) : super(*params) + + override fun toString(): String { + return params.joinToString("|") + } + } + + class SPACEParams : SSVParams() +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt new file mode 100644 index 00000000000..b2e1654479a --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt @@ -0,0 +1,19 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.time.LocalDate +import java.time.format.DateTimeFormatter + +class LocalDateAdapter { + @ToJson + fun toJson(value: LocalDate): String { + return DateTimeFormatter.ISO_LOCAL_DATE.format(value) + } + + @FromJson + fun fromJson(value: String): LocalDate { + return LocalDate.parse(value, DateTimeFormatter.ISO_LOCAL_DATE) + } + +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt new file mode 100644 index 00000000000..e082db94811 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt @@ -0,0 +1,19 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter + +class LocalDateTimeAdapter { + @ToJson + fun toJson(value: LocalDateTime): String { + return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value) + } + + @FromJson + fun fromJson(value: String): LocalDateTime { + return LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME) + } + +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt new file mode 100644 index 00000000000..87437871a31 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt @@ -0,0 +1,19 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.time.OffsetDateTime +import java.time.format.DateTimeFormatter + +class OffsetDateTimeAdapter { + @ToJson + fun toJson(value: OffsetDateTime): String { + return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value) + } + + @FromJson + fun fromJson(value: String): OffsetDateTime { + return OffsetDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE_TIME) + } + +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExt.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExt.kt new file mode 100644 index 00000000000..2a494b5f9a3 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExt.kt @@ -0,0 +1,16 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.JsonDataException +import com.squareup.moshi.Moshi +import retrofit2.Response + +@Throws(JsonDataException::class) +inline fun Response<*>.getErrorResponse(serializerBuilder: Moshi.Builder = Serializer.moshiBuilder): T? { + val serializer = serializerBuilder.build() + val parser = serializer.adapter(T::class.java) + val response = errorBody()?.string() + if (response != null) { + return parser.fromJson(response) + } + return null +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt new file mode 100644 index 00000000000..e22592e47d7 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -0,0 +1,23 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.Moshi +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory + +object Serializer { + @JvmStatic + val moshiBuilder: Moshi.Builder = Moshi.Builder() + .add(OffsetDateTimeAdapter()) + .add(LocalDateTimeAdapter()) + .add(LocalDateAdapter()) + .add(UUIDAdapter()) + .add(ByteArrayAdapter()) + .add(URIAdapter()) + .add(KotlinJsonAdapterFactory()) + .add(BigDecimalAdapter()) + .add(BigIntegerAdapter()) + + @JvmStatic + val moshi: Moshi by lazy { + moshiBuilder.build() + } +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt new file mode 100644 index 00000000000..927522757da --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt @@ -0,0 +1,13 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.net.URI + +class URIAdapter { + @ToJson + fun toJson(uri: URI) = uri.toString() + + @FromJson + fun fromJson(s: String): URI = URI.create(s) +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt new file mode 100644 index 00000000000..7ccf7dc25d2 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt @@ -0,0 +1,13 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.util.UUID + +class UUIDAdapter { + @ToJson + fun toJson(uuid: UUID) = uuid.toString() + + @FromJson + fun fromJson(s: String): UUID = UUID.fromString(s) +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/.openapi-generator-ignore b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/.openapi-generator/FILES b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/.openapi-generator/FILES new file mode 100644 index 00000000000..9cfbb490924 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/.openapi-generator/FILES @@ -0,0 +1,20 @@ +README.md +build.gradle +docs/DefaultApi.md +gradle.properties +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +settings.gradle +src/main/AndroidManifest.xml +src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/CollectionFormats.kt +src/main/kotlin/org/openapitools/client/infrastructure/CollectionFormats.kt +src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt +src/main/kotlin/org/openapitools/client/request/GsonRequest.kt +src/main/kotlin/org/openapitools/client/request/IRequestFactory.kt +src/main/kotlin/org/openapitools/client/request/RequestFactory.kt diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/.openapi-generator/VERSION b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/.openapi-generator/VERSION new file mode 100644 index 00000000000..5f68295fc19 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/README.md b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/README.md new file mode 100644 index 00000000000..1180f9c7dff --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/README.md @@ -0,0 +1,189 @@ +# org.openapitools.client - Kotlin client library for Demo + + +A kotlin client for Android using the currently recommended http client, Volley. See https://developer.android.com/training/volley + +- Currently sends GsonRequests +- Currently only supports Gson as a serializer - will throw an exception if a different serializer is chosen +- Defaults the source location to src/main/java as per standard Android builds + + +## Design + +Volley is a queue/request based layer on top of http url stack specific to Android. Android favours dependency injection and +a layered architecture, and IO performed off the main thread to maintain UI responsiveness, with a preferred technique of +kotlin co-routines. The code gen library reflects these factors. + +- Api calls use co-routines, and execute them using volley callbacks to avoid tying up a thread. +- Facilitate dependency injection, with default implementations available. +- Generate a requestFactory that can be overridden +- Allow the passing of the RequestFactory per tag (api client) or per operation (an extra parameter is created on operations with non-global security), with per operation auth overriding global security. +- DI scoping of the Request Factory and pre-generated auth header factories allow for thread safe and secure setting of credentials. +- Lazy header factories allow for refreshing tokens etc +- Factoring of header factories to the Request Factory allow ambient provision of credentials. Code gen library is credential storage agnostic. +- Header factories allow the merging of generated headers from open api spec with dynamically added headers + +- Injection of http url stack to allow custom http stacks. Default implementation is best practice singleton +- Data classes used for serialisation to reflect volley's preference - an immutable request that once queued can't be tampered with. + +- Reuse model class and other jvm common infrastructure + +- Optional generation of room database models, and transform methods to these from open api models +- Room and api models can be extended with additional extension properties. + +## Future improvements +- Option to generate image requests on certain conditionals e.g content-type gif etc +- Support for kotlin serialization. +- Multi part form parameters and support for file inputs + +## Usage +Hilt Dependency injection example - with default values for parameters overridden. +``` + @Provides + internal fun provideSomeApi( + context: Context, + restService: IRestService, + configurationService: IConfigurationService, + sessionService: ISessionService + ): SomeApi { + return SomeApi( + context = context, + requestQueue = restService.getRequestQueue(), + requestFactory = RequestFactory(listOf(createSessionHeaderFactory(sessionService), createTraceHeaderFactory()), + postProcessors = listOf(retryPolicySetter)), + basePath = configurationService.getBaseUrl() + ) + } +``` +Here is the constructor so you can see the defaults +```class SomeApi ( +val context: Context, +val requestQueue: Lazy = lazy(initializer = { + Volley.newRequestQueue(context.applicationContext) + }), + val requestFactory: IRequestFactory = RequestFactory(), + val basePath: String = "https://yourbasepath.from_input_parameter.com/api", + private val postProcessors :List <(Request<*>) -> Unit> = listOf()) { +``` + +### Overriding defaults +The above constructor for each api allows the following to be customized +- A custom context, so either a singleton request queue or different scope can be created - see +https://developer.android.com/training/volley/requestqueue#singleton +- An overrideable request queue - which in turn can have a custom http url stack passed to it +- An overrideable request factory constructor call, or a request factory that can be overridden by a custom template, with +custom header factory, request post processors and custom gson adapters injected. + +#### Overriding request generation +Request generation can be overridden by +- Overriding the entire request factory template +- Supplying custom header factories - methods that take any possible parameters but return a map of headers +- Supplying custom request post processors - methods that take and return the request object + +Header factory examples can be found in the auth section, as these are implemented as header factories. eg +``` +val basicAuthHeaderFactoryBuilder = { username: String?, password: String? -> +{ mapOf("Authorization" to "Basic " + Base64.encodeToString("${username ?: ""}:${password ?: ""}".toByteArray(), Base64.DEFAULT))} +} +``` +In this case it's a lambda function (a factory method) that takes an username and password, and returns a map of headers. Other +generated code will supply the username and password. In this case it results in a map of just one key/value pair, but +it could be multiple. The important part is it's returning a map - and that the surrounding code +will can bind the inputs to it at some point. + +Here is a different example that supplies tracing header values +``` +/** + * Create a lambda of tracing headers to be injected into an API's [RequestFactory]. + */ +private fun createTraceHeaderFactory(): () -> Map = { + mapOf( + HttpHeaderType.b3_traceId.rawValue to UUIDExtensions.asTraceId(UUID.randomUUID()), + HttpHeaderType.b3_spanId.rawValue to UUIDExtensions.asSpanId(UUID.randomUUID()), + HttpHeaderType.b3_sampled.rawValue to "1" + ) +} +``` +Finally a post processor example +``` + /** + * Configure a [DefaultRetryPolicy] to be injected into the [RequestFactory] with a maximum number of retries of zero. + */ + private val retryPolicySetter = { request: Request<*> -> + Unit.apply { + request.setRetryPolicy( + DefaultRetryPolicy( + RestService.DEFAULT_TIMEOUT_MS, + 0, + DefaultRetryPolicy.DEFAULT_BACKOFF_MULT + ) + ) + } + } +``` + +### Serialization +#### Gson and Polymorphic types +The GsonRequest object can be passed custom type adapters +``` +class GsonRequest( + method: Int, + url: String, + private val body: Any?, + private val headers: Map?, + private val params: MutableMap?, + private val contentTypeForBody: String?, + private val encodingForParams: String?, + private val gsonAdapters: Map?, + private val type: Type, + private val listener: Response.Listener, + errorListener: Response.ErrorListener +) : Request(method, url, errorListener) { + + val gsonBuilder: GsonBuilder = GsonBuilder() + .registerTypeAdapter(OffsetDateTime::class.java, OffsetDateTimeAdapter()) + .registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter()) + .registerTypeAdapter(LocalDate::class.java, LocalDateAdapter()) + .registerTypeAdapter(ByteArray::class.java, ByteArrayAdapter()) + +``` +## Requires + +* Kotlin 1.4.30 +* Gradle 6.8.3 + +## Build + +First, create the gradle wrapper script: + +``` +gradle wrapper +``` + +Then, run: + +``` +./gradlew check assemble +``` + +This runs all tests and packages the library. + + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**idsGet**](docs/DefaultApi.md#idsget) | **GET** /{ids} | + + + +## Documentation for Models + + + + +## Documentation for Authorization + +All endpoints do not require authorization. diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/build.gradle b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/build.gradle new file mode 100644 index 00000000000..ee1b502ce9e --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/build.gradle @@ -0,0 +1,87 @@ + +buildscript { + + ext.kotlin_version = '1.5.10' + ext.swagger_annotations_version = "1.6.2" + ext.gson_version = "2.8.6" + ext.volley_version = "1.2.0" + ext.junit_version = "4.13.2" + ext.robolectric_version = "4.5.1" + ext.concurrent_unit_version = "0.4.6" + + repositories { + mavenLocal() + google() + maven { + url 'https://dl.google.com/dl/android/maven2' + } + mavenCentral() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.android.tools.build:gradle:4.0.2' + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + +android { + compileSdkVersion 30 + defaultConfig { + minSdkVersion 21 + targetSdkVersion 30 + } + compileOptions { + coreLibraryDesugaringEnabled true + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + lintOptions { + abortOnError false + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.all { output -> + if (outputFile != null && outputFileName.endsWith('.aar')) { + outputFileName = "${archivesBaseName}-${version}.aar" + } + } + } + + testOptions { + unitTests.returnDefaultValues = true + } +} + +dependencies { + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation "io.swagger:swagger-annotations:$swagger_annotations_version" + implementation "com.google.code.gson:gson:$gson_version" + implementation "com.android.volley:volley:${volley_version}" + testImplementation "junit:junit:$junit_version" + testImplementation "org.robolectric:robolectric:${robolectric_version}" + testImplementation "net.jodah:concurrentunit:${concurrent_unit_version}" +} + +afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDirectory = project.file("${project.buildDir}/outputs/jar") + task.archiveFileName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } +} + diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/docs/DefaultApi.md b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/docs/DefaultApi.md new file mode 100644 index 00000000000..ca2435532ad --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/docs/DefaultApi.md @@ -0,0 +1,45 @@ +# DefaultApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**idsGet**](DefaultApi.md#idsGet) | **GET** /{ids} | + + + + + +### Example +```kotlin +// Import classes: +//import org.openapitools.client.* +//import org.openapitools.client.infrastructure.* +//import org.openapitools.client.models.* + +val apiClient = ApiClient() +val webService = apiClient.createWebservice(DefaultApi::class.java) +val ids : kotlin.collections.List = // kotlin.collections.List | + +webService.idsGet(ids) +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **ids** | [**kotlin.collections.List<kotlin.String>**](kotlin.String.md)| | + +### Return type + +null (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradle.properties b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradle.properties new file mode 100644 index 00000000000..5bac8ac5046 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradle.properties @@ -0,0 +1 @@ +android.useAndroidX=true diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradle/wrapper/gradle-wrapper.jar b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..e708b1c023e Binary files /dev/null and b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradle/wrapper/gradle-wrapper.properties b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..8cf6eb5ad22 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradlew b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradlew new file mode 100644 index 00000000000..4f906e0c811 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradlew.bat b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradlew.bat new file mode 100644 index 00000000000..107acd32c4e --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/settings.gradle b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/settings.gradle new file mode 100644 index 00000000000..796d7067213 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/settings.gradle @@ -0,0 +1,2 @@ + +rootProject.name = 'kotlin-array-simple-string-jvm-volley' \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/AndroidManifest.xml b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..90fc37cd891 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt new file mode 100644 index 00000000000..488d764d6f0 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -0,0 +1,96 @@ +package org.openapitools.client.apis + +import android.content.Context +import com.android.volley.DefaultRetryPolicy +import com.android.volley.Request +import com.android.volley.RequestQueue +import com.android.volley.Response +import com.android.volley.toolbox.BaseHttpStack +import com.android.volley.toolbox.Volley +import java.util.* +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException +import kotlin.coroutines.suspendCoroutine +import com.google.gson.reflect.TypeToken + +import org.openapitools.client.request.IRequestFactory +import org.openapitools.client.request.RequestFactory +import org.openapitools.client.infrastructure.CollectionFormats.* + + +/* +* If you wish to use a custom http stack with your client you +* can pass that to the request queue like: +* Volley.newRequestQueue(context.applicationContext, myCustomHttpStack) +*/ +class DefaultApi ( + private val context: Context, + private val requestQueue: Lazy = lazy(initializer = { + Volley.newRequestQueue(context.applicationContext) + }), + private val requestFactory: IRequestFactory = RequestFactory(), + private val basePath: String = "http://localhost", + private val postProcessors :List <(Request<*>) -> Unit> = listOf()) { + + /** + * + * + * @param ids + * @return void + */ + suspend fun idsGet(ids: kotlin.collections.List): Unit { + val body: Any? = null + + val contentTypes : Array = arrayOf() + val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } + + // Do some work or avoid some work based on what we know about the model, + // before we delegate to a pluggable request factory template + // The request factory template contains only pure code and no templates + // to make it easy to override with your own. + + // create path and map variables + val path = "/{ids}".replace("{" + "ids" + "}", ids.joinToString(",")) + + val formParams = mapOf() + + + // TODO: Cater for allowing empty values + // TODO, if its apikey auth, then add the header names here and the hardcoded auth key + // Only support hard coded apikey in query param auth for when we do this first path + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } + + val headerParams: Map = mapOf() + + return suspendCoroutine { continuation -> + val responseListener = Response.Listener { response -> + continuation.resume(response) + } + + val errorListener = Response.ErrorListener { error -> + continuation.resumeWithException(error) + } + + val responseType = object : TypeToken() {}.type + + // Call the correct request builder based on whether we have a return type or a body. + // All other switching on types must be done in code inside the builder + val request: Request = requestFactory.build( + Request.Method.GET, + "$basePath$path", + body, + headerParams, + queryParams, + formParams, + contentType, + responseType, + responseListener, + errorListener) + + postProcessors.forEach { it.invoke(request) } + + requestQueue.value.add(request) + } + } +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt new file mode 100644 index 00000000000..6120b081929 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt @@ -0,0 +1,33 @@ +package org.openapitools.client.infrastructure + +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonWriter +import com.google.gson.stream.JsonToken.NULL +import java.io.IOException + +class ByteArrayAdapter : TypeAdapter() { + @Throws(IOException::class) + override fun write(out: JsonWriter?, value: ByteArray?) { + if (value == null) { + out?.nullValue() + } else { + out?.value(String(value)) + } + } + + @Throws(IOException::class) + override fun read(out: JsonReader?): ByteArray? { + out ?: return null + + when (out.peek()) { + NULL -> { + out.nextNull() + return null + } + else -> { + return out.nextString().toByteArray() + } + } + } +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/CollectionFormats.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/CollectionFormats.kt new file mode 100644 index 00000000000..001e99325d2 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/CollectionFormats.kt @@ -0,0 +1,56 @@ +package org.openapitools.client.infrastructure + +class CollectionFormats { + + open class CSVParams { + + var params: List + + constructor(params: List) { + this.params = params + } + + constructor(vararg params: String) { + this.params = listOf(*params) + } + + override fun toString(): String { + return params.joinToString(",") + } + } + + open class SSVParams : CSVParams { + + constructor(params: List) : super(params) + + constructor(vararg params: String) : super(*params) + + override fun toString(): String { + return params.joinToString(" ") + } + } + + class TSVParams : CSVParams { + + constructor(params: List) : super(params) + + constructor(vararg params: String) : super(*params) + + override fun toString(): String { + return params.joinToString("\t") + } + } + + class PIPESParams : CSVParams { + + constructor(params: List) : super(params) + + constructor(vararg params: String) : super(*params) + + override fun toString(): String { + return params.joinToString("|") + } + } + + class SPACEParams : SSVParams() +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt new file mode 100644 index 00000000000..30ef6697183 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt @@ -0,0 +1,35 @@ +package org.openapitools.client.infrastructure + +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonWriter +import com.google.gson.stream.JsonToken.NULL +import java.io.IOException +import java.time.LocalDate +import java.time.format.DateTimeFormatter + +class LocalDateAdapter(private val formatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE) : TypeAdapter() { + @Throws(IOException::class) + override fun write(out: JsonWriter?, value: LocalDate?) { + if (value == null) { + out?.nullValue() + } else { + out?.value(formatter.format(value)) + } + } + + @Throws(IOException::class) + override fun read(out: JsonReader?): LocalDate? { + out ?: return null + + when (out.peek()) { + NULL -> { + out.nextNull() + return null + } + else -> { + return LocalDate.parse(out.nextString(), formatter) + } + } + } +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt new file mode 100644 index 00000000000..3ad781c66ca --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt @@ -0,0 +1,35 @@ +package org.openapitools.client.infrastructure + +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonWriter +import com.google.gson.stream.JsonToken.NULL +import java.io.IOException +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter + +class LocalDateTimeAdapter(private val formatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME) : TypeAdapter() { + @Throws(IOException::class) + override fun write(out: JsonWriter?, value: LocalDateTime?) { + if (value == null) { + out?.nullValue() + } else { + out?.value(formatter.format(value)) + } + } + + @Throws(IOException::class) + override fun read(out: JsonReader?): LocalDateTime? { + out ?: return null + + when (out.peek()) { + NULL -> { + out.nextNull() + return null + } + else -> { + return LocalDateTime.parse(out.nextString(), formatter) + } + } + } +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt new file mode 100644 index 00000000000..e615135c9cc --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt @@ -0,0 +1,35 @@ +package org.openapitools.client.infrastructure + +import com.google.gson.TypeAdapter +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonWriter +import com.google.gson.stream.JsonToken.NULL +import java.io.IOException +import java.time.OffsetDateTime +import java.time.format.DateTimeFormatter + +class OffsetDateTimeAdapter(private val formatter: DateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME) : TypeAdapter() { + @Throws(IOException::class) + override fun write(out: JsonWriter?, value: OffsetDateTime?) { + if (value == null) { + out?.nullValue() + } else { + out?.value(formatter.format(value)) + } + } + + @Throws(IOException::class) + override fun read(out: JsonReader?): OffsetDateTime? { + out ?: return null + + when (out.peek()) { + NULL -> { + out.nextNull() + return null + } + else -> { + return OffsetDateTime.parse(out.nextString(), formatter) + } + } + } +} diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/request/GsonRequest.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/request/GsonRequest.kt new file mode 100644 index 00000000000..965eeae66e2 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/request/GsonRequest.kt @@ -0,0 +1,119 @@ +package org.openapitools.client.request + +import com.android.volley.NetworkResponse +import com.android.volley.ParseError +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.HttpHeaderParser +import com.google.gson.Gson +import com.google.gson.GsonBuilder +import com.google.gson.JsonSyntaxException +import java.io.UnsupportedEncodingException +import java.nio.charset.Charset +import java.net.HttpURLConnection +import java.lang.reflect.Type +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.OffsetDateTime + +import org.openapitools.client.infrastructure.OffsetDateTimeAdapter +import org.openapitools.client.infrastructure.LocalDateTimeAdapter +import org.openapitools.client.infrastructure.LocalDateAdapter +import org.openapitools.client.infrastructure.ByteArrayAdapter + +class GsonRequest( + method: Int, + url: String, + private val body: Any?, + private val headers: Map?, + private val params: MutableMap?, + private val contentTypeForBody: String?, + private val encodingForParams: String?, + private val gsonAdapters: Map?, + private val type: Type, + private val listener: Response.Listener, + errorListener: Response.ErrorListener +) : Request(method, url, errorListener) { + + val gsonBuilder: GsonBuilder = GsonBuilder() + .registerTypeAdapter(OffsetDateTime::class.java, OffsetDateTimeAdapter()) + .registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeAdapter()) + .registerTypeAdapter(LocalDate::class.java, LocalDateAdapter()) + .registerTypeAdapter(ByteArray::class.java, ByteArrayAdapter()) + .apply { + gsonAdapters?.forEach { + this.registerTypeAdapter(it.key, it.value) + } + } + + val gson: Gson by lazy { + gsonBuilder.create() + } + + private var response: NetworkResponse? = null + + override fun deliverResponse(response: T?) { + listener.onResponse(response) + } + + override fun getParams(): MutableMap? = params ?: super.getParams() + + override fun getBodyContentType(): String = contentTypeForBody ?: super.getBodyContentType() + + override fun getParamsEncoding(): String = encodingForParams ?: super.getParamsEncoding() + + override fun getHeaders(): MutableMap { + val combined = HashMap() + combined.putAll(super.getHeaders()) + if (headers != null) { + combined.putAll(headers) + } + return combined + } + + override fun getBody(): ByteArray? { + if (body != null) { + return gson.toJson(body).toByteArray(Charsets.UTF_8) + } + return super.getBody() + } + + override fun parseNetworkResponse(response: NetworkResponse?): Response { + return try { + this.response = copyTo(response) + val json = String( + response?.data ?: ByteArray(0), + Charset.forName(HttpHeaderParser.parseCharset(response?.headers)) + ) + Response.success( + gson.fromJson(json, type), + HttpHeaderParser.parseCacheHeaders(response) + ) + } catch (e: UnsupportedEncodingException) { + Response.error(ParseError(e)) + } catch (e: JsonSyntaxException) { + Response.error(ParseError(e)) + } + } + + private fun copyTo(response: NetworkResponse?): NetworkResponse { + return if (response != null) { + NetworkResponse( + response.statusCode, + response.data, + response.notModified, + response.networkTimeMs, + response.allHeaders + ) + } else { + // Return an empty response. + NetworkResponse( + HttpURLConnection.HTTP_BAD_METHOD, + ByteArray(0), + false, + 0, + emptyList() + ) + } + } +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/request/IRequestFactory.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/request/IRequestFactory.kt new file mode 100644 index 00000000000..599db0bc0de --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/request/IRequestFactory.kt @@ -0,0 +1,64 @@ +package org.openapitools.client.request + +import com.android.volley.Request +import com.android.volley.Response +import java.io.UnsupportedEncodingException +import java.lang.reflect.Type +import java.net.URLEncoder +import java.text.ParseException +import java.text.SimpleDateFormat +import java.util.* +import java.time.format.DateTimeFormatter +import java.time.OffsetDateTime +import java.time.LocalDate + + +interface IRequestFactory { + + companion object { + /** + * ISO 8601 date time format. + * @see https://en.wikipedia.org/wiki/ISO_8601 + */ + fun formatDateTime(datetime: OffsetDateTime) = DateTimeFormatter.ISO_INSTANT.format(datetime) + fun formatDate(date: LocalDate) = DateTimeFormatter.ISO_LOCAL_DATE.format(date) + + fun escapeString(str: String): String { + return try { + URLEncoder.encode(str, "UTF-8") + } catch (e: UnsupportedEncodingException) { + str + } + } + + fun parameterToString(param: Any?) = + when (param) { + null -> "" + is OffsetDateTime -> formatDateTime(param) + is Collection<*> -> { + val b = StringBuilder() + for (o in param) { + if (b.isNotEmpty()) { + b.append(",") + } + b.append(o.toString()) + } + b.toString() + } + else -> param.toString() + } + } + + + fun build( + method: Int, + url : String, + body: Any?, + headers: Map?, + queryParams: Map?, + formParams: Map?, + contentTypeForBody: String?, + type: Type, + responseListener: Response.Listener, + errorListener: Response.ErrorListener): Request +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/request/RequestFactory.kt b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/request/RequestFactory.kt new file mode 100644 index 00000000000..b32f9ba2f15 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-jvm-volley/src/main/kotlin/org/openapitools/client/request/RequestFactory.kt @@ -0,0 +1,62 @@ +// Knowing the details of an operation it will produce a call to a Volley Request constructor +package org.openapitools.client.request + + +import com.android.volley.Request +import com.android.volley.Response +import org.openapitools.client.request.IRequestFactory.Companion.escapeString +import java.lang.reflect.Type +import java.util.Locale +import java.util.UUID + +class RequestFactory(private val headerFactories : List<() -> Map> = listOf(), private val postProcessors :List <(Request<*>) -> Unit> = listOf(), private val gsonAdapters: Map = mapOf()): IRequestFactory { + + /** + * {@inheritDoc} + */ + @Suppress("UNCHECKED_CAST") + override fun build( + method: Int, + url: String, + body: Any?, + headers: Map?, + queryParams: Map?, + formParams: Map?, + contentTypeForBody: String?, + type: Type, + responseListener: Response.Listener, + errorListener: Response.ErrorListener + ): Request { + val afterMarketHeaders = (headers?.toMutableMap() ?: mutableMapOf()) + // Factory built and aftermarket + // Merge the after market headers on top of the base ones in case we are overriding per call auth + val allHeaders = headerFactories.fold(afterMarketHeaders) { acc, factory -> (acc + factory.invoke()).toMutableMap() } + + // If we decide to support auth parameters in the url, then you will reference them by supplying a url string + // with known variable name refernces in the string. We will then apply + val updatedUrl = if (!queryParams.isNullOrEmpty()) { + queryParams.asSequence().fold("$url?") {acc, param -> + "$acc${escapeString(param.key)}=${escapeString(param.value)}&" + }.trimEnd('&') + } else { + url + } + + val request = GsonRequest( + method, + updatedUrl, + body, + allHeaders, + formParams?.toMutableMap(), + contentTypeForBody, + null, + gsonAdapters, + type, + responseListener, + errorListener) + + postProcessors.forEach{ it.invoke(request)} + + return request + } +} diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/.openapi-generator-ignore b/samples/client/petstore/kotlin-array-simple-string-multiplatform/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/.openapi-generator/FILES b/samples/client/petstore/kotlin-array-simple-string-multiplatform/.openapi-generator/FILES new file mode 100644 index 00000000000..6d9189fa063 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/.openapi-generator/FILES @@ -0,0 +1,27 @@ +README.md +build.gradle.kts +docs/DefaultApi.md +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +settings.gradle.kts +src/commonTest/kotlin/util/Coroutine.kt +src/iosTest/kotlin/util/Coroutine.kt +src/jsTest/kotlin/util/Coroutine.kt +src/jvmTest/kotlin/util/Coroutine.kt +src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +src/main/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt +src/main/kotlin/org/openapitools/client/auth/Authentication.kt +src/main/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt +src/main/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt +src/main/kotlin/org/openapitools/client/auth/OAuth.kt +src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +src/main/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt +src/main/kotlin/org/openapitools/client/infrastructure/Bytes.kt +src/main/kotlin/org/openapitools/client/infrastructure/HttpResponse.kt +src/main/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt +src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt +src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/.openapi-generator/VERSION b/samples/client/petstore/kotlin-array-simple-string-multiplatform/.openapi-generator/VERSION new file mode 100644 index 00000000000..5f68295fc19 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/README.md b/samples/client/petstore/kotlin-array-simple-string-multiplatform/README.md new file mode 100644 index 00000000000..f89fa402800 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/README.md @@ -0,0 +1,40 @@ +# org.openapitools.client - Kotlin client library for Demo + +## Requires + +* Kotlin 1.5.10 + +## Build + +``` +./gradlew check assemble +``` + +This runs all tests and packages the library. + +## Features/Implementation Notes + +* Supports JSON inputs/outputs, File inputs, and Form inputs. +* Supports collection formats for query parameters: csv, tsv, ssv, pipes. +* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions. + + + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**idsGet**](docs/DefaultApi.md#idsget) | **GET** /{ids} | + + + +## Documentation for Models + + + + +## Documentation for Authorization + +All endpoints do not require authorization. diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/build.gradle.kts b/samples/client/petstore/kotlin-array-simple-string-multiplatform/build.gradle.kts new file mode 100644 index 00000000000..2380844aa92 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/build.gradle.kts @@ -0,0 +1,99 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget + +plugins { + kotlin("multiplatform") version "1.6.0" // kotlin_version + kotlin("plugin.serialization") version "1.6.0" // kotlin_version +} + +group = "org.openapitools" +version = "1.0.0" + +val kotlin_version = "1.6.0" +val coroutines_version = "1.5.2" +val serialization_version = "1.3.0" +val ktor_version = "1.6.4" + +repositories { + mavenCentral() +} + +kotlin { + jvm() + ios { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } } + js { + browser() + nodejs() + } + + sourceSets { + val commonMain by getting { + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serialization_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") + } + } + + val commonTest by getting { + dependencies { + implementation(kotlin("test")) + implementation("io.ktor:ktor-client-mock:$ktor_version") + } + } + + val jvmMain by getting { + dependencies { + implementation(kotlin("stdlib-jdk7")) + implementation("io.ktor:ktor-client-cio-jvm:$ktor_version") + } + } + + val jvmTest by getting { + dependencies { + implementation(kotlin("test-junit")) + } + } + + val iosMain by getting { + dependencies { + api("io.ktor:ktor-client-ios:$ktor_version") + } + } + + val iosTest by getting + + val jsMain by getting { + dependencies { + api("io.ktor:ktor-client-js:$ktor_version") + } + } + + val jsTest by getting + + all { + languageSettings.apply { + useExperimentalAnnotation("kotlin.Experimental") + } + } + } +} + +tasks { + register("iosTest") { + val device = project.findProperty("device")?.toString() ?: "iPhone 8" + dependsOn("linkDebugTestIosX64") + group = JavaBasePlugin.VERIFICATION_GROUP + description = "Execute unit tests on ${device} simulator" + doLast { + val binary = kotlin.targets.getByName("iosX64").binaries.getTest("DEBUG") + exec { + commandLine("xcrun", "simctl", "spawn", device, binary.outputFile) + } + } + } + register("test") { + dependsOn("allTests") + } +} diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/docs/DefaultApi.md b/samples/client/petstore/kotlin-array-simple-string-multiplatform/docs/DefaultApi.md new file mode 100644 index 00000000000..45b43113f19 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/docs/DefaultApi.md @@ -0,0 +1,53 @@ +# DefaultApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**idsGet**](DefaultApi.md#idsGet) | **GET** /{ids} | + + + +# **idsGet** +> idsGet(ids) + + + +### Example +```kotlin +// Import classes: +//import org.openapitools.client.infrastructure.* +//import org.openapitools.client.models.* + +val apiInstance = DefaultApi() +val ids : kotlin.collections.List = // kotlin.collections.List | +try { + apiInstance.idsGet(ids) +} catch (e: ClientException) { + println("4xx response calling DefaultApi#idsGet") + e.printStackTrace() +} catch (e: ServerException) { + println("5xx response calling DefaultApi#idsGet") + e.printStackTrace() +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **ids** | [**kotlin.collections.List<kotlin.String>**](kotlin.String.md)| | + +### Return type + +null (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradle/wrapper/gradle-wrapper.jar b/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..e708b1c023e Binary files /dev/null and b/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradle/wrapper/gradle-wrapper.properties b/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..8cf6eb5ad22 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradlew b/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradlew new file mode 100644 index 00000000000..4f906e0c811 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradlew.bat b/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradlew.bat new file mode 100644 index 00000000000..107acd32c4e --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/settings.gradle.kts b/samples/client/petstore/kotlin-array-simple-string-multiplatform/settings.gradle.kts new file mode 100644 index 00000000000..87502dc7273 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "kotlin-array-simple-string-multiplatform" \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/commonTest/kotlin/util/Coroutine.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/commonTest/kotlin/util/Coroutine.kt new file mode 100644 index 00000000000..110762d355d --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/commonTest/kotlin/util/Coroutine.kt @@ -0,0 +1,32 @@ +/** + * Demo + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + + +package util + +import kotlinx.coroutines.CoroutineScope + +/** +* Block the current thread until execution of the given coroutine is complete. +* +* @param block The coroutine code. +* @return The result of the coroutine. +*/ +internal expect fun runTest(block: suspend CoroutineScope.() -> T): T diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/iosTest/kotlin/util/Coroutine.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/iosTest/kotlin/util/Coroutine.kt new file mode 100644 index 00000000000..51f9803de3c --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/iosTest/kotlin/util/Coroutine.kt @@ -0,0 +1,27 @@ +/** + * Demo + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + + +package util + +import kotlinx.coroutines.CoroutineScope +import kotlin.coroutines.EmptyCoroutineContext + +internal actual fun runTest(block: suspend CoroutineScope.() -> T): T = kotlinx.coroutines.runBlocking(EmptyCoroutineContext, block) diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/jsTest/kotlin/util/Coroutine.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/jsTest/kotlin/util/Coroutine.kt new file mode 100644 index 00000000000..2bea4861f67 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-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-array-simple-string-multiplatform/src/jvmTest/kotlin/util/Coroutine.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/jvmTest/kotlin/util/Coroutine.kt new file mode 100644 index 00000000000..51f9803de3c --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/jvmTest/kotlin/util/Coroutine.kt @@ -0,0 +1,27 @@ +/** + * Demo + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + + +package util + +import kotlinx.coroutines.CoroutineScope +import kotlin.coroutines.EmptyCoroutineContext + +internal actual fun runTest(block: suspend CoroutineScope.() -> T): T = kotlinx.coroutines.runBlocking(EmptyCoroutineContext, block) diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt new file mode 100644 index 00000000000..d79299bb11a --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -0,0 +1,73 @@ +/** + * Demo + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 1.0.0 + * + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.apis + + +import org.openapitools.client.infrastructure.* +import io.ktor.client.HttpClientConfig +import io.ktor.client.request.forms.formData +import io.ktor.client.engine.HttpClientEngine +import io.ktor.client.features.json.serializer.KotlinxSerializer +import kotlinx.serialization.json.Json +import io.ktor.http.ParametersBuilder +import kotlinx.serialization.* +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.* + +open class DefaultApi( + baseUrl: String = ApiClient.BASE_URL, + httpClientEngine: HttpClientEngine? = null, + httpClientConfig: ((HttpClientConfig<*>) -> Unit)? = null, + jsonSerializer: Json = ApiClient.JSON_DEFAULT +) : ApiClient(baseUrl, httpClientEngine, httpClientConfig, jsonSerializer) { + + /** + * + * + * @param ids + * @return void + */ + open suspend fun idsGet(ids: kotlin.collections.List): HttpResponse { + + val localVariableAuthNames = listOf() + + val localVariableBody = + io.ktor.client.utils.EmptyContent + + val localVariableQuery = mutableMapOf>() + val localVariableHeaders = mutableMapOf() + + val localVariableConfig = RequestConfig( + RequestMethod.GET, + "/{ids}".replace("{" + "ids" + "}", ids.joinToString(",")), + query = localVariableQuery, + headers = localVariableHeaders + ) + + return request( + localVariableConfig, + localVariableBody, + localVariableAuthNames + ).wrap() + } + + +} diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt new file mode 100644 index 00000000000..8bd8b59a8f8 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/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-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/auth/Authentication.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/auth/Authentication.kt new file mode 100644 index 00000000000..2c5dfb4acc5 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/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-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt new file mode 100644 index 00000000000..40276dbb985 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/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 + + @OptIn(InternalAPI::class) + 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-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt new file mode 100644 index 00000000000..a6fb285af5c --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/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-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/auth/OAuth.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/auth/OAuth.kt new file mode 100644 index 00000000000..08b289c2944 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/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-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt new file mode 100644 index 00000000000..ef7a8f1e1a6 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -0,0 +1,23 @@ +package org.openapitools.client.infrastructure + +typealias MultiValueMap = MutableMap> + +fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { + "csv" -> "," + "tsv" -> "\t" + "pipe" -> "|" + "space" -> " " + else -> "" +} + +val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" } + +fun toMultiValue(items: Array, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter) + = toMultiValue(items.asIterable(), collectionFormat, map) + +fun toMultiValue(items: Iterable, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List { + return when(collectionFormat) { + "multi" -> items.map(map) + else -> listOf(items.joinToString(separator = collectionDelimiter(collectionFormat), transform = map)) + } +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt new file mode 100644 index 00000000000..77dc28c8146 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -0,0 +1,195 @@ +package org.openapitools.client.infrastructure + +import io.ktor.client.HttpClient +import io.ktor.client.HttpClientConfig +import io.ktor.client.engine.HttpClientEngine +import io.ktor.client.features.json.JsonFeature +import io.ktor.client.features.json.JsonSerializer +import io.ktor.client.features.json.serializer.KotlinxSerializer +import io.ktor.client.request.* +import io.ktor.client.request.forms.FormDataContent +import io.ktor.client.request.forms.MultiPartFormDataContent +import io.ktor.client.request.header +import io.ktor.client.request.parameter +import io.ktor.client.statement.HttpResponse +import io.ktor.client.utils.EmptyContent +import io.ktor.http.* +import io.ktor.http.content.OutgoingContent +import io.ktor.http.content.PartData +import kotlin.Unit +import kotlinx.serialization.json.Json + +import org.openapitools.client.apis.* +import org.openapitools.client.models.* +import org.openapitools.client.auth.* + +open class ApiClient( + private val baseUrl: String, + httpClientEngine: HttpClientEngine?, + httpClientConfig: ((HttpClientConfig<*>) -> Unit)? = null, + private val json: Json +) { + + private val serializer: JsonSerializer by lazy { + KotlinxSerializer(json).ignoreOutgoingContent() + } + + private val clientConfig: (HttpClientConfig<*>) -> Unit by lazy { + { + // Hold a reference to the serializer to avoid freezing the entire ApiClient instance + // when the JsonFeature is configured. + val serializerReference = serializer + it.install(JsonFeature) { serializer = serializerReference } + httpClientConfig?.invoke(it) + } + } + + private val client: HttpClient by lazy { + httpClientEngine?.let { HttpClient(it, clientConfig) } ?: HttpClient(clientConfig) + } + + private val authentications: kotlin.collections.Map? = null + + companion object { + const val BASE_URL = "http://localhost" + val JSON_DEFAULT = Json { ignoreUnknownKeys = true } + protected val UNSAFE_HEADERS = listOf(HttpHeaders.ContentType) + } + + /** + * 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 + } + + /** + * 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 + } + + /** + * 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), authNames) + else request(requestConfig, authNames = authNames) + } + + protected suspend fun request(requestConfig: RequestConfig, body: OutgoingContent = EmptyContent, authNames: kotlin.collections.List): HttpResponse { + requestConfig.updateForAuth(authNames) + val headers = requestConfig.headers + + return client.request { + this.url { + this.takeFrom(URLBuilder(baseUrl)) + appendPath(requestConfig.path.trimStart('/').split('/')) + requestConfig.query.forEach { query -> + query.value.forEach { value -> + parameter(query.key, value) + } + } + } + this.method = requestConfig.method.httpMethod + headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) } + if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) + this.body = body + + } + } + + private fun RequestConfig.updateForAuth(authNames: kotlin.collections.List) { + for (authName in authNames) { + val auth = authentications?.get(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() } + } + + private val RequestMethod.httpMethod: HttpMethod + get() = when (this) { + RequestMethod.DELETE -> HttpMethod.Delete + RequestMethod.GET -> HttpMethod.Get + RequestMethod.HEAD -> HttpMethod.Head + RequestMethod.PATCH -> HttpMethod.Patch + RequestMethod.PUT -> HttpMethod.Put + RequestMethod.POST -> HttpMethod.Post + RequestMethod.OPTIONS -> HttpMethod.Options + } +} + +// https://github.com/ktorio/ktor/issues/851 +private fun JsonSerializer.ignoreOutgoingContent() = IgnoreOutgoingContentJsonSerializer(this) + +private class IgnoreOutgoingContentJsonSerializer(private val delegate: JsonSerializer) : JsonSerializer by delegate { + override fun write(data: Any): OutgoingContent { + if (data is OutgoingContent) return data + return delegate.write(data) + } +} diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt new file mode 100644 index 00000000000..7c635c14fdd --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt @@ -0,0 +1,30 @@ +package org.openapitools.client.infrastructure + +import kotlinx.serialization.* +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.* + +@Serializable +class Base64ByteArray(val value: ByteArray) { + @Serializer(Base64ByteArray::class) + companion object : KSerializer { + override val descriptor = PrimitiveSerialDescriptor("Base64ByteArray", PrimitiveKind.STRING) + 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-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/Bytes.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/Bytes.kt new file mode 100644 index 00000000000..7d30ce18fcf --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/Bytes.kt @@ -0,0 +1,100 @@ +package org.openapitools.client.infrastructure + +import io.ktor.utils.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 result.concatToString() +} + +/** + * 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-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/HttpResponse.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/HttpResponse.kt new file mode 100644 index 00000000000..61e55bc5b15 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/HttpResponse.kt @@ -0,0 +1,51 @@ +package org.openapitools.client.infrastructure + +import io.ktor.client.call.TypeInfo +import io.ktor.client.call.typeInfo +import io.ktor.http.Headers +import io.ktor.http.isSuccess + +open class HttpResponse(val response: io.ktor.client.statement.HttpResponse, val provider: BodyProvider) { + val status: Int = response.status.value + val success: Boolean = response.status.isSuccess() + val headers: Map> = response.headers.mapEntries() + suspend fun body(): T = provider.body(response) + suspend fun typedBody(type: TypeInfo): V = provider.typedBody(response, type) + + companion object { + private fun Headers.mapEntries(): Map> { + val result = mutableMapOf>() + entries().forEach { result[it.key] = it.value } + return result + } + } +} + +interface BodyProvider { + suspend fun body(response: io.ktor.client.statement.HttpResponse): T + suspend fun typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V +} + +class TypedBodyProvider(private val type: TypeInfo) : BodyProvider { + @Suppress("UNCHECKED_CAST") + override suspend fun body(response: io.ktor.client.statement.HttpResponse): T = + response.call.receive(type) as T + + @Suppress("UNCHECKED_CAST") + override suspend fun typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V = + response.call.receive(type) as V +} + +class MappedBodyProvider(private val provider: BodyProvider, private val block: S.() -> T) : BodyProvider { + override suspend fun body(response: io.ktor.client.statement.HttpResponse): T = + block(provider.body(response)) + + override suspend fun typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V = + provider.typedBody(response, type) +} + +inline fun io.ktor.client.statement.HttpResponse.wrap(): HttpResponse = + HttpResponse(this, TypedBodyProvider(typeInfo())) + +fun HttpResponse.map(block: T.() -> V): HttpResponse = + HttpResponse(response, MappedBodyProvider(provider, block)) diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt new file mode 100644 index 00000000000..04c88673331 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt @@ -0,0 +1,30 @@ +package org.openapitools.client.infrastructure + +import kotlinx.serialization.* +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.* + +@Serializable +class OctetByteArray(val value: ByteArray) { + @Serializer(OctetByteArray::class) + companion object : KSerializer { + override val descriptor = PrimitiveSerialDescriptor("OctetByteArray", PrimitiveKind.STRING) + 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-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt new file mode 100644 index 00000000000..be00e38fbae --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt @@ -0,0 +1,11 @@ +package org.openapitools.client.infrastructure + +/** + * Defines a config object for a given part of a multi-part request. + * NOTE: Headers is a Map because rfc2616 defines + * multi-valued headers as csv-only. + */ +data class PartConfig( + val headers: MutableMap = mutableMapOf(), + val body: T? = null +) diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt new file mode 100644 index 00000000000..7e948e1dd07 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -0,0 +1,17 @@ +package org.openapitools.client.infrastructure + +/** + * Defines a config object for a given request. + * NOTE: This object doesn't include 'body' because it + * allows for caching of the constructed object + * for many request definitions. + * NOTE: Headers is a Map because rfc2616 defines + * multi-valued headers as csv-only. + */ +data class RequestConfig( + val method: RequestMethod, + val path: String, + val headers: MutableMap = mutableMapOf(), + val query: MutableMap> = mutableMapOf(), + val body: T? = null +) \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt new file mode 100644 index 00000000000..931b12b8bd7 --- /dev/null +++ b/samples/client/petstore/kotlin-array-simple-string-multiplatform/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt @@ -0,0 +1,8 @@ +package org.openapitools.client.infrastructure + +/** + * Provides enumerated HTTP verbs + */ +enum class RequestMethod { + GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT +} \ No newline at end of file diff --git a/samples/client/petstore/kotlin-array-simple-string/settings.gradle b/samples/client/petstore/kotlin-array-simple-string/settings.gradle deleted file mode 100644 index 646809e89a5..00000000000 --- a/samples/client/petstore/kotlin-array-simple-string/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ - -rootProject.name = 'kotlin-array-simple-string' \ No newline at end of file diff --git a/samples/client/petstore/kotlin-bigdecimal-default-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-bigdecimal-default-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 7e61f11c13e..8daf4379155 100644 --- a/samples/client/petstore/kotlin-bigdecimal-default-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-bigdecimal-default-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -53,7 +53,6 @@ open class DefaultApi( val localVariableBody = apa val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( diff --git a/samples/client/petstore/kotlin-bigdecimal-default/docs/Apa.md b/samples/client/petstore/kotlin-bigdecimal-default/docs/Apa.md deleted file mode 100644 index 2831e9acf48..00000000000 --- a/samples/client/petstore/kotlin-bigdecimal-default/docs/Apa.md +++ /dev/null @@ -1,15 +0,0 @@ - -# Apa - -## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**bepa** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | | -**cepa** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | | -**depa** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | | [optional] -**epa** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | | [optional] -**fepa** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | | [optional] -**gepa** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | | [optional] - - - diff --git a/samples/client/petstore/kotlin-bigdecimal-default/settings.gradle b/samples/client/petstore/kotlin-bigdecimal-default/settings.gradle deleted file mode 100644 index 0c5a1dc4b94..00000000000 --- a/samples/client/petstore/kotlin-bigdecimal-default/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ - -rootProject.name = 'kotlin-bigdecimal-default' \ No newline at end of file diff --git a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/models/Apa.kt b/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/models/Apa.kt deleted file mode 100644 index 574811c7f1f..00000000000 --- a/samples/client/petstore/kotlin-bigdecimal-default/src/main/kotlin/org/openapitools/client/models/Apa.kt +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Demo - * - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 1.0.0 - * - * - * Please note: - * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * Do not edit this file manually. - */ - -@file:Suppress( - "ArrayInDataClass", - "EnumEntryName", - "RemoveRedundantQualifierName", - "UnusedImport" -) - -package org.openapitools.client.models - - -import com.squareup.moshi.Json - -/** - * - * - * @param bepa - * @param cepa - * @param depa - * @param epa - * @param fepa - * @param gepa - */ - -data class Apa ( - - @Json(name = "bepa") - val bepa: java.math.BigDecimal = java.math.BigDecimal("0"), - - @Json(name = "cepa") - val cepa: java.math.BigDecimal = java.math.BigDecimal("6.28318"), - - @Json(name = "depa") - val depa: java.math.BigDecimal? = java.math.BigDecimal("71"), - - @Json(name = "epa") - val epa: java.math.BigDecimal? = java.math.BigDecimal("-71"), - - @Json(name = "fepa") - @Deprecated(message = "This property is deprecated.") - val fepa: java.math.BigDecimal? = java.math.BigDecimal("100"), - - @Json(name = "gepa") - val gepa: java.math.BigDecimal? = null - -) - diff --git a/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 7e1a3739da1..66d79abe35a 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -41,13 +41,9 @@ class ApiClient( private val defaultClientBuilder: OkHttpClient.Builder by lazy { OkHttpClient() .newBuilder() - .addInterceptor(HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { - override fun log(message: String) { - logger?.invoke(message) - } - }).apply { - level = HttpLoggingInterceptor.Level.BODY - }) + .addInterceptor(HttpLoggingInterceptor { message -> logger?.invoke(message) } + .apply { level = HttpLoggingInterceptor.Level.BODY } + ) } init { diff --git a/samples/client/petstore/kotlin-default-values-jvm-volley/build.gradle b/samples/client/petstore/kotlin-default-values-jvm-volley/build.gradle index 6a369e59948..1777a3938b1 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-volley/build.gradle +++ b/samples/client/petstore/kotlin-default-values-jvm-volley/build.gradle @@ -2,17 +2,11 @@ buildscript { ext.kotlin_version = '1.5.10' - ext.swagger_annotations_version = "1.6.2" - ext.gson_version = "2.8.6" - ext.volley_version = "1.2.0" - ext.junit_version = "4.13.2" - ext.robolectric_version = "4.5.1" - ext.concurrent_unit_version = "0.4.6" repositories { diff --git a/samples/client/petstore/kotlin-default-values-jvm-volley/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-default-values-jvm-volley/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 13cf7117a52..29523534383 100644 --- a/samples/client/petstore/kotlin-default-values-jvm-volley/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-default-values-jvm-volley/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -7,7 +7,7 @@ import com.android.volley.RequestQueue import com.android.volley.Response import com.android.volley.toolbox.BaseHttpStack import com.android.volley.toolbox.Volley -import java.util.*; +import java.util.* import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine @@ -67,76 +67,27 @@ class DefaultApi ( */ suspend fun test(pi0: kotlin.Int = 10, pi1: kotlin.Int, pn0: java.math.BigDecimal = java.math.BigDecimal("10.0"), pn1: java.math.BigDecimal, qi0: kotlin.Int? = 10, qi1: kotlin.Int = 71, qi2: kotlin.Int? = null, qi3: kotlin.Int, qn0: java.math.BigDecimal? = java.math.BigDecimal("10.0"), qn1: java.math.BigDecimal = java.math.BigDecimal("71.0"), qn2: java.math.BigDecimal? = null, qn3: java.math.BigDecimal, hi0: kotlin.Int? = 10, hi1: kotlin.Int = 71, hi2: kotlin.Int? = null, hi3: kotlin.Int, hn0: java.math.BigDecimal? = java.math.BigDecimal("10.0"), hn1: java.math.BigDecimal = java.math.BigDecimal("71.0"), hn2: java.math.BigDecimal? = null, hn3: java.math.BigDecimal, fi0: kotlin.Int? = 10, fi1: kotlin.Int = 71, fi2: kotlin.Int? = null, fi3: kotlin.Int, fn0: java.math.BigDecimal? = java.math.BigDecimal("10.0"), fn1: java.math.BigDecimal = java.math.BigDecimal("71.0"), fn2: java.math.BigDecimal? = null, fn3: java.math.BigDecimal): Unit { val body: Any? = null - // verify the required parameter 'pi0' is set - // This is probably taken care of by non-null types anyway - requireNotNull(pi0) - // verify the required parameter 'pi1' is set - // This is probably taken care of by non-null types anyway - requireNotNull(pi1) - // verify the required parameter 'pn0' is set - // This is probably taken care of by non-null types anyway - requireNotNull(pn0) - // verify the required parameter 'pn1' is set - // This is probably taken care of by non-null types anyway - requireNotNull(pn1) - // verify the required parameter 'qi1' is set - // This is probably taken care of by non-null types anyway - requireNotNull(qi1) - // verify the required parameter 'qi3' is set - // This is probably taken care of by non-null types anyway - requireNotNull(qi3) - // verify the required parameter 'qn1' is set - // This is probably taken care of by non-null types anyway - requireNotNull(qn1) - // verify the required parameter 'qn3' is set - // This is probably taken care of by non-null types anyway - requireNotNull(qn3) - // verify the required parameter 'hi1' is set - // This is probably taken care of by non-null types anyway - requireNotNull(hi1) - // verify the required parameter 'hi3' is set - // This is probably taken care of by non-null types anyway - requireNotNull(hi3) - // verify the required parameter 'hn1' is set - // This is probably taken care of by non-null types anyway - requireNotNull(hn1) - // verify the required parameter 'hn3' is set - // This is probably taken care of by non-null types anyway - requireNotNull(hn3) - // verify the required parameter 'fi1' is set - // This is probably taken care of by non-null types anyway - requireNotNull(fi1) - // verify the required parameter 'fi3' is set - // This is probably taken care of by non-null types anyway - requireNotNull(fi3) - // verify the required parameter 'fn1' is set - // This is probably taken care of by non-null types anyway - requireNotNull(fn1) - // verify the required parameter 'fn3' is set - // This is probably taken care of by non-null types anyway - requireNotNull(fn3) val contentTypes : Array = arrayOf("multipart/form-data") val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/test".replace("{" + "pi0" + "}", IRequestFactory.escapeString(pi0.toString())).replace("{" + "pi1" + "}", IRequestFactory.escapeString(pi1.toString())).replace("{" + "pn0" + "}", IRequestFactory.escapeString(pn0.toString())).replace("{" + "pn1" + "}", IRequestFactory.escapeString(pn1.toString())); + val path = "/test".replace("{" + "pi0" + "}", IRequestFactory.escapeString(pi0.toString())).replace("{" + "pi1" + "}", IRequestFactory.escapeString(pi1.toString())).replace("{" + "pn0" + "}", IRequestFactory.escapeString(pn0.toString())).replace("{" + "pn1" + "}", IRequestFactory.escapeString(pn1.toString())) - // form params val formParams = mapOf( - "fi0" to IRequestFactory.parameterToString(fi0), - "fi1" to IRequestFactory.parameterToString(fi1), - "fi2" to IRequestFactory.parameterToString(fi2), - "fi3" to IRequestFactory.parameterToString(fi3), - "fn0" to IRequestFactory.parameterToString(fn0), - "fn1" to IRequestFactory.parameterToString(fn1), - "fn2" to IRequestFactory.parameterToString(fn2), - "fn3" to IRequestFactory.parameterToString(fn3), + "fi0" to IRequestFactory.parameterToString(fi0), + "fi1" to IRequestFactory.parameterToString(fi1), + "fi2" to IRequestFactory.parameterToString(fi2), + "fi3" to IRequestFactory.parameterToString(fi3), + "fn0" to IRequestFactory.parameterToString(fn0), + "fn1" to IRequestFactory.parameterToString(fn1), + "fn2" to IRequestFactory.parameterToString(fn2), + "fn3" to IRequestFactory.parameterToString(fn3) ) @@ -144,15 +95,16 @@ class DefaultApi ( // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path val queryParams = mapOf( - "qi0" to IRequestFactory.parameterToString(qi0), - "qi1" to IRequestFactory.parameterToString(qi1), - "qi2" to IRequestFactory.parameterToString(qi2), - "qi3" to IRequestFactory.parameterToString(qi3), - "qn0" to IRequestFactory.parameterToString(qn0), - "qn1" to IRequestFactory.parameterToString(qn1), - "qn2" to IRequestFactory.parameterToString(qn2), - "qn3" to IRequestFactory.parameterToString(qn3), - ).filter { it.value.isNotEmpty() } + "qi0" to IRequestFactory.parameterToString(qi0), + "qi1" to IRequestFactory.parameterToString(qi1), + "qi2" to IRequestFactory.parameterToString(qi2), + "qi3" to IRequestFactory.parameterToString(qi3), + "qn0" to IRequestFactory.parameterToString(qn0), + "qn1" to IRequestFactory.parameterToString(qn1), + "qn2" to IRequestFactory.parameterToString(qn2), + "qn3" to IRequestFactory.parameterToString(qn3) + ) + .filter { it.value.isNotEmpty() } val headerParams: Map = mapOf( "hi0" to IRequestFactory.parameterToString(hi0), @@ -162,7 +114,7 @@ class DefaultApi ( "hn0" to IRequestFactory.parameterToString(hn0), "hn1" to IRequestFactory.parameterToString(hn1), "hn2" to IRequestFactory.parameterToString(hn2), - "hn3" to IRequestFactory.parameterToString(hn3), + "hn3" to IRequestFactory.parameterToString(hn3) ) return suspendCoroutine { continuation -> @@ -190,7 +142,7 @@ class DefaultApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } diff --git a/samples/client/petstore/kotlin-default-values-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/samples/client/petstore/kotlin-default-values-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt index 933c2e29032..6f47869c5a0 100644 --- a/samples/client/petstore/kotlin-default-values-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +++ b/samples/client/petstore/kotlin-default-values-multiplatform/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -97,7 +97,6 @@ open class DefaultApi( qn1?.apply { localVariableQuery["qn1"] = listOf("$qn1") } qn2?.apply { localVariableQuery["qn2"] = listOf("$qn2") } qn3?.apply { localVariableQuery["qn3"] = listOf("$qn3") } - val localVariableHeaders = mutableMapOf() hi0?.apply { localVariableHeaders["hi0"] = this.toString() } hi1?.apply { localVariableHeaders["hi1"] = this.toString() } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index c4298d8a43a..dc98058fae3 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -194,8 +194,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { enum class Status_findPetsByStatus(val value: kotlin.String) { @SerializedName(value = "available") available("available"), @SerializedName(value = "pending") pending("pending"), - @SerializedName(value = "sold") sold("sold"), - ; + @SerializedName(value = "sold") sold("sold") } /** diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 99547499d7c..5cae3976f4d 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -194,8 +194,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { enum class Status_findPetsByStatus(val value: kotlin.String) { @JsonProperty(value = "available") AVAILABLE("available"), @JsonProperty(value = "pending") PENDING("pending"), - @JsonProperty(value = "sold") SOLD("sold"), - ; + @JsonProperty(value = "sold") SOLD("sold") } /** diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 0ad9f7191b2..30fbf33ea83 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -196,8 +196,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { enum class Status_findPetsByStatus(val value: kotlin.String) { @SerializedName(value = "available") available("available"), @SerializedName(value = "pending") pending("pending"), - @SerializedName(value = "sold") sold("sold"), - ; + @SerializedName(value = "sold") sold("sold") } /** diff --git a/samples/client/petstore/kotlin-jvm-volley/build.gradle b/samples/client/petstore/kotlin-jvm-volley/build.gradle index 6a369e59948..1777a3938b1 100644 --- a/samples/client/petstore/kotlin-jvm-volley/build.gradle +++ b/samples/client/petstore/kotlin-jvm-volley/build.gradle @@ -2,17 +2,11 @@ buildscript { ext.kotlin_version = '1.5.10' - ext.swagger_annotations_version = "1.6.2" - ext.gson_version = "2.8.6" - ext.volley_version = "1.2.0" - ext.junit_version = "4.13.2" - ext.robolectric_version = "4.5.1" - ext.concurrent_unit_version = "0.4.6" repositories { diff --git a/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/PetApi.kt index 18c1c24e79f..2385121224e 100644 --- a/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/PetApi.kt @@ -7,7 +7,7 @@ import com.android.volley.RequestQueue import com.android.volley.Response import com.android.volley.toolbox.BaseHttpStack import com.android.volley.toolbox.Volley -import java.util.*; +import java.util.* import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine @@ -42,34 +42,28 @@ class PetApi ( */ suspend fun addPet(body: Pet): Unit { val body: Any? = body - // verify the required parameter 'body' is set - // This is probably taken care of by non-null types anyway - requireNotNull(body) val contentTypes : Array = arrayOf("application/json","application/xml") val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/pet"; + val path = "/pet" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -96,7 +90,7 @@ class PetApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -110,34 +104,29 @@ class PetApi ( */ suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String? = null): Unit { val body: Any? = null - // verify the required parameter 'petId' is set - // This is probably taken care of by non-null types anyway - requireNotNull(petId) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/pet/{petId}".replace("{" + "petId" + "}", IRequestFactory.escapeString(petId.toString())); + val path = "/pet/{petId}".replace("{" + "petId" + "}", IRequestFactory.escapeString(petId.toString())) - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } val headerParams: Map = mapOf( - "api_key" to IRequestFactory.parameterToString(apiKey), + "api_key" to IRequestFactory.parameterToString(apiKey) ) return suspendCoroutine { continuation -> @@ -165,7 +154,7 @@ class PetApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -178,35 +167,30 @@ class PetApi ( */ suspend fun findPetsByStatus(status: CSVParams): kotlin.collections.List? { val body: Any? = null - // verify the required parameter 'status' is set - // This is probably taken care of by non-null types anyway - requireNotNull(status) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/pet/findByStatus"; + val path = "/pet/findByStatus" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path val queryParams = mapOf( - "status" to IRequestFactory.parameterToString(status), - ).filter { it.value.isNotEmpty() } + "status" to IRequestFactory.parameterToString(status) + ) + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener> { response -> @@ -233,7 +217,7 @@ class PetApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -247,35 +231,30 @@ class PetApi ( @Deprecated("This api was deprecated") suspend fun findPetsByTags(tags: CSVParams): kotlin.collections.List? { val body: Any? = null - // verify the required parameter 'tags' is set - // This is probably taken care of by non-null types anyway - requireNotNull(tags) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/pet/findByTags"; + val path = "/pet/findByTags" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path val queryParams = mapOf( - "tags" to IRequestFactory.parameterToString(tags), - ).filter { it.value.isNotEmpty() } + "tags" to IRequestFactory.parameterToString(tags) + ) + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener> { response -> @@ -302,7 +281,7 @@ class PetApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -315,34 +294,28 @@ class PetApi ( */ suspend fun getPetById(petId: kotlin.Long): Pet? { val body: Any? = null - // verify the required parameter 'petId' is set - // This is probably taken care of by non-null types anyway - requireNotNull(petId) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/pet/{petId}".replace("{" + "petId" + "}", IRequestFactory.escapeString(petId.toString())); + val path = "/pet/{petId}".replace("{" + "petId" + "}", IRequestFactory.escapeString(petId.toString())) - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -369,7 +342,7 @@ class PetApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -382,34 +355,28 @@ class PetApi ( */ suspend fun updatePet(body: Pet): Unit { val body: Any? = body - // verify the required parameter 'body' is set - // This is probably taken care of by non-null types anyway - requireNotNull(body) val contentTypes : Array = arrayOf("application/json","application/xml") val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/pet"; + val path = "/pet" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -436,7 +403,7 @@ class PetApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -451,36 +418,31 @@ class PetApi ( */ suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String? = null, status: kotlin.String? = null): Unit { val body: Any? = null - // verify the required parameter 'petId' is set - // This is probably taken care of by non-null types anyway - requireNotNull(petId) val contentTypes : Array = arrayOf("application/x-www-form-urlencoded") val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/pet/{petId}".replace("{" + "petId" + "}", IRequestFactory.escapeString(petId.toString())); + val path = "/pet/{petId}".replace("{" + "petId" + "}", IRequestFactory.escapeString(petId.toString())) - // form params val formParams = mapOf( - "name" to IRequestFactory.parameterToString(name), - "status" to IRequestFactory.parameterToString(status), + "name" to IRequestFactory.parameterToString(name), + "status" to IRequestFactory.parameterToString(status) ) // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -507,7 +469,7 @@ class PetApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -522,36 +484,31 @@ class PetApi ( */ suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String? = null, file: java.io.File? = null): ModelApiResponse? { val body: Any? = null - // verify the required parameter 'petId' is set - // This is probably taken care of by non-null types anyway - requireNotNull(petId) val contentTypes : Array = arrayOf("multipart/form-data") val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/pet/{petId}/uploadImage".replace("{" + "petId" + "}", IRequestFactory.escapeString(petId.toString())); + val path = "/pet/{petId}/uploadImage".replace("{" + "petId" + "}", IRequestFactory.escapeString(petId.toString())) - // form params val formParams = mapOf( - "additionalMetadata" to IRequestFactory.parameterToString(additionalMetadata), - "file" to IRequestFactory.parameterToString(file), + "additionalMetadata" to IRequestFactory.parameterToString(additionalMetadata), + "file" to IRequestFactory.parameterToString(file) ) // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -578,7 +535,7 @@ class PetApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } diff --git a/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/StoreApi.kt index 593b5e39d0d..8c34cfdd291 100644 --- a/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/StoreApi.kt @@ -7,7 +7,7 @@ import com.android.volley.RequestQueue import com.android.volley.Response import com.android.volley.toolbox.BaseHttpStack import com.android.volley.toolbox.Volley -import java.util.*; +import java.util.* import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine @@ -41,34 +41,28 @@ class StoreApi ( */ suspend fun deleteOrder(orderId: kotlin.String): Unit { val body: Any? = null - // verify the required parameter 'orderId' is set - // This is probably taken care of by non-null types anyway - requireNotNull(orderId) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/store/order/{orderId}".replace("{" + "orderId" + "}", IRequestFactory.escapeString(orderId.toString())); + val path = "/store/order/{orderId}".replace("{" + "orderId" + "}", IRequestFactory.escapeString(orderId.toString())) - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -95,7 +89,7 @@ class StoreApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -111,27 +105,24 @@ class StoreApi ( val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/store/inventory"; + val path = "/store/inventory" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener> { response -> @@ -158,7 +149,7 @@ class StoreApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -171,34 +162,28 @@ class StoreApi ( */ suspend fun getOrderById(orderId: kotlin.Long): Order? { val body: Any? = null - // verify the required parameter 'orderId' is set - // This is probably taken care of by non-null types anyway - requireNotNull(orderId) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/store/order/{orderId}".replace("{" + "orderId" + "}", IRequestFactory.escapeString(orderId.toString())); + val path = "/store/order/{orderId}".replace("{" + "orderId" + "}", IRequestFactory.escapeString(orderId.toString())) - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -225,7 +210,7 @@ class StoreApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -238,34 +223,28 @@ class StoreApi ( */ suspend fun placeOrder(body: Order): Order? { val body: Any? = body - // verify the required parameter 'body' is set - // This is probably taken care of by non-null types anyway - requireNotNull(body) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/store/order"; + val path = "/store/order" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -292,7 +271,7 @@ class StoreApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } diff --git a/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/UserApi.kt index e4b1c79e7db..19bdef550a7 100644 --- a/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-jvm-volley/src/main/java/org/openapitools/client/apis/UserApi.kt @@ -7,7 +7,7 @@ import com.android.volley.RequestQueue import com.android.volley.Response import com.android.volley.toolbox.BaseHttpStack import com.android.volley.toolbox.Volley -import java.util.*; +import java.util.* import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine @@ -41,34 +41,28 @@ class UserApi ( */ suspend fun createUser(body: User): Unit { val body: Any? = body - // verify the required parameter 'body' is set - // This is probably taken care of by non-null types anyway - requireNotNull(body) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/user"; + val path = "/user" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -95,7 +89,7 @@ class UserApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -108,34 +102,28 @@ class UserApi ( */ suspend fun createUsersWithArrayInput(body: kotlin.collections.List): Unit { val body: Any? = body - // verify the required parameter 'body' is set - // This is probably taken care of by non-null types anyway - requireNotNull(body) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/user/createWithArray"; + val path = "/user/createWithArray" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -162,7 +150,7 @@ class UserApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -175,34 +163,28 @@ class UserApi ( */ suspend fun createUsersWithListInput(body: kotlin.collections.List): Unit { val body: Any? = body - // verify the required parameter 'body' is set - // This is probably taken care of by non-null types anyway - requireNotNull(body) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/user/createWithList"; + val path = "/user/createWithList" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -229,7 +211,7 @@ class UserApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -242,34 +224,28 @@ class UserApi ( */ suspend fun deleteUser(username: kotlin.String): Unit { val body: Any? = null - // verify the required parameter 'username' is set - // This is probably taken care of by non-null types anyway - requireNotNull(username) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/user/{username}".replace("{" + "username" + "}", IRequestFactory.escapeString(username.toString())); + val path = "/user/{username}".replace("{" + "username" + "}", IRequestFactory.escapeString(username.toString())) - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -296,7 +272,7 @@ class UserApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -309,34 +285,28 @@ class UserApi ( */ suspend fun getUserByName(username: kotlin.String): User? { val body: Any? = null - // verify the required parameter 'username' is set - // This is probably taken care of by non-null types anyway - requireNotNull(username) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/user/{username}".replace("{" + "username" + "}", IRequestFactory.escapeString(username.toString())); + val path = "/user/{username}".replace("{" + "username" + "}", IRequestFactory.escapeString(username.toString())) - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -363,7 +333,7 @@ class UserApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -377,39 +347,31 @@ class UserApi ( */ suspend fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String? { val body: Any? = null - // verify the required parameter 'username' is set - // This is probably taken care of by non-null types anyway - requireNotNull(username) - // verify the required parameter 'password' is set - // This is probably taken care of by non-null types anyway - requireNotNull(password) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/user/login"; + val path = "/user/login" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path val queryParams = mapOf( - "username" to IRequestFactory.parameterToString(username), - "password" to IRequestFactory.parameterToString(password), - ).filter { it.value.isNotEmpty() } + "username" to IRequestFactory.parameterToString(username), + "password" to IRequestFactory.parameterToString(password) + ) + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -436,7 +398,7 @@ class UserApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -452,27 +414,24 @@ class UserApi ( val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/user/logout"; + val path = "/user/logout" - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -499,7 +458,7 @@ class UserApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } @@ -513,37 +472,28 @@ class UserApi ( */ suspend fun updateUser(username: kotlin.String, body: User): Unit { val body: Any? = body - // verify the required parameter 'username' is set - // This is probably taken care of by non-null types anyway - requireNotNull(username) - // verify the required parameter 'body' is set - // This is probably taken care of by non-null types anyway - requireNotNull(body) val contentTypes : Array = arrayOf() val contentType: String = if (contentTypes.isNotEmpty()) { contentTypes.first() } else { "application/json" } - // Do some work or avoid some work based on what we know about the model, + // Do some work or avoid some work based on what we know about the model, // before we delegate to a pluggable request factory template // The request factory template contains only pure code and no templates // to make it easy to override with your own. // create path and map variables - val path = "/user/{username}".replace("{" + "username" + "}", IRequestFactory.escapeString(username.toString())); + val path = "/user/{username}".replace("{" + "username" + "}", IRequestFactory.escapeString(username.toString())) - // form params - val formParams = mapOf( - ) + val formParams = mapOf() // TODO: Cater for allowing empty values // TODO, if its apikey auth, then add the header names here and the hardcoded auth key // Only support hard coded apikey in query param auth for when we do this first path - val queryParams = mapOf( - ).filter { it.value.isNotEmpty() } + val queryParams = mapOf() + .filter { it.value.isNotEmpty() } - val headerParams: Map = mapOf( - ) + val headerParams: Map = mapOf() return suspendCoroutine { continuation -> val responseListener = Response.Listener { response -> @@ -570,7 +520,7 @@ class UserApi ( responseListener, errorListener) - postProcessors.forEach{ it.invoke(request)} + postProcessors.forEach { it.invoke(request) } requestQueue.value.add(request) } diff --git a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 3e41e807ed3..77baf67fb11 100644 --- a/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-modelMutable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -194,8 +194,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { enum class Status_findPetsByStatus(val value: kotlin.String) { @Json(name = "available") available("available"), @Json(name = "pending") pending("pending"), - @Json(name = "sold") sold("sold"), - ; + @Json(name = "sold") sold("sold") } /** diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 2edb2f27d88..1817940a5e2 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -194,8 +194,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { enum class Status_findPetsByStatus(val value: kotlin.String) { @Json(name = "available") available("available"), @Json(name = "pending") pending("pending"), - @Json(name = "sold") sold("sold"), - ; + @Json(name = "sold") sold("sold") } /** 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 357ec61cdd4..5bfd90fd04c 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 @@ -54,7 +54,6 @@ open class PetApi( val localVariableBody = body val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -88,7 +87,6 @@ open class PetApi( io.ktor.client.utils.EmptyContent val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() apiKey?.apply { localVariableHeaders["api_key"] = this.toString() } @@ -123,7 +121,6 @@ open class PetApi( val localVariableQuery = mutableMapOf>() status?.apply { localVariableQuery["status"] = toMultiValue(this, "csv") } - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -167,7 +164,6 @@ open class PetApi( val localVariableQuery = mutableMapOf>() tags?.apply { localVariableQuery["tags"] = toMultiValue(this, "csv") } - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -210,7 +206,6 @@ open class PetApi( io.ktor.client.utils.EmptyContent val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -241,7 +236,6 @@ open class PetApi( val localVariableBody = body val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -279,7 +273,6 @@ open class PetApi( }.build() val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -317,7 +310,6 @@ open class PetApi( } val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( 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 d663aa08a60..1e3de76952b 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 @@ -54,7 +54,6 @@ open class StoreApi( io.ktor.client.utils.EmptyContent val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -86,7 +85,6 @@ open class StoreApi( io.ktor.client.utils.EmptyContent val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -129,7 +127,6 @@ open class StoreApi( io.ktor.client.utils.EmptyContent val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -161,7 +158,6 @@ open class StoreApi( val localVariableBody = body val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( 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 b40e8175e06..f1c1dc2e5f2 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 @@ -53,7 +53,6 @@ open class UserApi( val localVariableBody = body val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -85,7 +84,6 @@ open class UserApi( val localVariableBody = CreateUsersWithArrayInputRequest(body) val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -126,7 +124,6 @@ open class UserApi( val localVariableBody = CreateUsersWithListInputRequest(body) val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -168,7 +165,6 @@ open class UserApi( io.ktor.client.utils.EmptyContent val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -201,7 +197,6 @@ open class UserApi( io.ktor.client.utils.EmptyContent val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -237,7 +232,6 @@ open class UserApi( val localVariableQuery = mutableMapOf>() username?.apply { localVariableQuery["username"] = listOf("$username") } password?.apply { localVariableQuery["password"] = listOf("$password") } - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -268,7 +262,6 @@ open class UserApi( io.ktor.client.utils.EmptyContent val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( @@ -300,7 +293,6 @@ open class UserApi( val localVariableBody = body val localVariableQuery = mutableMapOf>() - val localVariableHeaders = mutableMapOf() val localVariableConfig = RequestConfig( 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 b3047d144b1..05991d73c2d 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 @@ -194,8 +194,7 @@ internal class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(bas internal enum class Status_findPetsByStatus(val value: kotlin.String) { @Json(name = "available") available("available"), @Json(name = "pending") pending("pending"), - @Json(name = "sold") sold("sold"), - ; + @Json(name = "sold") sold("sold") } /** diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 222346badbc..b2cce9c578b 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -194,8 +194,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { enum class Status_findPetsByStatus(val value: kotlin.String) { @Json(name = "available") available("available"), @Json(name = "pending") pending("pending"), - @Json(name = "sold") sold("sold"), - ; + @Json(name = "sold") sold("sold") } /** 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 2edb2f27d88..c54279ceb99 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 @@ -195,7 +195,6 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @Json(name = "available") available("available"), @Json(name = "pending") pending("pending"), @Json(name = "sold") sold("sold"), - ; } /** diff --git a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/auth/OAuth.kt b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/auth/OAuth.kt index cb6c411e348..69582551f37 100644 --- a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/auth/OAuth.kt +++ b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/auth/OAuth.kt @@ -50,8 +50,8 @@ class OAuth( ) : this( OAuthClientRequest.tokenLocation(tokenUrl).setScope(scopes) ) { - setFlow(flow); - authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl); + setFlow(flow) + authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl) } fun setFlow(flow: OAuthFlow) { @@ -146,6 +146,6 @@ class OAuth( throw IOException(e) } } - return true; + return true } } diff --git a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 9898e6001fb..ed22d5d071e 100644 --- a/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-kotlinx_serialization/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -47,13 +47,9 @@ class ApiClient( private val defaultClientBuilder: OkHttpClient.Builder by lazy { OkHttpClient() .newBuilder() - .addInterceptor(HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { - override fun log(message: String) { - logger?.invoke(message) - } - }).apply { - level = HttpLoggingInterceptor.Level.BODY - }) + .addInterceptor(HttpLoggingInterceptor { message -> logger?.invoke(message) } + .apply { level = HttpLoggingInterceptor.Level.BODY } + ) } init { @@ -71,7 +67,7 @@ class ApiClient( "api_key" -> ApiKeyAuth("header", "api_key")"petstore_auth" -> OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets") else -> throw RuntimeException("auth name $authName not found in available auth names") } - addAuthorization(authName, auth); + addAuthorization(authName, auth) } } @@ -145,7 +141,7 @@ class ApiClient( ?.setClientId(clientId) ?.setRedirectURI(redirectURI) } - return this; + return this } /** @@ -157,7 +153,7 @@ class ApiClient( apiAuthorizations.values.runOnFirst { registerAccessTokenListener(accessTokenListener) } - return this; + return this } /** diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 118cfcaa50c..8149c9c078e 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -3,8 +3,8 @@ package org.openapitools.client.apis import org.openapitools.client.infrastructure.CollectionFormats.* import retrofit2.http.* import okhttp3.RequestBody -import io.reactivex.rxjava3.core.Single; -import io.reactivex.rxjava3.core.Completable; +import io.reactivex.rxjava3.core.Single +import io.reactivex.rxjava3.core.Completable import org.openapitools.client.models.ModelApiResponse import org.openapitools.client.models.Pet diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 04e11a0562d..7946510c56b 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -3,8 +3,8 @@ package org.openapitools.client.apis import org.openapitools.client.infrastructure.CollectionFormats.* import retrofit2.http.* import okhttp3.RequestBody -import io.reactivex.rxjava3.core.Single; -import io.reactivex.rxjava3.core.Completable; +import io.reactivex.rxjava3.core.Single +import io.reactivex.rxjava3.core.Completable import org.openapitools.client.models.Order diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index eb73be1d703..55aeb36bbd7 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -3,8 +3,8 @@ package org.openapitools.client.apis import org.openapitools.client.infrastructure.CollectionFormats.* import retrofit2.http.* import okhttp3.RequestBody -import io.reactivex.rxjava3.core.Single; -import io.reactivex.rxjava3.core.Completable; +import io.reactivex.rxjava3.core.Single +import io.reactivex.rxjava3.core.Completable import org.openapitools.client.models.User diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/auth/OAuth.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/auth/OAuth.kt index cb6c411e348..69582551f37 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/auth/OAuth.kt +++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/auth/OAuth.kt @@ -50,8 +50,8 @@ class OAuth( ) : this( OAuthClientRequest.tokenLocation(tokenUrl).setScope(scopes) ) { - setFlow(flow); - authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl); + setFlow(flow) + authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl) } fun setFlow(flow: OAuthFlow) { @@ -146,6 +146,6 @@ class OAuth( throw IOException(e) } } - return true; + return true } } diff --git a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ffc0e0eb58c..561935b85fc 100644 --- a/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2-rx3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -50,13 +50,9 @@ class ApiClient( private val defaultClientBuilder: OkHttpClient.Builder by lazy { OkHttpClient() .newBuilder() - .addInterceptor(HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { - override fun log(message: String) { - logger?.invoke(message) - } - }).apply { - level = HttpLoggingInterceptor.Level.BODY - }) + .addInterceptor(HttpLoggingInterceptor { message -> logger?.invoke(message) } + .apply { level = HttpLoggingInterceptor.Level.BODY } + ) } init { @@ -74,7 +70,7 @@ class ApiClient( "api_key" -> ApiKeyAuth("header", "api_key")"petstore_auth" -> OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets") else -> throw RuntimeException("auth name $authName not found in available auth names") } - addAuthorization(authName, auth); + addAuthorization(authName, auth) } } @@ -148,7 +144,7 @@ class ApiClient( ?.setClientId(clientId) ?.setRedirectURI(redirectURI) } - return this; + return this } /** @@ -160,7 +156,7 @@ class ApiClient( apiAuthorizations.values.runOnFirst { registerAccessTokenListener(accessTokenListener) } - return this; + return this } /** diff --git a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/auth/OAuth.kt b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/auth/OAuth.kt index cb6c411e348..69582551f37 100644 --- a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/auth/OAuth.kt +++ b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/auth/OAuth.kt @@ -50,8 +50,8 @@ class OAuth( ) : this( OAuthClientRequest.tokenLocation(tokenUrl).setScope(scopes) ) { - setFlow(flow); - authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl); + setFlow(flow) + authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl) } fun setFlow(flow: OAuthFlow) { @@ -146,6 +146,6 @@ class OAuth( throw IOException(e) } } - return true; + return true } } diff --git a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 1ca40216481..09694992a6b 100644 --- a/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-retrofit2/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -47,13 +47,9 @@ class ApiClient( private val defaultClientBuilder: OkHttpClient.Builder by lazy { OkHttpClient() .newBuilder() - .addInterceptor(HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { - override fun log(message: String) { - logger?.invoke(message) - } - }).apply { - level = HttpLoggingInterceptor.Level.BODY - }) + .addInterceptor(HttpLoggingInterceptor { message -> logger?.invoke(message) } + .apply { level = HttpLoggingInterceptor.Level.BODY } + ) } init { @@ -71,7 +67,7 @@ class ApiClient( "api_key" -> ApiKeyAuth("header", "api_key")"petstore_auth" -> OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets") else -> throw RuntimeException("auth name $authName not found in available auth names") } - addAuthorization(authName, auth); + addAuthorization(authName, auth) } } @@ -145,7 +141,7 @@ class ApiClient( ?.setClientId(clientId) ?.setRedirectURI(redirectURI) } - return this; + return this } /** @@ -157,7 +153,7 @@ class ApiClient( apiAuthorizations.values.runOnFirst { registerAccessTokenListener(accessTokenListener) } - return this; + return this } /** 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 d260f3e5211..9e2f701e4dc 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 @@ -194,8 +194,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { enum class Status_findPetsByStatus(val value: kotlin.String) { @Json(name = "available") available("available"), @Json(name = "pending") pending("pending"), - @Json(name = "sold") sold("sold"), - ; + @Json(name = "sold") sold("sold") } /** 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 2edb2f27d88..1817940a5e2 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 @@ -194,8 +194,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { enum class Status_findPetsByStatus(val value: kotlin.String) { @Json(name = "available") available("available"), @Json(name = "pending") pending("pending"), - @Json(name = "sold") sold("sold"), - ; + @Json(name = "sold") sold("sold") } /** 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 2edb2f27d88..1817940a5e2 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 @@ -194,8 +194,7 @@ class PetApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { enum class Status_findPetsByStatus(val value: kotlin.String) { @Json(name = "available") available("available"), @Json(name = "pending") pending("pending"), - @Json(name = "sold") sold("sold"), - ; + @Json(name = "sold") sold("sold") } /**