forked from loafle/openapi-generator-original
* [kotlin] support collectionFormat:multi Adds "multi" support to collections. Also changes generic lists (List<T>) to arrays. Generic lists and nested lists can be problematic and require customized json factories. The previous implement appeared to work because the results in the test were LinkedHashMap with count greather than 0. The functional test has been updated to force serialization and verify the results. * [kotlin] Regenerate sample * [kotlin] Update model test for Array changes
47 lines
3.0 KiB
Plaintext
47 lines
3.0 KiB
Plaintext
{{>licenseInfo}}
|
|
package {{apiPackage}}
|
|
|
|
{{#imports}}import {{import}}
|
|
{{/imports}}
|
|
|
|
import {{packageName}}.infrastructure.*
|
|
|
|
{{#operations}}
|
|
class {{classname}}(basePath: kotlin.String = "{{{basePath}}}") : ApiClient(basePath) {
|
|
|
|
{{#operation}}
|
|
/**
|
|
* {{summary}}
|
|
* {{notes}}
|
|
{{#allParams}}* @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
|
|
{{/allParams}}* @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
|
*/{{#returnType}}
|
|
@Suppress("UNCHECKED_CAST"){{/returnType}}
|
|
fun {{operationId}}({{#allParams}}{{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}} {
|
|
val localVariableBody: kotlin.Any? = {{#hasBodyParam}}{{#bodyParams}}{{paramName}}{{/bodyParams}}{{/hasBodyParam}}{{^hasBodyParam}}{{^hasFormParams}}null{{/hasFormParams}}{{#hasFormParams}}mapOf({{#formParams}}"{{{baseName}}}" to "${{paramName}}"{{#hasMore}}, {{/hasMore}}{{/formParams}}){{/hasFormParams}}{{/hasBodyParam}}
|
|
val localVariableQuery: MultiValueMap = {{^hasQueryParams}}mapOf(){{/hasQueryParams}}{{#hasQueryParams}}mapOf({{#queryParams}}"{{paramName}}" to {{#isContainer}}toMultiValue({{paramName}}.toList(), "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf("${{paramName}}"){{/isContainer}}{{#hasMore}}, {{/hasMore}}{{/queryParams}}){{/hasQueryParams}}
|
|
val localVariableHeaders: kotlin.collections.Map<kotlin.String,kotlin.String> = {{^headerParams}}mapOf({{#hasFormParams}}"Content-Type" to "multipart/form-data"{{/hasFormParams}}){{/headerParams}}{{#headerParams}}mapOf("{{paramName}}" to {{#isContainer}}{{paramName}}.joinToString(separator = collectionDelimiter("{{collectionFormat}}")){{/isContainer}}{{^isContainer}}{{paramName}}{{/isContainer}}){{/headerParams}}
|
|
val localVariableConfig = RequestConfig(
|
|
RequestMethod.{{httpMethod}},
|
|
"{{path}}"{{#pathParams}}.replace("{"+"{{baseName}}"+"}", "${{paramName}}"){{/pathParams}},
|
|
query = localVariableQuery,
|
|
headers = localVariableHeaders
|
|
)
|
|
val response = request<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Any?{{/returnType}}>(
|
|
localVariableConfig,
|
|
localVariableBody
|
|
)
|
|
|
|
return when (response.responseType) {
|
|
ResponseType.Success -> {{#returnType}}(response as Success<*>).data as {{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}
|
|
ResponseType.Informational -> TODO()
|
|
ResponseType.Redirection -> TODO()
|
|
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
|
|
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
|
|
else -> throw kotlin.IllegalStateException("Undefined ResponseType.")
|
|
}
|
|
}
|
|
|
|
{{/operation}}
|
|
}
|
|
{{/operations}} |