forked from loafle/openapi-generator-original
Check date value before calling to_iso8601 (#7769)
* Check date value before calling to_iso8601 When deserializing a date value the value has to be a string when calling to_iso8601. Otherwise it fails with a match error due to a is_binary() guard. * Fix: to_iso returns tuple with three values.
This commit is contained in:
parent
9d85c82cdd
commit
f9b2839a30
@ -21,11 +21,15 @@ defmodule {{moduleName}}.Deserializer do
|
|||||||
|> Map.update!(field, &(Map.new(&1, fn {key, val} -> {key, Poison.Decode.decode(val, Keyword.merge(options, [as: struct(mod)]))} end)))
|
|> Map.update!(field, &(Map.new(&1, fn {key, val} -> {key, Poison.Decode.decode(val, Keyword.merge(options, [as: struct(mod)]))} end)))
|
||||||
end
|
end
|
||||||
def deserialize(model, field, :date, _, _options) do
|
def deserialize(model, field, :date, _, _options) do
|
||||||
case DateTime.from_iso8601(Map.get(model, field)) do
|
value = Map.get(model, field)
|
||||||
{:ok, datetime} ->
|
case is_binary(value) do
|
||||||
Map.put(model, field, datetime)
|
true -> case DateTime.from_iso8601(value) do
|
||||||
_ ->
|
{:ok, datetime, _offset} ->
|
||||||
model
|
Map.put(model, field, datetime)
|
||||||
|
_ ->
|
||||||
|
model
|
||||||
|
end
|
||||||
|
false -> model
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user