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)))
 | 
			
		||||
  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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user