diff --git a/Swift/Methods.swift.twig b/Swift/Methods.swift.twig index d6541d1..eceb90f 100644 --- a/Swift/Methods.swift.twig +++ b/Swift/Methods.swift.twig @@ -16,7 +16,7 @@ extension Singleton where Self: {{ protocolName }} { {% for method in methods %} {%- include 'blocks/method/method-func.twig' with { method: method, isStatic: true } %} - + {% endfor %} } {{ "\n" }} diff --git a/Swift/NetworkService.swift.twig b/Swift/NetworkService.swift.twig index 99c660a..bdebb7b 100644 --- a/Swift/NetworkService.swift.twig +++ b/Swift/NetworkService.swift.twig @@ -1,5 +1,3 @@ -{%- import "blocks/method/method-func.twig" as methodUtils -%} - import LeadKit import RxSwift import Alamofire @@ -16,10 +14,8 @@ protocol {{ protocolName }} { requestEncoding: ParameterEncoding?, requestHeaders: HTTPHeaders?) -> ApiRequestParameters - {% for method in methodUtils.methods %} - {{ isStatic ? "static " : "" }}func {{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyTypeName }},{{ "\n " }}{%- endif -%} - requestEncoding: ParameterEncoding? = nil, - requestHeaders: HTTPHeaders? = nil) -> Single<{{ method.responseType.type.typeName }}> + {% for method in methods %} + {%- include 'blocks/method/method-declaration.twig' with { method: method, isStatic: false } %} {% endfor %} } diff --git a/Swift/blocks/method/method-declaration.twig b/Swift/blocks/method/method-declaration.twig new file mode 100644 index 0000000..d963da6 --- /dev/null +++ b/Swift/blocks/method/method-declaration.twig @@ -0,0 +1,12 @@ +{%- import '../../macroses/common.utils.twig' as utils -%} + +{%- if (method.bodyType is not null) -%} + {%- set bodyParamName = utils.decapitalize(method.bodyType.type.typeName) -%} + {%- set bodyTypeName = method.bodyType.type.typeName -%} + + {%- set hasBody = true -%} +{%- endif -%} + +{%- set funcName = utils.decapitalize(method.name) -%} + +{{ isStatic ? "static " : "" }}func {{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyTypeName }},{{ " " }}{%- endif -%}requestEncoding: ParameterEncoding?, requestHeaders: HTTPHeaders?) -> Single<{{ method.responseType.type.typeName }}> diff --git a/Swift/blocks/method/method-func.twig b/Swift/blocks/method/method-func.twig index 018dc50..f7d8c07 100644 --- a/Swift/blocks/method/method-func.twig +++ b/Swift/blocks/method/method-func.twig @@ -26,6 +26,6 @@ requestEncoding: requestEncoding, requestHeaders: requestHeaders) - return apiRequest(with: parameters) + return apiRequest(with: parameters, decoder: JSONDecoder()) {%- endif %} }