From f9b2839a3076f26db1b8fc61655a26662f2552ee Mon Sep 17 00:00:00 2001 From: garte Date: Mon, 19 Mar 2018 08:15:38 +0100 Subject: [PATCH] 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. --- .../main/resources/elixir/deserializer.ex.mustache | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/elixir/deserializer.ex.mustache b/modules/swagger-codegen/src/main/resources/elixir/deserializer.ex.mustache index 931ba8f7b9c..ada1cf1346d 100644 --- a/modules/swagger-codegen/src/main/resources/elixir/deserializer.ex.mustache +++ b/modules/swagger-codegen/src/main/resources/elixir/deserializer.ex.mustache @@ -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))) end def deserialize(model, field, :date, _, _options) do - case DateTime.from_iso8601(Map.get(model, field)) do - {:ok, datetime} -> - Map.put(model, field, datetime) - _ -> - model + value = Map.get(model, field) + case is_binary(value) do + true -> case DateTime.from_iso8601(value) do + {:ok, datetime, _offset} -> + Map.put(model, field, datetime) + _ -> + model + end + false -> model end end end