api-generator-templates/Swift/blocks/method/method-func.twig

18 lines
908 B
Twig

{%- import '../../macroses/common.utils.twig' as utils -%}
{%- set bodyParamName = utils.decapitalize(method.bodyType.type.typeName) -%}
{%- set funcName = utils.decapitalize(method.name) -%}
/// {{ method.description }}
func {{ funcName }}({{ bodyParamName }}: {{ method.bodyType.type.typeName }},
encoding: ParameterEncoding = URLEncoding.default,
headers: HTTPHeaders? = nil) -> Single<{{ method.responseType.type.typeName }}> {
let parameters = ApiRequestParameters(url: "{{ method.url }}",
method: .post,
parameters: {{ bodyParamName }}.toJSON(),
encoding: encoding,
headers: headers)
return rxRequest(with: parameters).map { $0.model }.asSingle()
}