fix equtable, date formatting service and methods without body
This commit is contained in:
parent
b366d51ee0
commit
3640a5477f
|
|
@ -10,8 +10,7 @@ import SwiftDate
|
|||
enum ApiDateFormat: String, LeadKit.DateFormat {
|
||||
|
||||
{% for format in dateFormats -%}
|
||||
{%- set classType = classUtils.classType(format.type) -%}
|
||||
case {{ utils.dateFormatName(format.fieldName, classType) }} = "{{ format.dateFormat }}"
|
||||
case {{ format.name }} = "{{ format.format }}"
|
||||
{% endfor %}
|
||||
var swiftDateFormat: SwiftDate.DateFormat {
|
||||
return SwiftDate.DateFormat.custom(rawValue)
|
||||
|
|
@ -30,4 +29,5 @@ final class ApiDateFormattingService: DateFormattingService, Singleton {
|
|||
private init() {}
|
||||
|
||||
}
|
||||
{{ "\n" }}
|
||||
{%- endif -%}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
{%- set hasParent = parent is not null -%}
|
||||
{%- set classType = classUtils.classType(type) -%}
|
||||
{%- set parentClassType = classUtils.parentClassType(parent, type.parentTypeParameters) -%}
|
||||
{%- set hasGenerics = (type.typeParameters is not empty) %}
|
||||
{%- set hasGenerics = utils.valueTypeHasGenerics(type) != null %}
|
||||
{%- for field in allFieldsOrdered -%}
|
||||
{%- set fieldsHasGenericsOrNonEqutableCollections = default(fieldsHasGenericsOrNonEqutableCollections, false) or (utils.hasGenericsOrNonEqutableCollections(field.type) != null) -%}
|
||||
{%- endfor -%}
|
||||
|
|
@ -13,8 +13,6 @@ import ObjectMapper
|
|||
import SwiftDate
|
||||
import LeadKit
|
||||
|
||||
{%- include 'blocks/class/date-transformers.twig' with { fields: fields, classType: classType } %}
|
||||
|
||||
/// {{ description }}
|
||||
{% if (not hasChilds) -%}final {% endif %}class {{ classType }}: {{ parentClassType }} {
|
||||
|
||||
|
|
@ -48,13 +46,13 @@ import LeadKit
|
|||
{%- endif %}
|
||||
}
|
||||
|
||||
{% if not fieldsHasGenericsOrNonEqutableCollections -%}
|
||||
{% if (not hasGenerics) and (not fieldsHasGenericsOrNonEqutableCollections) -%}
|
||||
func isEqual(to other: {{ classType }}?) -> Bool {
|
||||
guard let other = other else {
|
||||
return false
|
||||
}
|
||||
|
||||
return{%- if hasParent %} super.isEqual(to: other) &&{%- endif %} {% include 'blocks/class/fields-equal.twig' with { fields: fields } %}
|
||||
return{%- if hasParent %} super.isEqual(to: other){%- endif %}{%- if (fields is not empty) and hasParent %} &&{% endif %} {% include 'blocks/class/fields-equal.twig' with { fields: fields } %}
|
||||
}
|
||||
{%- endif %}
|
||||
|
||||
|
|
@ -68,9 +66,10 @@ extension {{ type.baseTypeName }}: Equatable {
|
|||
}
|
||||
|
||||
}
|
||||
{%- endif %}
|
||||
{{ "\n" }}
|
||||
{%- endif -%}
|
||||
|
||||
{% if not hasGenerics -%}
|
||||
{%- if not hasGenerics -%}
|
||||
extension {{ type.baseTypeName }} {
|
||||
|
||||
static let new{{ type.baseTypeName }} = {{ type.baseTypeName }}({%- include 'blocks/class/fields-initialization-default-values.twig' with { fields: allFieldsOrdered } -%})
|
||||
|
|
@ -80,4 +79,5 @@ extension {{ type.baseTypeName }} {
|
|||
}
|
||||
|
||||
}
|
||||
{%- endif %}
|
||||
{{ "\n" }}
|
||||
{%- endif -%}
|
||||
|
|
@ -12,3 +12,4 @@ enum {{ name }}: {{ enumutils.enumType(valuesTypes) }}, RawRepresentable {
|
|||
{% include 'blocks/enum/cases.twig' with { values: values } %}
|
||||
|
||||
}
|
||||
{{ "\n" }}
|
||||
|
|
@ -9,3 +9,4 @@ extension NetworkService {
|
|||
|
||||
{% endfor %}
|
||||
}
|
||||
{{ "\n" }}
|
||||
|
|
@ -12,3 +12,4 @@ class {{ serviceName }}: NetworkService, ConfigurableNetworkService {
|
|||
}
|
||||
|
||||
}
|
||||
{{ "\n" }}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
{%- import '../../macroses/common.utils.twig' as utils -%}
|
||||
|
||||
{%- set hasDateFields = false -%}
|
||||
|
||||
{%- for field in fields -%}
|
||||
{%- if field.type.type.baseTypeName == "DateTime" -%}
|
||||
{%- set hasDateFields = true -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{%- if hasDateFields -%}
|
||||
{{ "\n" }}
|
||||
// MARK: - Date transformers
|
||||
{{ "\n" }}
|
||||
|
||||
{%- for field in fields -%}
|
||||
{% if field.type.type.baseTypeName == "DateTime" -%}
|
||||
private let {{ utils.dateTransformName(field.name, classType) }} = ApiDateFormattingService.mappingTransform(with: .{{ utils.dateFormatName(field.name, classType) }})
|
||||
{% endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
|
|
@ -1,16 +1,23 @@
|
|||
{%- import '../../macroses/common.utils.twig' as utils -%}
|
||||
|
||||
{%- set bodyParamName = utils.decapitalize(method.bodyType.type.typeName) -%}
|
||||
{%- 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 methodType = default(method.type, "POST") | lower -%}
|
||||
{%- set funcName = utils.decapitalize(method.name) -%}
|
||||
|
||||
/// {{ method.description }}
|
||||
func {{ funcName }}({{ bodyParamName }}: {{ method.bodyType.type.typeName }},
|
||||
func {{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyTypeName }},{{ "\n " }}{%- endif -%}
|
||||
encoding: ParameterEncoding = URLEncoding.default,
|
||||
headers: HTTPHeaders? = nil) -> Single<{{ method.responseType.type.typeName }}> {
|
||||
|
||||
let parameters = ApiRequestParameters(url: "{{ method.url }}",
|
||||
method: .post,
|
||||
parameters: {{ bodyParamName }}.toJSON(),
|
||||
method: .{{ methodType }},
|
||||
parameters: {% if hasBody -%}{{ bodyParamName }}.toJSON(){%- else -%}nil{%- endif -%},
|
||||
encoding: encoding,
|
||||
headers: headers)
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
{%- import _self as self -%}
|
||||
|
||||
{%- if field.type.type.baseTypeName == "DateTime" -%}
|
||||
map.value("{{ field.jsonName }}", using: {{ self.dateTransformName(field.name, className) -}})
|
||||
map.value("{{ field.jsonName }}", using: {{ self.mappingTransformForField(field) -}})
|
||||
{%- elseif field.type.type.baseTypeName == "Decimal" -%}
|
||||
map.value("{{ field.jsonName }}", using: NSDecimalNumberTransform())
|
||||
{%- else -%}
|
||||
|
|
@ -52,23 +52,15 @@
|
|||
{%- import _self as self -%}
|
||||
|
||||
{%- if field.type.type.baseTypeName == "DateTime" -%}
|
||||
(map["{{ field.jsonName }}"], {{ self.dateTransformName(field.name, className) -}})
|
||||
(map["{{ field.jsonName }}"], {{ self.mappingTransformForField(field) -}})
|
||||
{%- else -%}
|
||||
map["{{ field.jsonName }}"]
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro dateTransformName(fieldName, className) %}
|
||||
{%- import _self as self -%}
|
||||
|
||||
{{ self.decapitalize(className) }}{{ self.capitalize(fieldName) -}}Transform
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro dateFormatName(fieldName, className) %}
|
||||
{%- import _self as self -%}
|
||||
|
||||
{{ self.decapitalize(className) }}{{ self.capitalize(fieldName) -}}Format
|
||||
{%- endmacro %}
|
||||
{% macro mappingTransformForField(field) %}
|
||||
ApiDateFormattingService.mappingTransform(with: .{{ dateFormatToName(field.type.dateFormat) }})
|
||||
{% endmacro %}
|
||||
|
||||
{% macro enumValueName(value) %}
|
||||
{%- import _self as self -%}
|
||||
|
|
@ -108,10 +100,22 @@
|
|||
{%- endif -%}
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro valueTypeHasGenerics(valueType) %}
|
||||
{%- if valueType.typeParameters is not empty -%}
|
||||
{{ true }}
|
||||
{%- elseif (valueType.parent is not null) -%}
|
||||
{%- import _self as self -%}
|
||||
|
||||
self.valueTypeHasGenerics(valueType.parent)
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro hasGenericsOrNonEqutableCollections(type) %}
|
||||
{%- set valueType = type.type -%}
|
||||
|
||||
{%- if (valueType.typeParameters is not empty) -%}
|
||||
{%- import _self as self -%}
|
||||
|
||||
{%- if self.valueTypeHasGenerics(valueType) != null -%}
|
||||
{{ true }}
|
||||
{%- elseif valueType.baseTypeName == "Array" -%}
|
||||
{%- if valueType.itemsType.parent is not null -%}
|
||||
|
|
@ -122,8 +126,6 @@
|
|||
{%- elseif valueType.baseTypeName == "Map" -%}
|
||||
{{ true }}
|
||||
{%- elseif type.allFieldsOrdered is not null -%}
|
||||
{%- import _self as self -%}
|
||||
|
||||
{%- for field in type.allFieldsOrdered -%}
|
||||
{{ self.hasGenericsOrNonEqutableCollections(field.type) }}
|
||||
{%- endfor -%}
|
||||
|
|
|
|||
Loading…
Reference in New Issue