forked from loafle/openapi-generator-original
[BUG][Kotlin-client] Handling default values of parameters (#12255)
* Bugfix Kotlin-client: Handling default values of parameters * Adding object
This commit is contained in:
parent
b6a8037f62
commit
8950a9a3c0
5
.github/workflows/samples-kotlin-client.yaml
vendored
5
.github/workflows/samples-kotlin-client.yaml
vendored
@ -40,6 +40,11 @@ jobs:
|
|||||||
- samples/client/petstore/kotlin-uppercase-enum
|
- samples/client/petstore/kotlin-uppercase-enum
|
||||||
- samples/client/petstore/kotlin-array-simple-string
|
- samples/client/petstore/kotlin-array-simple-string
|
||||||
- samples/client/petstore/kotlin-bigdecimal-default
|
- 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
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-java@v3
|
- uses: actions/setup-java@v3
|
||||||
|
8
bin/configs/kotlin-default-values-jvm-okhttp3.yaml
Normal file
8
bin/configs/kotlin-default-values-jvm-okhttp3.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
generatorName: kotlin
|
||||||
|
outputDir: samples/client/petstore/kotlin-default-values-jvm-okhttp3
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_10865_default_values.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
|
||||||
|
additionalProperties:
|
||||||
|
artifactId: kotlin-default-values-jvm-okhttp3
|
||||||
|
library: jvm-okhttp3
|
||||||
|
sortParamsByRequiredFlag: false
|
8
bin/configs/kotlin-default-values-jvm-okhttp4.yaml
Normal file
8
bin/configs/kotlin-default-values-jvm-okhttp4.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
generatorName: kotlin
|
||||||
|
outputDir: samples/client/petstore/kotlin-default-values-jvm-okhttp4
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_10865_default_values.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
|
||||||
|
additionalProperties:
|
||||||
|
artifactId: kotlin-default-values-jvm-okhttp4
|
||||||
|
library: jvm-okhttp4
|
||||||
|
sortParamsByRequiredFlag: false
|
8
bin/configs/kotlin-default-values-jvm-retrofit2.yaml
Normal file
8
bin/configs/kotlin-default-values-jvm-retrofit2.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
generatorName: kotlin
|
||||||
|
outputDir: samples/client/petstore/kotlin-default-values-jvm-retrofit2
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_10865_default_values.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
|
||||||
|
additionalProperties:
|
||||||
|
artifactId: kotlin-default-values-jvm-retrofit2
|
||||||
|
library: jvm-retrofit2
|
||||||
|
sortParamsByRequiredFlag: false
|
10
bin/configs/kotlin-default-values-jvm-volley.yaml
Normal file
10
bin/configs/kotlin-default-values-jvm-volley.yaml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
generatorName: kotlin
|
||||||
|
outputDir: samples/client/petstore/kotlin-default-values-jvm-volley
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_10865_default_values.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
|
||||||
|
additionalProperties:
|
||||||
|
artifactId: kotlin-default-values-jvm-volley
|
||||||
|
library: jvm-volley
|
||||||
|
sortParamsByRequiredFlag: false
|
||||||
|
serializationLibrary: gson
|
||||||
|
generateRoomModels: true
|
8
bin/configs/kotlin-default-values-multiplatform.yaml
Normal file
8
bin/configs/kotlin-default-values-multiplatform.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
generatorName: kotlin
|
||||||
|
outputDir: samples/client/petstore/kotlin-default-values-multiplatform
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_10865_default_values.yaml
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
|
||||||
|
additionalProperties:
|
||||||
|
artifactId: kotlin-default-values-multiplatform
|
||||||
|
library: multiplatform
|
||||||
|
sortParamsByRequiredFlag: false
|
@ -115,22 +115,22 @@ import {{packageName}}.infrastructure.toMultiValue
|
|||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
/**
|
/**
|
||||||
* {{summary}}
|
* {{summary}}
|
||||||
* {{notes}}
|
* {{notes}}
|
||||||
{{#allParams}}* @param {{{paramName}}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
|
{{#allParams}}* @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}
|
||||||
{{/allParams}}* @return {{#returnType}}{{{returnType}}}{{#nullableReturnType}} or null{{/nullableReturnType}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
{{/allParams}}* @return {{#returnType}}{{{returnType}}}{{#nullableReturnType}} or null{{/nullableReturnType}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||||
* @throws IllegalStateException If the request is not correctly configured
|
* @throws IllegalStateException If the request is not correctly configured
|
||||||
* @throws IOException Rethrows the OkHttp execute method exception
|
* @throws IOException Rethrows the OkHttp execute method exception
|
||||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||||
* @throws ClientException If the API returns a client error response
|
* @throws ClientException If the API returns a client error response
|
||||||
* @throws ServerException If the API returns a server error response
|
* @throws ServerException If the API returns a server error response
|
||||||
*/{{#returnType}}
|
*/{{#returnType}}
|
||||||
@Suppress("UNCHECKED_CAST"){{/returnType}}
|
@Suppress("UNCHECKED_CAST"){{/returnType}}
|
||||||
@Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
@Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
@Deprecated(message = "This operation is deprecated.")
|
@Deprecated(message = "This operation is deprecated.")
|
||||||
{{/isDeprecated}}
|
{{/isDeprecated}}
|
||||||
{{^doNotUseRxAndCoroutines}}{{#useCoroutines}}suspend {{/useCoroutines}}{{/doNotUseRxAndCoroutines}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{#isEnum}}{{#isContainer}}kotlin.collections.List<{{enumName}}_{{operationId}}>{{/isContainer}}{{^isContainer}}{{enumName}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{#nullableReturnType}}?{{/nullableReturnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}{{^doNotUseRxAndCoroutines}}{{#useCoroutines}} = withContext(Dispatchers.IO){{/useCoroutines}}{{/doNotUseRxAndCoroutines}} {
|
{{^doNotUseRxAndCoroutines}}{{#useCoroutines}}suspend {{/useCoroutines}}{{/doNotUseRxAndCoroutines}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{#isEnum}}{{#isContainer}}kotlin.collections.List<{{enumName}}_{{operationId}}>{{/isContainer}}{{^isContainer}}{{enumName}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{#nullableReturnType}}?{{/nullableReturnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}{{^doNotUseRxAndCoroutines}}{{#useCoroutines}} = withContext(Dispatchers.IO){{/useCoroutines}}{{/doNotUseRxAndCoroutines}} {
|
||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
{{/isDeprecated}}
|
{{/isDeprecated}}
|
||||||
@ -152,13 +152,13 @@ import {{packageName}}.infrastructure.toMultiValue
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {{summary}}
|
* {{summary}}
|
||||||
* {{notes}}
|
* {{notes}}
|
||||||
{{#allParams}}* @param {{{paramName}}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
|
{{#allParams}}* @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}
|
||||||
{{/allParams}}* @return ApiResponse<{{#returnType}}{{{returnType}}}?{{/returnType}}{{^returnType}}Unit?{{/returnType}}>
|
{{/allParams}}* @return ApiResponse<{{#returnType}}{{{returnType}}}?{{/returnType}}{{^returnType}}Unit?{{/returnType}}>
|
||||||
* @throws IllegalStateException If the request is not correctly configured
|
* @throws IllegalStateException If the request is not correctly configured
|
||||||
* @throws IOException Rethrows the OkHttp execute method exception
|
* @throws IOException Rethrows the OkHttp execute method exception
|
||||||
*/{{#returnType}}
|
*/{{#returnType}}
|
||||||
@Suppress("UNCHECKED_CAST"){{/returnType}}
|
@Suppress("UNCHECKED_CAST"){{/returnType}}
|
||||||
@Throws(IllegalStateException::class, IOException::class)
|
@Throws(IllegalStateException::class, IOException::class)
|
||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
@ -176,11 +176,11 @@ import {{packageName}}.infrastructure.toMultiValue
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To obtain the request config of the operation {{operationId}}
|
* To obtain the request config of the operation {{operationId}}
|
||||||
*
|
*
|
||||||
{{#allParams}}* @param {{{paramName}}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
|
{{#allParams}}* @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}
|
||||||
{{/allParams}}* @return RequestConfig
|
{{/allParams}}* @return RequestConfig
|
||||||
*/
|
*/
|
||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
@Deprecated(message = "This operation is deprecated.")
|
@Deprecated(message = "This operation is deprecated.")
|
||||||
{{/isDeprecated}}
|
{{/isDeprecated}}
|
||||||
|
@ -62,7 +62,7 @@ interface {{classname}} {
|
|||||||
* - {{code}}: {{{message}}}{{/responses}}
|
* - {{code}}: {{{message}}}{{/responses}}
|
||||||
*
|
*
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
* @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
|
* @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
* @return {{^useCoroutines}}[Call]<{{/useCoroutines}}{{#isResponseFile}}[ResponseBody]{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}[{{{.}}}]{{/returnType}}{{^returnType}}[Unit]{{/returnType}}{{/isResponseFile}}{{^useCoroutines}}>{{/useCoroutines}}
|
* @return {{^useCoroutines}}[Call]<{{/useCoroutines}}{{#isResponseFile}}[ResponseBody]{{/isResponseFile}}{{^isResponseFile}}{{#returnType}}[{{{.}}}]{{/returnType}}{{^returnType}}[Unit]{{/returnType}}{{/isResponseFile}}{{^useCoroutines}}>{{/useCoroutines}}
|
||||||
*/
|
*/
|
||||||
|
@ -1 +1 @@
|
|||||||
{{#isFormParam}}{{^isFile}}{{#isMultipart}}@Part{{/isMultipart}}{{^isMultipart}}@Field{{/isMultipart}}("{{baseName}}") {{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isFile}}{{#isFile}}{{#isMultipart}}@Part{{/isMultipart}}{{^isMultipart}}@Field("{{baseName}}"){{/isMultipart}} {{{paramName}}}: MultipartBody.Part{{^required}}? = null{{/required}}{{/isFile}}{{/isFormParam}}
|
{{#isFormParam}}{{^isFile}}{{#isMultipart}}@Part{{/isMultipart}}{{^isMultipart}}@Field{{/isMultipart}}("{{baseName}}") {{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isFile}}{{#isFile}}{{#isMultipart}}@Part{{/isMultipart}}{{^isMultipart}}@Field("{{baseName}}"){{/isMultipart}} {{{paramName}}}: MultipartBody.Part{{^required}}? = null{{/required}}{{/isFile}}{{/isFormParam}}
|
@ -1 +1 @@
|
|||||||
{{#isHeaderParam}}@Header("{{baseName}}") {{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isHeaderParam}}
|
{{#isHeaderParam}}@Header("{{baseName}}") {{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isHeaderParam}}
|
@ -1 +1 @@
|
|||||||
{{#isPathParam}}@Path("{{baseName}}") {{{paramName}}}: {{{dataType}}}{{/isPathParam}}
|
{{#isPathParam}}@Path("{{baseName}}") {{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isPathParam}}
|
@ -1 +1 @@
|
|||||||
{{#isQueryParam}}@Query("{{baseName}}") {{{paramName}}}: {{#collectionFormat}}{{#isCollectionFormatMulti}}{{{dataType}}}{{/isCollectionFormatMulti}}{{^isCollectionFormatMulti}}{{{collectionFormat.toUpperCase}}}Params{{/isCollectionFormatMulti}}{{/collectionFormat}}{{^collectionFormat}}{{{dataType}}}{{/collectionFormat}}{{^required}}? = null{{/required}}{{/isQueryParam}}
|
{{#isQueryParam}}@Query("{{baseName}}") {{{paramName}}}: {{#collectionFormat}}{{#isCollectionFormatMulti}}{{{dataType}}}{{/isCollectionFormatMulti}}{{^isCollectionFormatMulti}}{{{collectionFormat.toUpperCase}}}Params{{/isCollectionFormatMulti}}{{/collectionFormat}}{{^collectionFormat}}{{{dataType}}}{{/collectionFormat}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isQueryParam}}
|
@ -37,11 +37,11 @@ class {{classname}} (
|
|||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
/**
|
/**
|
||||||
* {{summary}}
|
* {{summary}}
|
||||||
* {{notes}}
|
* {{notes}}
|
||||||
{{#allParams}} * @param {{paramName}} {{description}}
|
{{#allParams}}* @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}
|
||||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
{{/allParams}}* @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||||
*/
|
*/
|
||||||
{{#isDeprecated}}
|
{{#isDeprecated}}
|
||||||
@Deprecated("This api was deprecated")
|
@Deprecated("This api was deprecated")
|
||||||
{{/isDeprecated}}
|
{{/isDeprecated}}
|
||||||
|
@ -1 +1 @@
|
|||||||
{{#isFormParam}}{{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isFormParam}}
|
{{#isFormParam}}{{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isFormParam}}
|
@ -1 +1 @@
|
|||||||
{{#isHeaderParam}}{{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isHeaderParam}}
|
{{#isHeaderParam}}{{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isHeaderParam}}
|
@ -1 +1 @@
|
|||||||
{{#isPathParam}}{{{paramName}}}: {{{dataType}}}{{/isPathParam}}
|
{{#isPathParam}}{{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isPathParam}}
|
@ -1 +1 @@
|
|||||||
{{#isQueryParam}}{{{paramName}}}: {{#collectionFormat}}{{#isCollectionFormatMulti}}{{{dataType}}}{{/isCollectionFormatMulti}}{{^isCollectionFormatMulti}}{{{collectionFormat.toUpperCase}}}Params{{/isCollectionFormatMulti}}{{/collectionFormat}}{{^collectionFormat}}{{{dataType}}}{{/collectionFormat}}{{^required}}? = null{{/required}}{{/isQueryParam}}
|
{{#isQueryParam}}{{{paramName}}}: {{#collectionFormat}}{{#isCollectionFormatMulti}}{{{dataType}}}{{/isCollectionFormatMulti}}{{^isCollectionFormatMulti}}{{{collectionFormat.toUpperCase}}}Params{{/isCollectionFormatMulti}}{{/collectionFormat}}{{^collectionFormat}}{{{dataType}}}{{/collectionFormat}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{/isQueryParam}}
|
@ -27,13 +27,13 @@ import kotlinx.serialization.encoding.*
|
|||||||
/**
|
/**
|
||||||
* {{summary}}
|
* {{summary}}
|
||||||
* {{notes}}
|
* {{notes}}
|
||||||
{{#allParams}} * @param {{{paramName}}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
|
{{#allParams}} * @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}
|
||||||
{{/allParams}} * @return {{{returnType}}}{{^returnType}}void{{/returnType}}
|
{{/allParams}} * @return {{{returnType}}}{{^returnType}}void{{/returnType}}
|
||||||
*/
|
*/
|
||||||
{{#returnType}}
|
{{#returnType}}
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
{{/returnType}}
|
{{/returnType}}
|
||||||
open suspend fun {{operationId}}({{#allParams}}{{{paramName}}}: {{{dataType}}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): HttpResponse<{{{returnType}}}{{^returnType}}Unit{{/returnType}}> {
|
open suspend fun {{operationId}}({{#allParams}}{{{paramName}}}: {{{dataType}}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{defaultValue}}}.toDouble(){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{defaultValue}}}.toDouble(){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): HttpResponse<{{{returnType}}}{{^returnType}}Unit{{/returnType}}> {
|
||||||
|
|
||||||
val localVariableAuthNames = listOf<String>({{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}})
|
val localVariableAuthNames = listOf<String>({{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}})
|
||||||
|
|
||||||
|
@ -0,0 +1,171 @@
|
|||||||
|
swagger: '2.0'
|
||||||
|
info:
|
||||||
|
version: 1.0.0
|
||||||
|
title: Demo
|
||||||
|
paths:
|
||||||
|
'/test':
|
||||||
|
post:
|
||||||
|
summary: "Tests default values"
|
||||||
|
description: "Tests default values of different parameters"
|
||||||
|
operationId: "test"
|
||||||
|
parameters:
|
||||||
|
- name: pi0
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
default: 10
|
||||||
|
- name: pi1
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
|
||||||
|
- name: pn0
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
type: number
|
||||||
|
default: 10
|
||||||
|
- name: pn1
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
type: number
|
||||||
|
|
||||||
|
|
||||||
|
- name: qi0
|
||||||
|
in: query
|
||||||
|
required: false
|
||||||
|
type: integer
|
||||||
|
default: 10
|
||||||
|
- name: qi1
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
default: 71
|
||||||
|
- name: qi2
|
||||||
|
in: query
|
||||||
|
required: false
|
||||||
|
type: integer
|
||||||
|
- name: qi3
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
|
||||||
|
- name: qn0
|
||||||
|
in: query
|
||||||
|
required: false
|
||||||
|
type: number
|
||||||
|
default: 10
|
||||||
|
- name: qn1
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
type: number
|
||||||
|
default: 71
|
||||||
|
- name: qn2
|
||||||
|
in: query
|
||||||
|
required: false
|
||||||
|
type: number
|
||||||
|
- name: qn3
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
type: number
|
||||||
|
|
||||||
|
|
||||||
|
- name: hi0
|
||||||
|
in: header
|
||||||
|
required: false
|
||||||
|
type: integer
|
||||||
|
default: 10
|
||||||
|
- name: hi1
|
||||||
|
in: header
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
default: 71
|
||||||
|
- name: hi2
|
||||||
|
in: header
|
||||||
|
required: false
|
||||||
|
type: integer
|
||||||
|
- name: hi3
|
||||||
|
in: header
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
|
||||||
|
- name: hn0
|
||||||
|
in: header
|
||||||
|
required: false
|
||||||
|
type: number
|
||||||
|
default: 10
|
||||||
|
- name: hn1
|
||||||
|
in: header
|
||||||
|
required: true
|
||||||
|
type: number
|
||||||
|
default: 71
|
||||||
|
- name: hn2
|
||||||
|
in: header
|
||||||
|
required: false
|
||||||
|
type: number
|
||||||
|
- name: hn3
|
||||||
|
in: header
|
||||||
|
required: true
|
||||||
|
type: number
|
||||||
|
|
||||||
|
|
||||||
|
- name: fi0
|
||||||
|
in: formData
|
||||||
|
required: false
|
||||||
|
type: integer
|
||||||
|
default: 10
|
||||||
|
- name: fi1
|
||||||
|
in: formData
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
default: 71
|
||||||
|
- name: fi2
|
||||||
|
in: formData
|
||||||
|
required: false
|
||||||
|
type: integer
|
||||||
|
- name: fi3
|
||||||
|
in: formData
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
|
||||||
|
- name: fn0
|
||||||
|
in: formData
|
||||||
|
required: false
|
||||||
|
type: number
|
||||||
|
default: 10
|
||||||
|
- name: fn1
|
||||||
|
in: formData
|
||||||
|
required: true
|
||||||
|
type: number
|
||||||
|
default: 71
|
||||||
|
- name: fn2
|
||||||
|
in: formData
|
||||||
|
required: false
|
||||||
|
type: number
|
||||||
|
- name: fn3
|
||||||
|
in: formData
|
||||||
|
required: true
|
||||||
|
type: number
|
||||||
|
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: "Success"
|
||||||
|
|
||||||
|
definitions:
|
||||||
|
Apa:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- i0
|
||||||
|
- n0
|
||||||
|
properties:
|
||||||
|
i0:
|
||||||
|
type: integer
|
||||||
|
default: 10
|
||||||
|
i1:
|
||||||
|
type: integer
|
||||||
|
default: 20
|
||||||
|
n0:
|
||||||
|
type: number
|
||||||
|
default: 71
|
||||||
|
n1:
|
||||||
|
type: number
|
||||||
|
default: 68
|
@ -48,16 +48,16 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param ids
|
* @param ids
|
||||||
* @return void
|
* @return void
|
||||||
* @throws IllegalStateException If the request is not correctly configured
|
* @throws IllegalStateException If the request is not correctly configured
|
||||||
* @throws IOException Rethrows the OkHttp execute method exception
|
* @throws IOException Rethrows the OkHttp execute method exception
|
||||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||||
* @throws ClientException If the API returns a client error response
|
* @throws ClientException If the API returns a client error response
|
||||||
* @throws ServerException If the API returns a server error response
|
* @throws ServerException If the API returns a server error response
|
||||||
*/
|
*/
|
||||||
@Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
@Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||||
fun idsGet(ids: kotlin.collections.List<kotlin.String>) : Unit {
|
fun idsGet(ids: kotlin.collections.List<kotlin.String>) : Unit {
|
||||||
val localVarResponse = idsGetWithHttpInfo(ids = ids)
|
val localVarResponse = idsGetWithHttpInfo(ids = ids)
|
||||||
@ -78,13 +78,13 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param ids
|
* @param ids
|
||||||
* @return ApiResponse<Unit?>
|
* @return ApiResponse<Unit?>
|
||||||
* @throws IllegalStateException If the request is not correctly configured
|
* @throws IllegalStateException If the request is not correctly configured
|
||||||
* @throws IOException Rethrows the OkHttp execute method exception
|
* @throws IOException Rethrows the OkHttp execute method exception
|
||||||
*/
|
*/
|
||||||
@Throws(IllegalStateException::class, IOException::class)
|
@Throws(IllegalStateException::class, IOException::class)
|
||||||
fun idsGetWithHttpInfo(ids: kotlin.collections.List<kotlin.String>) : ApiResponse<Unit?> {
|
fun idsGetWithHttpInfo(ids: kotlin.collections.List<kotlin.String>) : ApiResponse<Unit?> {
|
||||||
val localVariableConfig = idsGetRequestConfig(ids = ids)
|
val localVariableConfig = idsGetRequestConfig(ids = ids)
|
||||||
@ -95,11 +95,11 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To obtain the request config of the operation idsGet
|
* To obtain the request config of the operation idsGet
|
||||||
*
|
*
|
||||||
* @param ids
|
* @param ids
|
||||||
* @return RequestConfig
|
* @return RequestConfig
|
||||||
*/
|
*/
|
||||||
fun idsGetRequestConfig(ids: kotlin.collections.List<kotlin.String>) : RequestConfig<Unit> {
|
fun idsGetRequestConfig(ids: kotlin.collections.List<kotlin.String>) : RequestConfig<Unit> {
|
||||||
val localVariableBody = null
|
val localVariableBody = null
|
||||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||||
|
@ -43,7 +43,7 @@ open class DefaultApi(
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param apa
|
* @param apa
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
open suspend fun testPost(apa: Apa): HttpResponse<Unit> {
|
open suspend fun testPost(apa: Apa): HttpResponse<Unit> {
|
||||||
|
@ -49,16 +49,16 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param apa
|
* @param apa
|
||||||
* @return void
|
* @return void
|
||||||
* @throws IllegalStateException If the request is not correctly configured
|
* @throws IllegalStateException If the request is not correctly configured
|
||||||
* @throws IOException Rethrows the OkHttp execute method exception
|
* @throws IOException Rethrows the OkHttp execute method exception
|
||||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||||
* @throws ClientException If the API returns a client error response
|
* @throws ClientException If the API returns a client error response
|
||||||
* @throws ServerException If the API returns a server error response
|
* @throws ServerException If the API returns a server error response
|
||||||
*/
|
*/
|
||||||
@Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
@Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||||
fun testPost(apa: Apa) : Unit {
|
fun testPost(apa: Apa) : Unit {
|
||||||
val localVarResponse = testPostWithHttpInfo(apa = apa)
|
val localVarResponse = testPostWithHttpInfo(apa = apa)
|
||||||
@ -79,13 +79,13 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param apa
|
* @param apa
|
||||||
* @return ApiResponse<Unit?>
|
* @return ApiResponse<Unit?>
|
||||||
* @throws IllegalStateException If the request is not correctly configured
|
* @throws IllegalStateException If the request is not correctly configured
|
||||||
* @throws IOException Rethrows the OkHttp execute method exception
|
* @throws IOException Rethrows the OkHttp execute method exception
|
||||||
*/
|
*/
|
||||||
@Throws(IllegalStateException::class, IOException::class)
|
@Throws(IllegalStateException::class, IOException::class)
|
||||||
fun testPostWithHttpInfo(apa: Apa) : ApiResponse<Unit?> {
|
fun testPostWithHttpInfo(apa: Apa) : ApiResponse<Unit?> {
|
||||||
val localVariableConfig = testPostRequestConfig(apa = apa)
|
val localVariableConfig = testPostRequestConfig(apa = apa)
|
||||||
@ -96,11 +96,11 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To obtain the request config of the operation testPost
|
* To obtain the request config of the operation testPost
|
||||||
*
|
*
|
||||||
* @param apa
|
* @param apa
|
||||||
* @return RequestConfig
|
* @return RequestConfig
|
||||||
*/
|
*/
|
||||||
fun testPostRequestConfig(apa: Apa) : RequestConfig<Apa> {
|
fun testPostRequestConfig(apa: Apa) : RequestConfig<Apa> {
|
||||||
val localVariableBody = apa
|
val localVariableBody = apa
|
||||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||||
|
@ -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
|
@ -0,0 +1,28 @@
|
|||||||
|
README.md
|
||||||
|
build.gradle
|
||||||
|
docs/Apa.md
|
||||||
|
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/ApiAbstractions.kt
|
||||||
|
src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
|
||||||
|
src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.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/Errors.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/PartConfig.kt
|
||||||
|
src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt
|
||||||
|
src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt
|
||||||
|
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
|
@ -0,0 +1 @@
|
|||||||
|
6.0.0-SNAPSHOT
|
@ -0,0 +1,50 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
<a name="documentation-for-api-endpoints"></a>
|
||||||
|
## Documentation for API Endpoints
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Class | Method | HTTP request | Description
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
*DefaultApi* | [**test**](docs/DefaultApi.md#test) | **POST** /test | Tests default values
|
||||||
|
|
||||||
|
|
||||||
|
<a name="documentation-for-models"></a>
|
||||||
|
## Documentation for Models
|
||||||
|
|
||||||
|
- [org.openapitools.client.models.Apa](docs/Apa.md)
|
||||||
|
|
||||||
|
|
||||||
|
<a name="documentation-for-authorization"></a>
|
||||||
|
## Documentation for Authorization
|
||||||
|
|
||||||
|
All endpoints do not require authorization.
|
@ -0,0 +1,37 @@
|
|||||||
|
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'
|
||||||
|
|
||||||
|
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:okhttp:3.12.13"
|
||||||
|
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
# Apa
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**i0** | **kotlin.Int** | |
|
||||||
|
**n0** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | |
|
||||||
|
**i1** | **kotlin.Int** | | [optional]
|
||||||
|
**n1** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | | [optional]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,109 @@
|
|||||||
|
# DefaultApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**test**](DefaultApi.md#test) | **POST** /test | Tests default values
|
||||||
|
|
||||||
|
|
||||||
|
<a name="test"></a>
|
||||||
|
# **test**
|
||||||
|
> test(pi0, pi1, pn0, pn1, qi0, qi1, qi2, qi3, qn0, qn1, qn2, qn3, hi0, hi1, hi2, hi3, hn0, hn1, hn2, hn3, fi0, fi1, fi2, fi3, fn0, fn1, fn2, fn3)
|
||||||
|
|
||||||
|
Tests default values
|
||||||
|
|
||||||
|
Tests default values of different parameters
|
||||||
|
|
||||||
|
### Example
|
||||||
|
```kotlin
|
||||||
|
// Import classes:
|
||||||
|
//import org.openapitools.client.infrastructure.*
|
||||||
|
//import org.openapitools.client.models.*
|
||||||
|
|
||||||
|
val apiInstance = DefaultApi()
|
||||||
|
val pi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val pi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val pn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val pn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qi2 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qi3 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qn2 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qn3 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hi2 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hi3 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hn2 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hn3 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fi2 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fi3 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fn2 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fn3 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
try {
|
||||||
|
apiInstance.test(pi0, pi1, pn0, pn1, qi0, qi1, qi2, qi3, qn0, qn1, qn2, qn3, hi0, hi1, hi2, hi3, hn0, hn1, hn2, hn3, fi0, fi1, fi2, fi3, fn0, fn1, fn2, fn3)
|
||||||
|
} catch (e: ClientException) {
|
||||||
|
println("4xx response calling DefaultApi#test")
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: ServerException) {
|
||||||
|
println("5xx response calling DefaultApi#test")
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**pi0** | **kotlin.Int**| | [default to 10]
|
||||||
|
**pi1** | **kotlin.Int**| |
|
||||||
|
**pn0** | **java.math.BigDecimal**| | [default to 10.0]
|
||||||
|
**pn1** | **java.math.BigDecimal**| |
|
||||||
|
**qi0** | **kotlin.Int**| | [optional] [default to 10]
|
||||||
|
**qi1** | **kotlin.Int**| | [default to 71]
|
||||||
|
**qi2** | **kotlin.Int**| | [optional]
|
||||||
|
**qi3** | **kotlin.Int**| |
|
||||||
|
**qn0** | **java.math.BigDecimal**| | [optional] [default to 10.0]
|
||||||
|
**qn1** | **java.math.BigDecimal**| | [default to 71.0]
|
||||||
|
**qn2** | **java.math.BigDecimal**| | [optional]
|
||||||
|
**qn3** | **java.math.BigDecimal**| |
|
||||||
|
**hi0** | **kotlin.Int**| | [optional] [default to 10]
|
||||||
|
**hi1** | **kotlin.Int**| | [default to 71]
|
||||||
|
**hi2** | **kotlin.Int**| | [optional]
|
||||||
|
**hi3** | **kotlin.Int**| |
|
||||||
|
**hn0** | **java.math.BigDecimal**| | [optional] [default to 10.0]
|
||||||
|
**hn1** | **java.math.BigDecimal**| | [default to 71.0]
|
||||||
|
**hn2** | **java.math.BigDecimal**| | [optional]
|
||||||
|
**hn3** | **java.math.BigDecimal**| |
|
||||||
|
**fi0** | **kotlin.Int**| | [optional] [default to 10]
|
||||||
|
**fi1** | **kotlin.Int**| | [default to 71]
|
||||||
|
**fi2** | **kotlin.Int**| | [optional]
|
||||||
|
**fi3** | **kotlin.Int**| |
|
||||||
|
**fn0** | **java.math.BigDecimal**| | [optional] [default to 10.0]
|
||||||
|
**fn1** | **java.math.BigDecimal**| | [default to 71.0]
|
||||||
|
**fn2** | **java.math.BigDecimal**| | [optional]
|
||||||
|
**fn3** | **java.math.BigDecimal**| |
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
null (empty response body)
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: multipart/form-data
|
||||||
|
- **Accept**: Not defined
|
||||||
|
|
BIN
samples/client/petstore/kotlin-default-values-jvm-okhttp3/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
samples/client/petstore/kotlin-default-values-jvm-okhttp3/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
@ -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
|
185
samples/client/petstore/kotlin-default-values-jvm-okhttp3/gradlew
vendored
Normal file
185
samples/client/petstore/kotlin-default-values-jvm-okhttp3/gradlew
vendored
Normal file
@ -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" "$@"
|
89
samples/client/petstore/kotlin-default-values-jvm-okhttp3/gradlew.bat
vendored
Normal file
89
samples/client/petstore/kotlin-default-values-jvm-okhttp3/gradlew.bat
vendored
Normal file
@ -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
|
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
rootProject.name = 'kotlin-default-values-jvm-okhttp3'
|
@ -0,0 +1,232 @@
|
|||||||
|
/**
|
||||||
|
* 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 java.io.IOException
|
||||||
|
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
|
||||||
|
import org.openapitools.client.infrastructure.ApiClient
|
||||||
|
import org.openapitools.client.infrastructure.ApiResponse
|
||||||
|
import org.openapitools.client.infrastructure.ClientException
|
||||||
|
import org.openapitools.client.infrastructure.ClientError
|
||||||
|
import org.openapitools.client.infrastructure.ServerException
|
||||||
|
import org.openapitools.client.infrastructure.ServerError
|
||||||
|
import org.openapitools.client.infrastructure.MultiValueMap
|
||||||
|
import org.openapitools.client.infrastructure.PartConfig
|
||||||
|
import org.openapitools.client.infrastructure.RequestConfig
|
||||||
|
import org.openapitools.client.infrastructure.RequestMethod
|
||||||
|
import org.openapitools.client.infrastructure.ResponseType
|
||||||
|
import org.openapitools.client.infrastructure.Success
|
||||||
|
import org.openapitools.client.infrastructure.toMultiValue
|
||||||
|
|
||||||
|
class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
val defaultBasePath: String by lazy {
|
||||||
|
System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests default values
|
||||||
|
* Tests default values of different parameters
|
||||||
|
* @param pi0 (default to 10)
|
||||||
|
* @param pi1
|
||||||
|
* @param pn0 (default to 10.0)
|
||||||
|
* @param pn1
|
||||||
|
* @param qi0 (optional, default to 10)
|
||||||
|
* @param qi1 (default to 71)
|
||||||
|
* @param qi2 (optional)
|
||||||
|
* @param qi3
|
||||||
|
* @param qn0 (optional, default to 10.0)
|
||||||
|
* @param qn1 (default to 71.0)
|
||||||
|
* @param qn2 (optional)
|
||||||
|
* @param qn3
|
||||||
|
* @param hi0 (optional, default to 10)
|
||||||
|
* @param hi1 (default to 71)
|
||||||
|
* @param hi2 (optional)
|
||||||
|
* @param hi3
|
||||||
|
* @param hn0 (optional, default to 10.0)
|
||||||
|
* @param hn1 (default to 71.0)
|
||||||
|
* @param hn2 (optional)
|
||||||
|
* @param hn3
|
||||||
|
* @param fi0 (optional, default to 10)
|
||||||
|
* @param fi1 (default to 71)
|
||||||
|
* @param fi2 (optional)
|
||||||
|
* @param fi3
|
||||||
|
* @param fn0 (optional, default to 10.0)
|
||||||
|
* @param fn1 (default to 71.0)
|
||||||
|
* @param fn2 (optional)
|
||||||
|
* @param fn3
|
||||||
|
* @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 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 localVarResponse = testWithHttpInfo(pi0 = pi0, pi1 = pi1, pn0 = pn0, pn1 = pn1, qi0 = qi0, qi1 = qi1, qi2 = qi2, qi3 = qi3, qn0 = qn0, qn1 = qn1, qn2 = qn2, qn3 = qn3, hi0 = hi0, hi1 = hi1, hi2 = hi2, hi3 = hi3, hn0 = hn0, hn1 = hn1, hn2 = hn2, hn3 = hn3, fi0 = fi0, fi1 = fi1, fi2 = fi2, fi3 = fi3, fn0 = fn0, fn1 = fn1, fn2 = fn2, fn3 = fn3)
|
||||||
|
|
||||||
|
return when (localVarResponse.responseType) {
|
||||||
|
ResponseType.Success -> Unit
|
||||||
|
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||||
|
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||||
|
ResponseType.ClientError -> {
|
||||||
|
val localVarError = localVarResponse as ClientError<*>
|
||||||
|
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||||
|
}
|
||||||
|
ResponseType.ServerError -> {
|
||||||
|
val localVarError = localVarResponse as ServerError<*>
|
||||||
|
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests default values
|
||||||
|
* Tests default values of different parameters
|
||||||
|
* @param pi0 (default to 10)
|
||||||
|
* @param pi1
|
||||||
|
* @param pn0 (default to 10.0)
|
||||||
|
* @param pn1
|
||||||
|
* @param qi0 (optional, default to 10)
|
||||||
|
* @param qi1 (default to 71)
|
||||||
|
* @param qi2 (optional)
|
||||||
|
* @param qi3
|
||||||
|
* @param qn0 (optional, default to 10.0)
|
||||||
|
* @param qn1 (default to 71.0)
|
||||||
|
* @param qn2 (optional)
|
||||||
|
* @param qn3
|
||||||
|
* @param hi0 (optional, default to 10)
|
||||||
|
* @param hi1 (default to 71)
|
||||||
|
* @param hi2 (optional)
|
||||||
|
* @param hi3
|
||||||
|
* @param hn0 (optional, default to 10.0)
|
||||||
|
* @param hn1 (default to 71.0)
|
||||||
|
* @param hn2 (optional)
|
||||||
|
* @param hn3
|
||||||
|
* @param fi0 (optional, default to 10)
|
||||||
|
* @param fi1 (default to 71)
|
||||||
|
* @param fi2 (optional)
|
||||||
|
* @param fi3
|
||||||
|
* @param fn0 (optional, default to 10.0)
|
||||||
|
* @param fn1 (default to 71.0)
|
||||||
|
* @param fn2 (optional)
|
||||||
|
* @param fn3
|
||||||
|
* @return ApiResponse<Unit?>
|
||||||
|
* @throws IllegalStateException If the request is not correctly configured
|
||||||
|
* @throws IOException Rethrows the OkHttp execute method exception
|
||||||
|
*/
|
||||||
|
@Throws(IllegalStateException::class, IOException::class)
|
||||||
|
fun testWithHttpInfo(pi0: kotlin.Int, pi1: kotlin.Int, pn0: java.math.BigDecimal, pn1: java.math.BigDecimal, qi0: kotlin.Int?, qi1: kotlin.Int, qi2: kotlin.Int?, qi3: kotlin.Int, qn0: java.math.BigDecimal?, qn1: java.math.BigDecimal, qn2: java.math.BigDecimal?, qn3: java.math.BigDecimal, hi0: kotlin.Int?, hi1: kotlin.Int, hi2: kotlin.Int?, hi3: kotlin.Int, hn0: java.math.BigDecimal?, hn1: java.math.BigDecimal, hn2: java.math.BigDecimal?, hn3: java.math.BigDecimal, fi0: kotlin.Int?, fi1: kotlin.Int, fi2: kotlin.Int?, fi3: kotlin.Int, fn0: java.math.BigDecimal?, fn1: java.math.BigDecimal, fn2: java.math.BigDecimal?, fn3: java.math.BigDecimal) : ApiResponse<Unit?> {
|
||||||
|
val localVariableConfig = testRequestConfig(pi0 = pi0, pi1 = pi1, pn0 = pn0, pn1 = pn1, qi0 = qi0, qi1 = qi1, qi2 = qi2, qi3 = qi3, qn0 = qn0, qn1 = qn1, qn2 = qn2, qn3 = qn3, hi0 = hi0, hi1 = hi1, hi2 = hi2, hi3 = hi3, hn0 = hn0, hn1 = hn1, hn2 = hn2, hn3 = hn3, fi0 = fi0, fi1 = fi1, fi2 = fi2, fi3 = fi3, fn0 = fn0, fn1 = fn1, fn2 = fn2, fn3 = fn3)
|
||||||
|
|
||||||
|
return request<Map<String, PartConfig<*>>, Unit>(
|
||||||
|
localVariableConfig
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To obtain the request config of the operation test
|
||||||
|
*
|
||||||
|
* @param pi0 (default to 10)
|
||||||
|
* @param pi1
|
||||||
|
* @param pn0 (default to 10.0)
|
||||||
|
* @param pn1
|
||||||
|
* @param qi0 (optional, default to 10)
|
||||||
|
* @param qi1 (default to 71)
|
||||||
|
* @param qi2 (optional)
|
||||||
|
* @param qi3
|
||||||
|
* @param qn0 (optional, default to 10.0)
|
||||||
|
* @param qn1 (default to 71.0)
|
||||||
|
* @param qn2 (optional)
|
||||||
|
* @param qn3
|
||||||
|
* @param hi0 (optional, default to 10)
|
||||||
|
* @param hi1 (default to 71)
|
||||||
|
* @param hi2 (optional)
|
||||||
|
* @param hi3
|
||||||
|
* @param hn0 (optional, default to 10.0)
|
||||||
|
* @param hn1 (default to 71.0)
|
||||||
|
* @param hn2 (optional)
|
||||||
|
* @param hn3
|
||||||
|
* @param fi0 (optional, default to 10)
|
||||||
|
* @param fi1 (default to 71)
|
||||||
|
* @param fi2 (optional)
|
||||||
|
* @param fi3
|
||||||
|
* @param fn0 (optional, default to 10.0)
|
||||||
|
* @param fn1 (default to 71.0)
|
||||||
|
* @param fn2 (optional)
|
||||||
|
* @param fn3
|
||||||
|
* @return RequestConfig
|
||||||
|
*/
|
||||||
|
fun testRequestConfig(pi0: kotlin.Int, pi1: kotlin.Int, pn0: java.math.BigDecimal, pn1: java.math.BigDecimal, qi0: kotlin.Int?, qi1: kotlin.Int, qi2: kotlin.Int?, qi3: kotlin.Int, qn0: java.math.BigDecimal?, qn1: java.math.BigDecimal, qn2: java.math.BigDecimal?, qn3: java.math.BigDecimal, hi0: kotlin.Int?, hi1: kotlin.Int, hi2: kotlin.Int?, hi3: kotlin.Int, hn0: java.math.BigDecimal?, hn1: java.math.BigDecimal, hn2: java.math.BigDecimal?, hn3: java.math.BigDecimal, fi0: kotlin.Int?, fi1: kotlin.Int, fi2: kotlin.Int?, fi3: kotlin.Int, fn0: java.math.BigDecimal?, fn1: java.math.BigDecimal, fn2: java.math.BigDecimal?, fn3: java.math.BigDecimal) : RequestConfig<Map<String, PartConfig<*>>> {
|
||||||
|
val localVariableBody = mapOf(
|
||||||
|
"fi0" to PartConfig(body = fi0, headers = mutableMapOf()),
|
||||||
|
"fi1" to PartConfig(body = fi1, headers = mutableMapOf()),
|
||||||
|
"fi2" to PartConfig(body = fi2, headers = mutableMapOf()),
|
||||||
|
"fi3" to PartConfig(body = fi3, headers = mutableMapOf()),
|
||||||
|
"fn0" to PartConfig(body = fn0, headers = mutableMapOf()),
|
||||||
|
"fn1" to PartConfig(body = fn1, headers = mutableMapOf()),
|
||||||
|
"fn2" to PartConfig(body = fn2, headers = mutableMapOf()),
|
||||||
|
"fn3" to PartConfig(body = fn3, headers = mutableMapOf()),)
|
||||||
|
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
|
||||||
|
.apply {
|
||||||
|
if (qi0 != null) {
|
||||||
|
put("qi0", listOf(qi0.toString()))
|
||||||
|
}
|
||||||
|
put("qi1", listOf(qi1.toString()))
|
||||||
|
if (qi2 != null) {
|
||||||
|
put("qi2", listOf(qi2.toString()))
|
||||||
|
}
|
||||||
|
put("qi3", listOf(qi3.toString()))
|
||||||
|
if (qn0 != null) {
|
||||||
|
put("qn0", listOf(qn0.toString()))
|
||||||
|
}
|
||||||
|
put("qn1", listOf(qn1.toString()))
|
||||||
|
if (qn2 != null) {
|
||||||
|
put("qn2", listOf(qn2.toString()))
|
||||||
|
}
|
||||||
|
put("qn3", listOf(qn3.toString()))
|
||||||
|
}
|
||||||
|
val localVariableHeaders: MutableMap<String, String> = mutableMapOf("Content-Type" to "multipart/form-data")
|
||||||
|
hi0?.apply { localVariableHeaders["hi0"] = this.toString() }
|
||||||
|
hi1.apply { localVariableHeaders["hi1"] = this.toString() }
|
||||||
|
hi2?.apply { localVariableHeaders["hi2"] = this.toString() }
|
||||||
|
hi3.apply { localVariableHeaders["hi3"] = this.toString() }
|
||||||
|
hn0?.apply { localVariableHeaders["hn0"] = this.toString() }
|
||||||
|
hn1.apply { localVariableHeaders["hn1"] = this.toString() }
|
||||||
|
hn2?.apply { localVariableHeaders["hn2"] = this.toString() }
|
||||||
|
hn3.apply { localVariableHeaders["hn3"] = this.toString() }
|
||||||
|
|
||||||
|
return RequestConfig(
|
||||||
|
method = RequestMethod.POST,
|
||||||
|
path = "/test".replace("{"+"pi0"+"}", "$pi0").replace("{"+"pi1"+"}", "$pi1").replace("{"+"pn0"+"}", "$pn0").replace("{"+"pn1"+"}", "$pn1"),
|
||||||
|
query = localVariableQuery,
|
||||||
|
headers = localVariableHeaders,
|
||||||
|
body = localVariableBody
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
typealias MultiValueMap = MutableMap<String,List<String>>
|
||||||
|
|
||||||
|
fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) {
|
||||||
|
"csv" -> ","
|
||||||
|
"tsv" -> "\t"
|
||||||
|
"pipe" -> "|"
|
||||||
|
"space" -> " "
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" }
|
||||||
|
|
||||||
|
fun <T : Any?> toMultiValue(items: Array<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter)
|
||||||
|
= toMultiValue(items.asIterable(), collectionFormat, map)
|
||||||
|
|
||||||
|
fun <T : Any?> toMultiValue(items: Iterable<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List<String> {
|
||||||
|
return when(collectionFormat) {
|
||||||
|
"multi" -> items.map(map)
|
||||||
|
else -> listOf(items.joinToString(separator = collectionDelimiter(collectionFormat), transform = map))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,236 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.RequestBody
|
||||||
|
import okhttp3.MediaType
|
||||||
|
import okhttp3.FormBody
|
||||||
|
import okhttp3.HttpUrl
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.Headers
|
||||||
|
import okhttp3.MultipartBody
|
||||||
|
import okhttp3.Call
|
||||||
|
import okhttp3.Callback
|
||||||
|
import okhttp3.Response
|
||||||
|
import okhttp3.internal.Util.EMPTY_REQUEST
|
||||||
|
import java.io.BufferedWriter
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileWriter
|
||||||
|
import java.io.IOException
|
||||||
|
import java.net.URLConnection
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.LocalTime
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
import java.time.OffsetTime
|
||||||
|
import java.util.Locale
|
||||||
|
import com.squareup.moshi.adapter
|
||||||
|
|
||||||
|
open class ApiClient(val baseUrl: String) {
|
||||||
|
companion object {
|
||||||
|
protected const val ContentType = "Content-Type"
|
||||||
|
protected const val Accept = "Accept"
|
||||||
|
protected const val Authorization = "Authorization"
|
||||||
|
protected const val JsonMediaType = "application/json"
|
||||||
|
protected const val FormDataMediaType = "multipart/form-data"
|
||||||
|
protected const val FormUrlEncMediaType = "application/x-www-form-urlencoded"
|
||||||
|
protected const val XmlMediaType = "application/xml"
|
||||||
|
|
||||||
|
val apiKey: MutableMap<String, String> = mutableMapOf()
|
||||||
|
val apiKeyPrefix: MutableMap<String, String> = mutableMapOf()
|
||||||
|
var username: String? = null
|
||||||
|
var password: String? = null
|
||||||
|
var accessToken: String? = null
|
||||||
|
const val baseUrlKey = "org.openapitools.client.baseUrl"
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
val client: OkHttpClient by lazy {
|
||||||
|
builder.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guess Content-Type header from the given file (defaults to "application/octet-stream").
|
||||||
|
*
|
||||||
|
* @param file The given file
|
||||||
|
* @return The guessed Content-Type
|
||||||
|
*/
|
||||||
|
protected fun guessContentTypeFromFile(file: File): String {
|
||||||
|
val contentType = URLConnection.guessContentTypeFromName(file.name)
|
||||||
|
return contentType ?: "application/octet-stream"
|
||||||
|
}
|
||||||
|
|
||||||
|
protected inline fun <reified T> requestBody(content: T, mediaType: String?): RequestBody =
|
||||||
|
when {
|
||||||
|
mediaType == FormDataMediaType ->
|
||||||
|
MultipartBody.Builder()
|
||||||
|
.setType(MultipartBody.FORM)
|
||||||
|
.apply {
|
||||||
|
// content's type *must* be Map<String, PartConfig<*>>
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
(content as Map<String, PartConfig<*>>).forEach { (name, part) ->
|
||||||
|
val contentType = part.headers.remove("Content-Type")
|
||||||
|
val bodies = if (part.body is Iterable<*>) part.body else listOf(part.body)
|
||||||
|
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.of(headers),
|
||||||
|
requestSingleBody(body, contentType))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
else -> requestSingleBody(content, mediaType)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected inline fun <reified T> requestSingleBody(content: T, mediaType: String?): RequestBody =
|
||||||
|
when {
|
||||||
|
content is File -> RequestBody.create(MediaType.parse(mediaType ?: guessContentTypeFromFile(content)), content)
|
||||||
|
mediaType == FormUrlEncMediaType -> {
|
||||||
|
FormBody.Builder().apply {
|
||||||
|
// content's type *must* be Map<String, PartConfig<*>>
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
(content as Map<String, PartConfig<*>>).forEach { (name, part) ->
|
||||||
|
add(name, parameterToString(part.body))
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
}
|
||||||
|
mediaType == null || mediaType.startsWith("application/") && mediaType.endsWith("json") ->
|
||||||
|
if (content == null) {
|
||||||
|
EMPTY_REQUEST
|
||||||
|
} else {
|
||||||
|
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
|
||||||
|
else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
|
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
|
||||||
|
if(body == null) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (T::class.java == File::class.java) {
|
||||||
|
// return tempfile
|
||||||
|
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
|
||||||
|
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
|
||||||
|
f.deleteOnExit()
|
||||||
|
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) }
|
||||||
|
return f as T
|
||||||
|
}
|
||||||
|
val bodyContent = body.string()
|
||||||
|
if (bodyContent.isEmpty()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return when {
|
||||||
|
mediaType==null || (mediaType.startsWith("application/") && mediaType.endsWith("json")) ->
|
||||||
|
Serializer.moshi.adapter<T>().fromJson(bodyContent)
|
||||||
|
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected inline fun <reified I, reified T: Any?> request(requestConfig: RequestConfig<I>): ApiResponse<T?> {
|
||||||
|
val httpUrl = HttpUrl.parse(baseUrl) ?: throw IllegalStateException("baseUrl is invalid.")
|
||||||
|
|
||||||
|
val url = httpUrl.newBuilder()
|
||||||
|
.addPathSegments(requestConfig.path.trimStart('/'))
|
||||||
|
.apply {
|
||||||
|
requestConfig.query.forEach { query ->
|
||||||
|
query.value.forEach { queryValue ->
|
||||||
|
addQueryParameter(query.key, queryValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
|
||||||
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
|
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
|
}
|
||||||
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
|
requestConfig.headers[Accept] = JsonMediaType
|
||||||
|
}
|
||||||
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
|
if(headers[ContentType].isNullOrEmpty()) {
|
||||||
|
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if(headers[Accept].isNullOrEmpty()) {
|
||||||
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: support multiple contentType options here.
|
||||||
|
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
|
||||||
|
val request = when (requestConfig.method) {
|
||||||
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
RequestMethod.GET -> Request.Builder().url(url)
|
||||||
|
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
||||||
|
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType))
|
||||||
|
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType))
|
||||||
|
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType))
|
||||||
|
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
||||||
|
}.apply {
|
||||||
|
headers.forEach { header -> addHeader(header.key, header.value) }
|
||||||
|
}.build()
|
||||||
|
|
||||||
|
val response = client.newCall(request).execute()
|
||||||
|
|
||||||
|
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.getDefault())
|
||||||
|
|
||||||
|
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
|
||||||
|
return when {
|
||||||
|
response.isRedirect -> Redirection(
|
||||||
|
response.code(),
|
||||||
|
response.headers().toMultimap()
|
||||||
|
)
|
||||||
|
response.isInformational -> Informational(
|
||||||
|
response.message(),
|
||||||
|
response.code(),
|
||||||
|
response.headers().toMultimap()
|
||||||
|
)
|
||||||
|
response.isSuccessful -> Success(
|
||||||
|
responseBody(response.body(), accept),
|
||||||
|
response.code(),
|
||||||
|
response.headers().toMultimap()
|
||||||
|
)
|
||||||
|
response.isClientError -> ClientError(
|
||||||
|
response.message(),
|
||||||
|
response.body()?.string(),
|
||||||
|
response.code(),
|
||||||
|
response.headers().toMultimap()
|
||||||
|
)
|
||||||
|
else -> ServerError(
|
||||||
|
response.message(),
|
||||||
|
response.body()?.string(),
|
||||||
|
response.code(),
|
||||||
|
response.headers().toMultimap()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun parameterToString(value: Any?): String = when (value) {
|
||||||
|
null -> ""
|
||||||
|
is Array<*> -> toMultiValue(value, "csv").toString()
|
||||||
|
is Iterable<*> -> toMultiValue(value, "csv").toString()
|
||||||
|
is OffsetDateTime, is OffsetTime, is LocalDateTime, is LocalDate, is LocalTime ->
|
||||||
|
parseDateToQueryString(value)
|
||||||
|
else -> value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
||||||
|
/*
|
||||||
|
.replace("\"", "") converts the json object string to an actual string for the query parameter.
|
||||||
|
The moshi or gson adapter allows a more generic solution instead of trying to use a native
|
||||||
|
formatter. It also easily allows to provide a simple way to define a custom date format pattern
|
||||||
|
inside a gson/moshi adapter.
|
||||||
|
*/
|
||||||
|
return Serializer.moshi.adapter(T::class.java).toJson(value).replace("\"", "")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
enum class ResponseType {
|
||||||
|
Success, Informational, Redirection, ClientError, ServerError
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Response
|
||||||
|
|
||||||
|
abstract class ApiResponse<T>(val responseType: ResponseType): Response {
|
||||||
|
abstract val statusCode: Int
|
||||||
|
abstract val headers: Map<String,List<String>>
|
||||||
|
}
|
||||||
|
|
||||||
|
class Success<T>(
|
||||||
|
val data: T,
|
||||||
|
override val statusCode: Int = -1,
|
||||||
|
override val headers: Map<String, List<String>> = mapOf()
|
||||||
|
): ApiResponse<T>(ResponseType.Success)
|
||||||
|
|
||||||
|
class Informational<T>(
|
||||||
|
val statusText: String,
|
||||||
|
override val statusCode: Int = -1,
|
||||||
|
override val headers: Map<String, List<String>> = mapOf()
|
||||||
|
) : ApiResponse<T>(ResponseType.Informational)
|
||||||
|
|
||||||
|
class Redirection<T>(
|
||||||
|
override val statusCode: Int = -1,
|
||||||
|
override val headers: Map<String, List<String>> = mapOf()
|
||||||
|
) : ApiResponse<T>(ResponseType.Redirection)
|
||||||
|
|
||||||
|
class ClientError<T>(
|
||||||
|
val message: String? = null,
|
||||||
|
val body: Any? = null,
|
||||||
|
override val statusCode: Int = -1,
|
||||||
|
override val headers: Map<String, List<String>> = mapOf()
|
||||||
|
) : ApiResponse<T>(ResponseType.ClientError)
|
||||||
|
|
||||||
|
class ServerError<T>(
|
||||||
|
val message: String? = null,
|
||||||
|
val body: Any? = null,
|
||||||
|
override val statusCode: Int = -1,
|
||||||
|
override val headers: Map<String, List<String>>
|
||||||
|
): ApiResponse<T>(ResponseType.ServerError)
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -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()
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
@file:Suppress("unused")
|
||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
import java.lang.RuntimeException
|
||||||
|
|
||||||
|
open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val serialVersionUID: Long = 123L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val serialVersionUID: Long = 456L
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<String,String> because rfc2616 defines
|
||||||
|
* multi-valued headers as csv-only.
|
||||||
|
*/
|
||||||
|
data class PartConfig<T>(
|
||||||
|
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||||
|
val body: T? = null
|
||||||
|
)
|
@ -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<String,String> because rfc2616 defines
|
||||||
|
* multi-valued headers as csv-only.
|
||||||
|
*/
|
||||||
|
data class RequestConfig<T>(
|
||||||
|
val method: RequestMethod,
|
||||||
|
val path: String,
|
||||||
|
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||||
|
val query: MutableMap<String, List<String>> = mutableMapOf(),
|
||||||
|
val body: T? = null
|
||||||
|
)
|
@ -0,0 +1,8 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides enumerated HTTP verbs
|
||||||
|
*/
|
||||||
|
enum class RequestMethod {
|
||||||
|
GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an extension to evaluation whether the response is a 4xx code
|
||||||
|
*/
|
||||||
|
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
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* 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 i0
|
||||||
|
* @param n0
|
||||||
|
* @param i1
|
||||||
|
* @param n1
|
||||||
|
*/
|
||||||
|
|
||||||
|
data class Apa (
|
||||||
|
|
||||||
|
@Json(name = "i0")
|
||||||
|
val i0: kotlin.Int,
|
||||||
|
|
||||||
|
@Json(name = "n0")
|
||||||
|
val n0: java.math.BigDecimal,
|
||||||
|
|
||||||
|
@Json(name = "i1")
|
||||||
|
val i1: kotlin.Int? = null,
|
||||||
|
|
||||||
|
@Json(name = "n1")
|
||||||
|
val n1: java.math.BigDecimal? = null
|
||||||
|
|
||||||
|
)
|
||||||
|
|
@ -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
|
@ -0,0 +1,28 @@
|
|||||||
|
README.md
|
||||||
|
build.gradle
|
||||||
|
docs/Apa.md
|
||||||
|
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/ApiAbstractions.kt
|
||||||
|
src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
|
||||||
|
src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.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/Errors.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/PartConfig.kt
|
||||||
|
src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt
|
||||||
|
src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt
|
||||||
|
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
|
@ -0,0 +1 @@
|
|||||||
|
6.0.0-SNAPSHOT
|
@ -0,0 +1,50 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
<a name="documentation-for-api-endpoints"></a>
|
||||||
|
## Documentation for API Endpoints
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Class | Method | HTTP request | Description
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
*DefaultApi* | [**test**](docs/DefaultApi.md#test) | **POST** /test | Tests default values
|
||||||
|
|
||||||
|
|
||||||
|
<a name="documentation-for-models"></a>
|
||||||
|
## Documentation for Models
|
||||||
|
|
||||||
|
- [org.openapitools.client.models.Apa](docs/Apa.md)
|
||||||
|
|
||||||
|
|
||||||
|
<a name="documentation-for-authorization"></a>
|
||||||
|
## Documentation for Authorization
|
||||||
|
|
||||||
|
All endpoints do not require authorization.
|
@ -0,0 +1,37 @@
|
|||||||
|
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'
|
||||||
|
|
||||||
|
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:okhttp:4.9.1"
|
||||||
|
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
# Apa
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**i0** | **kotlin.Int** | |
|
||||||
|
**n0** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | |
|
||||||
|
**i1** | **kotlin.Int** | | [optional]
|
||||||
|
**n1** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | | [optional]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,109 @@
|
|||||||
|
# DefaultApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**test**](DefaultApi.md#test) | **POST** /test | Tests default values
|
||||||
|
|
||||||
|
|
||||||
|
<a name="test"></a>
|
||||||
|
# **test**
|
||||||
|
> test(pi0, pi1, pn0, pn1, qi0, qi1, qi2, qi3, qn0, qn1, qn2, qn3, hi0, hi1, hi2, hi3, hn0, hn1, hn2, hn3, fi0, fi1, fi2, fi3, fn0, fn1, fn2, fn3)
|
||||||
|
|
||||||
|
Tests default values
|
||||||
|
|
||||||
|
Tests default values of different parameters
|
||||||
|
|
||||||
|
### Example
|
||||||
|
```kotlin
|
||||||
|
// Import classes:
|
||||||
|
//import org.openapitools.client.infrastructure.*
|
||||||
|
//import org.openapitools.client.models.*
|
||||||
|
|
||||||
|
val apiInstance = DefaultApi()
|
||||||
|
val pi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val pi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val pn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val pn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qi2 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qi3 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qn2 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qn3 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hi2 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hi3 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hn2 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hn3 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fi2 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fi3 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fn2 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fn3 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
try {
|
||||||
|
apiInstance.test(pi0, pi1, pn0, pn1, qi0, qi1, qi2, qi3, qn0, qn1, qn2, qn3, hi0, hi1, hi2, hi3, hn0, hn1, hn2, hn3, fi0, fi1, fi2, fi3, fn0, fn1, fn2, fn3)
|
||||||
|
} catch (e: ClientException) {
|
||||||
|
println("4xx response calling DefaultApi#test")
|
||||||
|
e.printStackTrace()
|
||||||
|
} catch (e: ServerException) {
|
||||||
|
println("5xx response calling DefaultApi#test")
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**pi0** | **kotlin.Int**| | [default to 10]
|
||||||
|
**pi1** | **kotlin.Int**| |
|
||||||
|
**pn0** | **java.math.BigDecimal**| | [default to 10.0]
|
||||||
|
**pn1** | **java.math.BigDecimal**| |
|
||||||
|
**qi0** | **kotlin.Int**| | [optional] [default to 10]
|
||||||
|
**qi1** | **kotlin.Int**| | [default to 71]
|
||||||
|
**qi2** | **kotlin.Int**| | [optional]
|
||||||
|
**qi3** | **kotlin.Int**| |
|
||||||
|
**qn0** | **java.math.BigDecimal**| | [optional] [default to 10.0]
|
||||||
|
**qn1** | **java.math.BigDecimal**| | [default to 71.0]
|
||||||
|
**qn2** | **java.math.BigDecimal**| | [optional]
|
||||||
|
**qn3** | **java.math.BigDecimal**| |
|
||||||
|
**hi0** | **kotlin.Int**| | [optional] [default to 10]
|
||||||
|
**hi1** | **kotlin.Int**| | [default to 71]
|
||||||
|
**hi2** | **kotlin.Int**| | [optional]
|
||||||
|
**hi3** | **kotlin.Int**| |
|
||||||
|
**hn0** | **java.math.BigDecimal**| | [optional] [default to 10.0]
|
||||||
|
**hn1** | **java.math.BigDecimal**| | [default to 71.0]
|
||||||
|
**hn2** | **java.math.BigDecimal**| | [optional]
|
||||||
|
**hn3** | **java.math.BigDecimal**| |
|
||||||
|
**fi0** | **kotlin.Int**| | [optional] [default to 10]
|
||||||
|
**fi1** | **kotlin.Int**| | [default to 71]
|
||||||
|
**fi2** | **kotlin.Int**| | [optional]
|
||||||
|
**fi3** | **kotlin.Int**| |
|
||||||
|
**fn0** | **java.math.BigDecimal**| | [optional] [default to 10.0]
|
||||||
|
**fn1** | **java.math.BigDecimal**| | [default to 71.0]
|
||||||
|
**fn2** | **java.math.BigDecimal**| | [optional]
|
||||||
|
**fn3** | **java.math.BigDecimal**| |
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
null (empty response body)
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: multipart/form-data
|
||||||
|
- **Accept**: Not defined
|
||||||
|
|
BIN
samples/client/petstore/kotlin-default-values-jvm-okhttp4/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
samples/client/petstore/kotlin-default-values-jvm-okhttp4/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
@ -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
|
185
samples/client/petstore/kotlin-default-values-jvm-okhttp4/gradlew
vendored
Normal file
185
samples/client/petstore/kotlin-default-values-jvm-okhttp4/gradlew
vendored
Normal file
@ -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" "$@"
|
89
samples/client/petstore/kotlin-default-values-jvm-okhttp4/gradlew.bat
vendored
Normal file
89
samples/client/petstore/kotlin-default-values-jvm-okhttp4/gradlew.bat
vendored
Normal file
@ -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
|
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
rootProject.name = 'kotlin-default-values-jvm-okhttp4'
|
@ -0,0 +1,232 @@
|
|||||||
|
/**
|
||||||
|
* 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 java.io.IOException
|
||||||
|
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
|
||||||
|
import org.openapitools.client.infrastructure.ApiClient
|
||||||
|
import org.openapitools.client.infrastructure.ApiResponse
|
||||||
|
import org.openapitools.client.infrastructure.ClientException
|
||||||
|
import org.openapitools.client.infrastructure.ClientError
|
||||||
|
import org.openapitools.client.infrastructure.ServerException
|
||||||
|
import org.openapitools.client.infrastructure.ServerError
|
||||||
|
import org.openapitools.client.infrastructure.MultiValueMap
|
||||||
|
import org.openapitools.client.infrastructure.PartConfig
|
||||||
|
import org.openapitools.client.infrastructure.RequestConfig
|
||||||
|
import org.openapitools.client.infrastructure.RequestMethod
|
||||||
|
import org.openapitools.client.infrastructure.ResponseType
|
||||||
|
import org.openapitools.client.infrastructure.Success
|
||||||
|
import org.openapitools.client.infrastructure.toMultiValue
|
||||||
|
|
||||||
|
class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
val defaultBasePath: String by lazy {
|
||||||
|
System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests default values
|
||||||
|
* Tests default values of different parameters
|
||||||
|
* @param pi0 (default to 10)
|
||||||
|
* @param pi1
|
||||||
|
* @param pn0 (default to 10.0)
|
||||||
|
* @param pn1
|
||||||
|
* @param qi0 (optional, default to 10)
|
||||||
|
* @param qi1 (default to 71)
|
||||||
|
* @param qi2 (optional)
|
||||||
|
* @param qi3
|
||||||
|
* @param qn0 (optional, default to 10.0)
|
||||||
|
* @param qn1 (default to 71.0)
|
||||||
|
* @param qn2 (optional)
|
||||||
|
* @param qn3
|
||||||
|
* @param hi0 (optional, default to 10)
|
||||||
|
* @param hi1 (default to 71)
|
||||||
|
* @param hi2 (optional)
|
||||||
|
* @param hi3
|
||||||
|
* @param hn0 (optional, default to 10.0)
|
||||||
|
* @param hn1 (default to 71.0)
|
||||||
|
* @param hn2 (optional)
|
||||||
|
* @param hn3
|
||||||
|
* @param fi0 (optional, default to 10)
|
||||||
|
* @param fi1 (default to 71)
|
||||||
|
* @param fi2 (optional)
|
||||||
|
* @param fi3
|
||||||
|
* @param fn0 (optional, default to 10.0)
|
||||||
|
* @param fn1 (default to 71.0)
|
||||||
|
* @param fn2 (optional)
|
||||||
|
* @param fn3
|
||||||
|
* @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 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 localVarResponse = testWithHttpInfo(pi0 = pi0, pi1 = pi1, pn0 = pn0, pn1 = pn1, qi0 = qi0, qi1 = qi1, qi2 = qi2, qi3 = qi3, qn0 = qn0, qn1 = qn1, qn2 = qn2, qn3 = qn3, hi0 = hi0, hi1 = hi1, hi2 = hi2, hi3 = hi3, hn0 = hn0, hn1 = hn1, hn2 = hn2, hn3 = hn3, fi0 = fi0, fi1 = fi1, fi2 = fi2, fi3 = fi3, fn0 = fn0, fn1 = fn1, fn2 = fn2, fn3 = fn3)
|
||||||
|
|
||||||
|
return when (localVarResponse.responseType) {
|
||||||
|
ResponseType.Success -> Unit
|
||||||
|
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||||
|
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||||
|
ResponseType.ClientError -> {
|
||||||
|
val localVarError = localVarResponse as ClientError<*>
|
||||||
|
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||||
|
}
|
||||||
|
ResponseType.ServerError -> {
|
||||||
|
val localVarError = localVarResponse as ServerError<*>
|
||||||
|
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests default values
|
||||||
|
* Tests default values of different parameters
|
||||||
|
* @param pi0 (default to 10)
|
||||||
|
* @param pi1
|
||||||
|
* @param pn0 (default to 10.0)
|
||||||
|
* @param pn1
|
||||||
|
* @param qi0 (optional, default to 10)
|
||||||
|
* @param qi1 (default to 71)
|
||||||
|
* @param qi2 (optional)
|
||||||
|
* @param qi3
|
||||||
|
* @param qn0 (optional, default to 10.0)
|
||||||
|
* @param qn1 (default to 71.0)
|
||||||
|
* @param qn2 (optional)
|
||||||
|
* @param qn3
|
||||||
|
* @param hi0 (optional, default to 10)
|
||||||
|
* @param hi1 (default to 71)
|
||||||
|
* @param hi2 (optional)
|
||||||
|
* @param hi3
|
||||||
|
* @param hn0 (optional, default to 10.0)
|
||||||
|
* @param hn1 (default to 71.0)
|
||||||
|
* @param hn2 (optional)
|
||||||
|
* @param hn3
|
||||||
|
* @param fi0 (optional, default to 10)
|
||||||
|
* @param fi1 (default to 71)
|
||||||
|
* @param fi2 (optional)
|
||||||
|
* @param fi3
|
||||||
|
* @param fn0 (optional, default to 10.0)
|
||||||
|
* @param fn1 (default to 71.0)
|
||||||
|
* @param fn2 (optional)
|
||||||
|
* @param fn3
|
||||||
|
* @return ApiResponse<Unit?>
|
||||||
|
* @throws IllegalStateException If the request is not correctly configured
|
||||||
|
* @throws IOException Rethrows the OkHttp execute method exception
|
||||||
|
*/
|
||||||
|
@Throws(IllegalStateException::class, IOException::class)
|
||||||
|
fun testWithHttpInfo(pi0: kotlin.Int, pi1: kotlin.Int, pn0: java.math.BigDecimal, pn1: java.math.BigDecimal, qi0: kotlin.Int?, qi1: kotlin.Int, qi2: kotlin.Int?, qi3: kotlin.Int, qn0: java.math.BigDecimal?, qn1: java.math.BigDecimal, qn2: java.math.BigDecimal?, qn3: java.math.BigDecimal, hi0: kotlin.Int?, hi1: kotlin.Int, hi2: kotlin.Int?, hi3: kotlin.Int, hn0: java.math.BigDecimal?, hn1: java.math.BigDecimal, hn2: java.math.BigDecimal?, hn3: java.math.BigDecimal, fi0: kotlin.Int?, fi1: kotlin.Int, fi2: kotlin.Int?, fi3: kotlin.Int, fn0: java.math.BigDecimal?, fn1: java.math.BigDecimal, fn2: java.math.BigDecimal?, fn3: java.math.BigDecimal) : ApiResponse<Unit?> {
|
||||||
|
val localVariableConfig = testRequestConfig(pi0 = pi0, pi1 = pi1, pn0 = pn0, pn1 = pn1, qi0 = qi0, qi1 = qi1, qi2 = qi2, qi3 = qi3, qn0 = qn0, qn1 = qn1, qn2 = qn2, qn3 = qn3, hi0 = hi0, hi1 = hi1, hi2 = hi2, hi3 = hi3, hn0 = hn0, hn1 = hn1, hn2 = hn2, hn3 = hn3, fi0 = fi0, fi1 = fi1, fi2 = fi2, fi3 = fi3, fn0 = fn0, fn1 = fn1, fn2 = fn2, fn3 = fn3)
|
||||||
|
|
||||||
|
return request<Map<String, PartConfig<*>>, Unit>(
|
||||||
|
localVariableConfig
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To obtain the request config of the operation test
|
||||||
|
*
|
||||||
|
* @param pi0 (default to 10)
|
||||||
|
* @param pi1
|
||||||
|
* @param pn0 (default to 10.0)
|
||||||
|
* @param pn1
|
||||||
|
* @param qi0 (optional, default to 10)
|
||||||
|
* @param qi1 (default to 71)
|
||||||
|
* @param qi2 (optional)
|
||||||
|
* @param qi3
|
||||||
|
* @param qn0 (optional, default to 10.0)
|
||||||
|
* @param qn1 (default to 71.0)
|
||||||
|
* @param qn2 (optional)
|
||||||
|
* @param qn3
|
||||||
|
* @param hi0 (optional, default to 10)
|
||||||
|
* @param hi1 (default to 71)
|
||||||
|
* @param hi2 (optional)
|
||||||
|
* @param hi3
|
||||||
|
* @param hn0 (optional, default to 10.0)
|
||||||
|
* @param hn1 (default to 71.0)
|
||||||
|
* @param hn2 (optional)
|
||||||
|
* @param hn3
|
||||||
|
* @param fi0 (optional, default to 10)
|
||||||
|
* @param fi1 (default to 71)
|
||||||
|
* @param fi2 (optional)
|
||||||
|
* @param fi3
|
||||||
|
* @param fn0 (optional, default to 10.0)
|
||||||
|
* @param fn1 (default to 71.0)
|
||||||
|
* @param fn2 (optional)
|
||||||
|
* @param fn3
|
||||||
|
* @return RequestConfig
|
||||||
|
*/
|
||||||
|
fun testRequestConfig(pi0: kotlin.Int, pi1: kotlin.Int, pn0: java.math.BigDecimal, pn1: java.math.BigDecimal, qi0: kotlin.Int?, qi1: kotlin.Int, qi2: kotlin.Int?, qi3: kotlin.Int, qn0: java.math.BigDecimal?, qn1: java.math.BigDecimal, qn2: java.math.BigDecimal?, qn3: java.math.BigDecimal, hi0: kotlin.Int?, hi1: kotlin.Int, hi2: kotlin.Int?, hi3: kotlin.Int, hn0: java.math.BigDecimal?, hn1: java.math.BigDecimal, hn2: java.math.BigDecimal?, hn3: java.math.BigDecimal, fi0: kotlin.Int?, fi1: kotlin.Int, fi2: kotlin.Int?, fi3: kotlin.Int, fn0: java.math.BigDecimal?, fn1: java.math.BigDecimal, fn2: java.math.BigDecimal?, fn3: java.math.BigDecimal) : RequestConfig<Map<String, PartConfig<*>>> {
|
||||||
|
val localVariableBody = mapOf(
|
||||||
|
"fi0" to PartConfig(body = fi0, headers = mutableMapOf()),
|
||||||
|
"fi1" to PartConfig(body = fi1, headers = mutableMapOf()),
|
||||||
|
"fi2" to PartConfig(body = fi2, headers = mutableMapOf()),
|
||||||
|
"fi3" to PartConfig(body = fi3, headers = mutableMapOf()),
|
||||||
|
"fn0" to PartConfig(body = fn0, headers = mutableMapOf()),
|
||||||
|
"fn1" to PartConfig(body = fn1, headers = mutableMapOf()),
|
||||||
|
"fn2" to PartConfig(body = fn2, headers = mutableMapOf()),
|
||||||
|
"fn3" to PartConfig(body = fn3, headers = mutableMapOf()),)
|
||||||
|
val localVariableQuery: MultiValueMap = mutableMapOf<kotlin.String, kotlin.collections.List<kotlin.String>>()
|
||||||
|
.apply {
|
||||||
|
if (qi0 != null) {
|
||||||
|
put("qi0", listOf(qi0.toString()))
|
||||||
|
}
|
||||||
|
put("qi1", listOf(qi1.toString()))
|
||||||
|
if (qi2 != null) {
|
||||||
|
put("qi2", listOf(qi2.toString()))
|
||||||
|
}
|
||||||
|
put("qi3", listOf(qi3.toString()))
|
||||||
|
if (qn0 != null) {
|
||||||
|
put("qn0", listOf(qn0.toString()))
|
||||||
|
}
|
||||||
|
put("qn1", listOf(qn1.toString()))
|
||||||
|
if (qn2 != null) {
|
||||||
|
put("qn2", listOf(qn2.toString()))
|
||||||
|
}
|
||||||
|
put("qn3", listOf(qn3.toString()))
|
||||||
|
}
|
||||||
|
val localVariableHeaders: MutableMap<String, String> = mutableMapOf("Content-Type" to "multipart/form-data")
|
||||||
|
hi0?.apply { localVariableHeaders["hi0"] = this.toString() }
|
||||||
|
hi1.apply { localVariableHeaders["hi1"] = this.toString() }
|
||||||
|
hi2?.apply { localVariableHeaders["hi2"] = this.toString() }
|
||||||
|
hi3.apply { localVariableHeaders["hi3"] = this.toString() }
|
||||||
|
hn0?.apply { localVariableHeaders["hn0"] = this.toString() }
|
||||||
|
hn1.apply { localVariableHeaders["hn1"] = this.toString() }
|
||||||
|
hn2?.apply { localVariableHeaders["hn2"] = this.toString() }
|
||||||
|
hn3.apply { localVariableHeaders["hn3"] = this.toString() }
|
||||||
|
|
||||||
|
return RequestConfig(
|
||||||
|
method = RequestMethod.POST,
|
||||||
|
path = "/test".replace("{"+"pi0"+"}", "$pi0").replace("{"+"pi1"+"}", "$pi1").replace("{"+"pn0"+"}", "$pn0").replace("{"+"pn1"+"}", "$pn1"),
|
||||||
|
query = localVariableQuery,
|
||||||
|
headers = localVariableHeaders,
|
||||||
|
body = localVariableBody
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
typealias MultiValueMap = MutableMap<String,List<String>>
|
||||||
|
|
||||||
|
fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) {
|
||||||
|
"csv" -> ","
|
||||||
|
"tsv" -> "\t"
|
||||||
|
"pipe" -> "|"
|
||||||
|
"space" -> " "
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
|
||||||
|
val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" }
|
||||||
|
|
||||||
|
fun <T : Any?> toMultiValue(items: Array<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter)
|
||||||
|
= toMultiValue(items.asIterable(), collectionFormat, map)
|
||||||
|
|
||||||
|
fun <T : Any?> toMultiValue(items: Iterable<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List<String> {
|
||||||
|
return when(collectionFormat) {
|
||||||
|
"multi" -> items.map(map)
|
||||||
|
else -> listOf(items.joinToString(separator = collectionDelimiter(collectionFormat), transform = map))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,238 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.RequestBody
|
||||||
|
import okhttp3.RequestBody.Companion.asRequestBody
|
||||||
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
import okhttp3.FormBody
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
|
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 java.io.BufferedWriter
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileWriter
|
||||||
|
import java.io.IOException
|
||||||
|
import java.net.URLConnection
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.LocalTime
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
import java.time.OffsetTime
|
||||||
|
import java.util.Locale
|
||||||
|
import com.squareup.moshi.adapter
|
||||||
|
|
||||||
|
open class ApiClient(val baseUrl: String) {
|
||||||
|
companion object {
|
||||||
|
protected const val ContentType = "Content-Type"
|
||||||
|
protected const val Accept = "Accept"
|
||||||
|
protected const val Authorization = "Authorization"
|
||||||
|
protected const val JsonMediaType = "application/json"
|
||||||
|
protected const val FormDataMediaType = "multipart/form-data"
|
||||||
|
protected const val FormUrlEncMediaType = "application/x-www-form-urlencoded"
|
||||||
|
protected const val XmlMediaType = "application/xml"
|
||||||
|
|
||||||
|
val apiKey: MutableMap<String, String> = mutableMapOf()
|
||||||
|
val apiKeyPrefix: MutableMap<String, String> = mutableMapOf()
|
||||||
|
var username: String? = null
|
||||||
|
var password: String? = null
|
||||||
|
var accessToken: String? = null
|
||||||
|
const val baseUrlKey = "org.openapitools.client.baseUrl"
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
val client: OkHttpClient by lazy {
|
||||||
|
builder.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
val builder: OkHttpClient.Builder = OkHttpClient.Builder()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guess Content-Type header from the given file (defaults to "application/octet-stream").
|
||||||
|
*
|
||||||
|
* @param file The given file
|
||||||
|
* @return The guessed Content-Type
|
||||||
|
*/
|
||||||
|
protected fun guessContentTypeFromFile(file: File): String {
|
||||||
|
val contentType = URLConnection.guessContentTypeFromName(file.name)
|
||||||
|
return contentType ?: "application/octet-stream"
|
||||||
|
}
|
||||||
|
|
||||||
|
protected inline fun <reified T> requestBody(content: T, mediaType: String?): RequestBody =
|
||||||
|
when {
|
||||||
|
mediaType == FormDataMediaType ->
|
||||||
|
MultipartBody.Builder()
|
||||||
|
.setType(MultipartBody.FORM)
|
||||||
|
.apply {
|
||||||
|
// content's type *must* be Map<String, PartConfig<*>>
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
(content as Map<String, PartConfig<*>>).forEach { (name, part) ->
|
||||||
|
val contentType = part.headers.remove("Content-Type")
|
||||||
|
val bodies = if (part.body is Iterable<*>) part.body else listOf(part.body)
|
||||||
|
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(),
|
||||||
|
requestSingleBody(body, contentType))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
else -> requestSingleBody(content, mediaType)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected inline fun <reified T> requestSingleBody(content: T, mediaType: String?): RequestBody =
|
||||||
|
when {
|
||||||
|
content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull())
|
||||||
|
mediaType == FormUrlEncMediaType -> {
|
||||||
|
FormBody.Builder().apply {
|
||||||
|
// content's type *must* be Map<String, PartConfig<*>>
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
(content as Map<String, PartConfig<*>>).forEach { (name, part) ->
|
||||||
|
add(name, parameterToString(part.body))
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
}
|
||||||
|
mediaType == null || mediaType.startsWith("application/") && mediaType.endsWith("json") ->
|
||||||
|
if (content == null) {
|
||||||
|
EMPTY_REQUEST
|
||||||
|
} else {
|
||||||
|
Serializer.moshi.adapter(T::class.java).toJson(content)
|
||||||
|
.toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull())
|
||||||
|
}
|
||||||
|
mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
|
||||||
|
// TODO: this should be extended with other serializers
|
||||||
|
else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
|
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
|
||||||
|
if(body == null) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (T::class.java == File::class.java) {
|
||||||
|
// return tempfile
|
||||||
|
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
|
||||||
|
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
|
||||||
|
f.deleteOnExit()
|
||||||
|
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) }
|
||||||
|
return f as T
|
||||||
|
}
|
||||||
|
val bodyContent = body.string()
|
||||||
|
if (bodyContent.isEmpty()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return when {
|
||||||
|
mediaType==null || (mediaType.startsWith("application/") && mediaType.endsWith("json")) ->
|
||||||
|
Serializer.moshi.adapter<T>().fromJson(bodyContent)
|
||||||
|
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected inline fun <reified I, reified T: Any?> request(requestConfig: RequestConfig<I>): ApiResponse<T?> {
|
||||||
|
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||||
|
|
||||||
|
val url = httpUrl.newBuilder()
|
||||||
|
.addPathSegments(requestConfig.path.trimStart('/'))
|
||||||
|
.apply {
|
||||||
|
requestConfig.query.forEach { query ->
|
||||||
|
query.value.forEach { queryValue ->
|
||||||
|
addQueryParameter(query.key, queryValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
|
||||||
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
|
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
|
}
|
||||||
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
|
requestConfig.headers[Accept] = JsonMediaType
|
||||||
|
}
|
||||||
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
|
if(headers[ContentType].isNullOrEmpty()) {
|
||||||
|
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if(headers[Accept].isNullOrEmpty()) {
|
||||||
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: support multiple contentType options here.
|
||||||
|
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
|
||||||
|
val request = when (requestConfig.method) {
|
||||||
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
RequestMethod.GET -> Request.Builder().url(url)
|
||||||
|
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
||||||
|
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType))
|
||||||
|
RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType))
|
||||||
|
RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType))
|
||||||
|
RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null)
|
||||||
|
}.apply {
|
||||||
|
headers.forEach { header -> addHeader(header.key, header.value) }
|
||||||
|
}.build()
|
||||||
|
|
||||||
|
val response = client.newCall(request).execute()
|
||||||
|
|
||||||
|
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.getDefault())
|
||||||
|
|
||||||
|
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
|
||||||
|
return when {
|
||||||
|
response.isRedirect -> Redirection(
|
||||||
|
response.code,
|
||||||
|
response.headers.toMultimap()
|
||||||
|
)
|
||||||
|
response.isInformational -> Informational(
|
||||||
|
response.message,
|
||||||
|
response.code,
|
||||||
|
response.headers.toMultimap()
|
||||||
|
)
|
||||||
|
response.isSuccessful -> Success(
|
||||||
|
responseBody(response.body, accept),
|
||||||
|
response.code,
|
||||||
|
response.headers.toMultimap()
|
||||||
|
)
|
||||||
|
response.isClientError -> ClientError(
|
||||||
|
response.message,
|
||||||
|
response.body?.string(),
|
||||||
|
response.code,
|
||||||
|
response.headers.toMultimap()
|
||||||
|
)
|
||||||
|
else -> ServerError(
|
||||||
|
response.message,
|
||||||
|
response.body?.string(),
|
||||||
|
response.code,
|
||||||
|
response.headers.toMultimap()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun parameterToString(value: Any?): String = when (value) {
|
||||||
|
null -> ""
|
||||||
|
is Array<*> -> toMultiValue(value, "csv").toString()
|
||||||
|
is Iterable<*> -> toMultiValue(value, "csv").toString()
|
||||||
|
is OffsetDateTime, is OffsetTime, is LocalDateTime, is LocalDate, is LocalTime ->
|
||||||
|
parseDateToQueryString(value)
|
||||||
|
else -> value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
||||||
|
/*
|
||||||
|
.replace("\"", "") converts the json object string to an actual string for the query parameter.
|
||||||
|
The moshi or gson adapter allows a more generic solution instead of trying to use a native
|
||||||
|
formatter. It also easily allows to provide a simple way to define a custom date format pattern
|
||||||
|
inside a gson/moshi adapter.
|
||||||
|
*/
|
||||||
|
return Serializer.moshi.adapter(T::class.java).toJson(value).replace("\"", "")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
enum class ResponseType {
|
||||||
|
Success, Informational, Redirection, ClientError, ServerError
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Response
|
||||||
|
|
||||||
|
abstract class ApiResponse<T>(val responseType: ResponseType): Response {
|
||||||
|
abstract val statusCode: Int
|
||||||
|
abstract val headers: Map<String,List<String>>
|
||||||
|
}
|
||||||
|
|
||||||
|
class Success<T>(
|
||||||
|
val data: T,
|
||||||
|
override val statusCode: Int = -1,
|
||||||
|
override val headers: Map<String, List<String>> = mapOf()
|
||||||
|
): ApiResponse<T>(ResponseType.Success)
|
||||||
|
|
||||||
|
class Informational<T>(
|
||||||
|
val statusText: String,
|
||||||
|
override val statusCode: Int = -1,
|
||||||
|
override val headers: Map<String, List<String>> = mapOf()
|
||||||
|
) : ApiResponse<T>(ResponseType.Informational)
|
||||||
|
|
||||||
|
class Redirection<T>(
|
||||||
|
override val statusCode: Int = -1,
|
||||||
|
override val headers: Map<String, List<String>> = mapOf()
|
||||||
|
) : ApiResponse<T>(ResponseType.Redirection)
|
||||||
|
|
||||||
|
class ClientError<T>(
|
||||||
|
val message: String? = null,
|
||||||
|
val body: Any? = null,
|
||||||
|
override val statusCode: Int = -1,
|
||||||
|
override val headers: Map<String, List<String>> = mapOf()
|
||||||
|
) : ApiResponse<T>(ResponseType.ClientError)
|
||||||
|
|
||||||
|
class ServerError<T>(
|
||||||
|
val message: String? = null,
|
||||||
|
val body: Any? = null,
|
||||||
|
override val statusCode: Int = -1,
|
||||||
|
override val headers: Map<String, List<String>>
|
||||||
|
): ApiResponse<T>(ResponseType.ServerError)
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -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()
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
@file:Suppress("unused")
|
||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
import java.lang.RuntimeException
|
||||||
|
|
||||||
|
open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val serialVersionUID: Long = 123L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val serialVersionUID: Long = 456L
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<String,String> because rfc2616 defines
|
||||||
|
* multi-valued headers as csv-only.
|
||||||
|
*/
|
||||||
|
data class PartConfig<T>(
|
||||||
|
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||||
|
val body: T? = null
|
||||||
|
)
|
@ -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<String,String> because rfc2616 defines
|
||||||
|
* multi-valued headers as csv-only.
|
||||||
|
*/
|
||||||
|
data class RequestConfig<T>(
|
||||||
|
val method: RequestMethod,
|
||||||
|
val path: String,
|
||||||
|
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||||
|
val query: MutableMap<String, List<String>> = mutableMapOf(),
|
||||||
|
val body: T? = null
|
||||||
|
)
|
@ -0,0 +1,8 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides enumerated HTTP verbs
|
||||||
|
*/
|
||||||
|
enum class RequestMethod {
|
||||||
|
GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an extension to evaluation whether the response is a 4xx code
|
||||||
|
*/
|
||||||
|
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
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* 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 i0
|
||||||
|
* @param n0
|
||||||
|
* @param i1
|
||||||
|
* @param n1
|
||||||
|
*/
|
||||||
|
|
||||||
|
data class Apa (
|
||||||
|
|
||||||
|
@Json(name = "i0")
|
||||||
|
val i0: kotlin.Int,
|
||||||
|
|
||||||
|
@Json(name = "n0")
|
||||||
|
val n0: java.math.BigDecimal,
|
||||||
|
|
||||||
|
@Json(name = "i1")
|
||||||
|
val i1: kotlin.Int? = null,
|
||||||
|
|
||||||
|
@Json(name = "n1")
|
||||||
|
val n1: java.math.BigDecimal? = null
|
||||||
|
|
||||||
|
)
|
||||||
|
|
@ -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
|
@ -0,0 +1,23 @@
|
|||||||
|
README.md
|
||||||
|
build.gradle
|
||||||
|
docs/Apa.md
|
||||||
|
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
|
||||||
|
src/main/kotlin/org/openapitools/client/models/Apa.kt
|
@ -0,0 +1 @@
|
|||||||
|
6.0.0-SNAPSHOT
|
@ -0,0 +1,50 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
<a name="documentation-for-api-endpoints"></a>
|
||||||
|
## Documentation for API Endpoints
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Class | Method | HTTP request | Description
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
*DefaultApi* | [**test**](docs/DefaultApi.md#test) | **POST** test | Tests default values
|
||||||
|
|
||||||
|
|
||||||
|
<a name="documentation-for-models"></a>
|
||||||
|
## Documentation for Models
|
||||||
|
|
||||||
|
- [org.openapitools.client.models.Apa](docs/Apa.md)
|
||||||
|
|
||||||
|
|
||||||
|
<a name="documentation-for-authorization"></a>
|
||||||
|
## Documentation for Authorization
|
||||||
|
|
||||||
|
All endpoints do not require authorization.
|
@ -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"
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
# Apa
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**i0** | **kotlin.Int** | |
|
||||||
|
**n0** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | |
|
||||||
|
**i1** | **kotlin.Int** | | [optional]
|
||||||
|
**n1** | [**java.math.BigDecimal**](java.math.BigDecimal.md) | | [optional]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,101 @@
|
|||||||
|
# DefaultApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Method | HTTP request | Description
|
||||||
|
------------- | ------------- | -------------
|
||||||
|
[**test**](DefaultApi.md#test) | **POST** test | Tests default values
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Tests default values
|
||||||
|
|
||||||
|
Tests default values of different parameters
|
||||||
|
|
||||||
|
### 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 pi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val pi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val pn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val pn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qi2 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qi3 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val qn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qn2 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val qn3 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hi2 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hi3 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val hn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hn2 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val hn3 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fi0 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fi1 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fi2 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fi3 : kotlin.Int = 56 // kotlin.Int |
|
||||||
|
val fn0 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fn1 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fn2 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
val fn3 : java.math.BigDecimal = 8.14 // java.math.BigDecimal |
|
||||||
|
|
||||||
|
webService.test(pi0, pi1, pn0, pn1, qi0, qi1, qi2, qi3, qn0, qn1, qn2, qn3, hi0, hi1, hi2, hi3, hn0, hn1, hn2, hn3, fi0, fi1, fi2, fi3, fn0, fn1, fn2, fn3)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------- | ------------- | ------------- | -------------
|
||||||
|
**pi0** | **kotlin.Int**| | [default to 10]
|
||||||
|
**pi1** | **kotlin.Int**| |
|
||||||
|
**pn0** | **java.math.BigDecimal**| | [default to 10.0]
|
||||||
|
**pn1** | **java.math.BigDecimal**| |
|
||||||
|
**qi0** | **kotlin.Int**| | [optional] [default to 10]
|
||||||
|
**qi1** | **kotlin.Int**| | [default to 71]
|
||||||
|
**qi2** | **kotlin.Int**| | [optional]
|
||||||
|
**qi3** | **kotlin.Int**| |
|
||||||
|
**qn0** | **java.math.BigDecimal**| | [optional] [default to 10.0]
|
||||||
|
**qn1** | **java.math.BigDecimal**| | [default to 71.0]
|
||||||
|
**qn2** | **java.math.BigDecimal**| | [optional]
|
||||||
|
**qn3** | **java.math.BigDecimal**| |
|
||||||
|
**hi0** | **kotlin.Int**| | [optional] [default to 10]
|
||||||
|
**hi1** | **kotlin.Int**| | [default to 71]
|
||||||
|
**hi2** | **kotlin.Int**| | [optional]
|
||||||
|
**hi3** | **kotlin.Int**| |
|
||||||
|
**hn0** | **java.math.BigDecimal**| | [optional] [default to 10.0]
|
||||||
|
**hn1** | **java.math.BigDecimal**| | [default to 71.0]
|
||||||
|
**hn2** | **java.math.BigDecimal**| | [optional]
|
||||||
|
**hn3** | **java.math.BigDecimal**| |
|
||||||
|
**fi0** | **kotlin.Int**| | [optional] [default to 10]
|
||||||
|
**fi1** | **kotlin.Int**| | [default to 71]
|
||||||
|
**fi2** | **kotlin.Int**| | [optional]
|
||||||
|
**fi3** | **kotlin.Int**| |
|
||||||
|
**fn0** | **java.math.BigDecimal**| | [optional] [default to 10.0]
|
||||||
|
**fn1** | **java.math.BigDecimal**| | [default to 71.0]
|
||||||
|
**fn2** | **java.math.BigDecimal**| | [optional]
|
||||||
|
**fn3** | **java.math.BigDecimal**| |
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
null (empty response body)
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: multipart/form-data
|
||||||
|
- **Accept**: Not defined
|
||||||
|
|
BIN
samples/client/petstore/kotlin-default-values-jvm-retrofit2/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
samples/client/petstore/kotlin-default-values-jvm-retrofit2/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
@ -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
|
185
samples/client/petstore/kotlin-default-values-jvm-retrofit2/gradlew
vendored
Normal file
185
samples/client/petstore/kotlin-default-values-jvm-retrofit2/gradlew
vendored
Normal file
@ -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" "$@"
|
89
samples/client/petstore/kotlin-default-values-jvm-retrofit2/gradlew.bat
vendored
Normal file
89
samples/client/petstore/kotlin-default-values-jvm-retrofit2/gradlew.bat
vendored
Normal file
@ -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
|
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
rootProject.name = 'kotlin-default-values-jvm-retrofit2'
|
@ -0,0 +1,50 @@
|
|||||||
|
package org.openapitools.client.apis
|
||||||
|
|
||||||
|
import org.openapitools.client.infrastructure.CollectionFormats.*
|
||||||
|
import retrofit2.http.*
|
||||||
|
import retrofit2.Call
|
||||||
|
import okhttp3.RequestBody
|
||||||
|
|
||||||
|
|
||||||
|
interface DefaultApi {
|
||||||
|
/**
|
||||||
|
* Tests default values
|
||||||
|
* Tests default values of different parameters
|
||||||
|
* Responses:
|
||||||
|
* - 200: Success
|
||||||
|
*
|
||||||
|
* @param pi0 (default to 10)
|
||||||
|
* @param pi1
|
||||||
|
* @param pn0 (default to 10.0)
|
||||||
|
* @param pn1
|
||||||
|
* @param qi0 (optional, default to 10)
|
||||||
|
* @param qi1 (default to 71)
|
||||||
|
* @param qi2 (optional)
|
||||||
|
* @param qi3
|
||||||
|
* @param qn0 (optional, default to 10.0)
|
||||||
|
* @param qn1 (default to 71.0)
|
||||||
|
* @param qn2 (optional)
|
||||||
|
* @param qn3
|
||||||
|
* @param hi0 (optional, default to 10)
|
||||||
|
* @param hi1 (default to 71)
|
||||||
|
* @param hi2 (optional)
|
||||||
|
* @param hi3
|
||||||
|
* @param hn0 (optional, default to 10.0)
|
||||||
|
* @param hn1 (default to 71.0)
|
||||||
|
* @param hn2 (optional)
|
||||||
|
* @param hn3
|
||||||
|
* @param fi0 (optional, default to 10)
|
||||||
|
* @param fi1 (default to 71)
|
||||||
|
* @param fi2 (optional)
|
||||||
|
* @param fi3
|
||||||
|
* @param fn0 (optional, default to 10.0)
|
||||||
|
* @param fn1 (default to 71.0)
|
||||||
|
* @param fn2 (optional)
|
||||||
|
* @param fn3
|
||||||
|
* @return [Call]<[Unit]>
|
||||||
|
*/
|
||||||
|
@Multipart
|
||||||
|
@POST("test")
|
||||||
|
fun test(@Path("pi0") pi0: kotlin.Int = 10, @Path("pi1") pi1: kotlin.Int, @Path("pn0") pn0: java.math.BigDecimal = java.math.BigDecimal("10.0"), @Path("pn1") pn1: java.math.BigDecimal, @Query("qi0") qi0: kotlin.Int? = 10, @Query("qi1") qi1: kotlin.Int = 71, @Query("qi2") qi2: kotlin.Int? = null, @Query("qi3") qi3: kotlin.Int, @Query("qn0") qn0: java.math.BigDecimal? = java.math.BigDecimal("10.0"), @Query("qn1") qn1: java.math.BigDecimal = java.math.BigDecimal("71.0"), @Query("qn2") qn2: java.math.BigDecimal? = null, @Query("qn3") qn3: java.math.BigDecimal, @Header("hi0") hi0: kotlin.Int? = 10, @Header("hi1") hi1: kotlin.Int = 71, @Header("hi2") hi2: kotlin.Int? = null, @Header("hi3") hi3: kotlin.Int, @Header("hn0") hn0: java.math.BigDecimal? = java.math.BigDecimal("10.0"), @Header("hn1") hn1: java.math.BigDecimal = java.math.BigDecimal("71.0"), @Header("hn2") hn2: java.math.BigDecimal? = null, @Header("hn3") hn3: java.math.BigDecimal, @Part("fi0") fi0: kotlin.Int? = 10, @Part("fi1") fi1: kotlin.Int = 71, @Part("fi2") fi2: kotlin.Int? = null, @Part("fi3") fi3: kotlin.Int, @Part("fn0") fn0: java.math.BigDecimal? = java.math.BigDecimal("10.0"), @Part("fn1") fn1: java.math.BigDecimal = java.math.BigDecimal("71.0"), @Part("fn2") fn2: java.math.BigDecimal? = null, @Part("fn3") fn3: java.math.BigDecimal): Call<Unit>
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,106 @@
|
|||||||
|
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<String, Interceptor>()
|
||||||
|
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(object : HttpLoggingInterceptor.Logger {
|
||||||
|
override fun log(message: String) {
|
||||||
|
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 <S> createService(serviceClass: Class<S>): S {
|
||||||
|
val usedCallFactory = this.callFactory ?: clientBuilder.build()
|
||||||
|
return retrofitBuilder.callFactory(usedCallFactory).build().create(serviceClass)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun normalizeBaseUrl() {
|
||||||
|
if (!baseUrl.endsWith("/")) {
|
||||||
|
baseUrl += "/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun <T, reified U> Iterable<T>.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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user