Merge pull request #37 from TouchInstinct/fix/swift_optional_date_encoding

fix swift optional date encoding
This commit is contained in:
Ivan Smolin 2018-08-24 14:08:15 +03:00 committed by GitHub
commit 53ddf87777
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -32,7 +32,7 @@
{%- import _self as self -%}
{%- if field.type.type.baseTypeName == "DateTime" -%}
ApiDateFormattingService.string(from: {{ self.formatNullableOrOptional(field.name, field.nullable, field.optional) -}}, format: .{{ dateFormatToName(field.type.dateFormat) }})
ApiDateFormattingService.string(from: {{ field.name -}}, format: .{{ dateFormatToName(field.type.dateFormat) }})
{%- elseif field.type.type.baseTypeName == "Decimal" -%}
{{ self.formatNullableOrOptional(field.name, field.nullable, field.optional) -}}
.decimalValue
@ -55,8 +55,8 @@
{%- if field.optional -%}
try container.encodeIfPresent({{ self.formatEncodingValue(field) }}, forKey: .{{ field.name }})
{%- elseif field.nullable -%}
if let value = {{ self.formatEncodingValue(field) }} {
try container.encode(value, forKey: .{{ field.name }})
if let {{ field.name }} = {{ field.name }} {
try container.encode({{ self.formatEncodingValue(field) }}, forKey: .{{ field.name }})
} else {
try container.encodeNil(forKey: .{{ field.name }})
}