All Downloads are FREE. Search and download functionalities are using the official Maven repository.

handlebars.kotlin-client.api.mustache Maven / Gradle / Ivy

There is a newer version: 1.0.54
Show newest version
{{>licenseInfo}}
package {{apiPackage}}

{{#imports}}import {{import}}
{{/imports}}

import {{packageName}}.infrastructure.*
{{#threetenbp}}
import org.threeten.bp.LocalDateTime
{{/threetenbp}}

{{#operations}}
class {{classname}}(basePath: kotlin.String = "{{{basePath}}}") : ApiClient(basePath) {

    {{#operation}}
    {{#contents}}
    /**
     * {{summary}}
     * {{notes}}
    {{#parameters}} * @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
    {{/parameters}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
     */{{#returnType}}
    @Suppress("UNCHECKED_CAST"){{/returnType}}
    fun {{operationId}}({{#parameters}}{{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}): {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}} {
        {{#or hasFormParams hasBodyParam}}
        val localVariableBody: kotlin.Any? = {{^isForm}}{{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}{{/isForm}}{{#isForm}}{{#hasFormParams}}mapOf({{#formParams}}"{{{baseName}}}" to "${{paramName}}"{{#hasMore}}, {{/hasMore}}{{/formParams}}){{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/isForm}}
        {{/or}}
        {{#hasQueryParams}}val localVariableQuery: MultiValueMap = mapOf({{#queryParams}}"{{baseName}}" to {{#isContainer}}toMultiValue({{paramName}}{{^required}}!!{{/required}}.toList(), "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf("${{paramName}}"){{/isContainer}}{{#hasMore}}, {{/hasMore}}{{/queryParams}}){{/hasQueryParams}}
        {{#or hasFormParams hasHeaderParams}}
        val localVariableHeaders: kotlin.collections.Map = mapOf({{#hasFormParams}}"Content-Type" to "multipart/form-data"{{/hasFormParams}}{{^hasHeaderParams}}){{/hasHeaderParams}}{{#hasHeaderParams}}{{#hasFormParams}}, {{/hasFormParams}}{{#headerParams}}"{{baseName}}" to {{#isContainer}}{{paramName}}.joinToString(separator = collectionDelimiter("{{collectionFormat}}"){{/isContainer}}{{^isContainer}}{{paramName}}{{^required}}.toString(){{/required}}{{/isContainer}}{{#hasMore}}, {{/hasMore}}{{/headerParams}}){{/hasHeaderParams}}
        {{/or}}
        val localVariableConfig = RequestConfig(
                RequestMethod.{{httpMethod}},
                "{{path}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", "${{paramName}}"){{/pathParams}}{{#hasQueryParams}}, query = localVariableQuery{{/hasQueryParams}}{{#or hasFormParams hasHeaderParams}}, headers = localVariableHeaders{{/or}}
        )
        val response = request<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Any?{{/returnType}}>(
                localVariableConfig{{#or hasFormParams hasBodyParam}}, localVariableBody{{/or}}
        )

        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")
        }
    }
    {{/contents}}
    {{/operation}}
}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy