File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
modules/openapi-generator/src/main/resources/elixir
samples/client/petstore/elixir Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -91,8 +91,12 @@ defmodule {{moduleName}}.Deserializer do
9191 end
9292 end
9393
94- defp to_struct(map_or_list , module)
94+ defp to_struct(value , module)
9595 defp to_struct(nil, _), do: nil
96+
97+ defp to_struct(binary, module) when is_binary(binary) and is_atom(module) do
98+ module.decode(binary)
99+ end
96100
97101 defp to_struct(list, module) when is_list(list) and is_atom(module) do
98102 Enum.map(list, &to_struct(&1, module))
Original file line number Diff line number Diff line change @@ -93,8 +93,12 @@ defmodule OpenapiPetstore.Deserializer do
9393 end
9494 end
9595
96- defp to_struct ( map_or_list , module )
96+ defp to_struct ( value , module )
9797 defp to_struct ( nil , _ ) , do: nil
98+
99+ defp to_struct ( binary , module ) when is_binary ( binary ) and is_atom ( module ) do
100+ module . decode ( binary )
101+ end
98102
99103 defp to_struct ( list , module ) when is_list ( list ) and is_atom ( module ) do
100104 Enum . map ( list , & to_struct ( & 1 , module ) )
Original file line number Diff line number Diff line change 1+ defmodule OuterEnumTest do
2+ use ExUnit.Case , async: true
3+
4+ alias OpenapiPetstore.Deserializer
5+ alias OpenapiPetstore.Model.EnumTest
6+
7+ @ valid_json """
8+ {
9+ "enum_string": "UPPER",
10+ "outerEnum": "placed"
11+ }
12+ """
13+
14+ @ tag timeout: :infinity
15+ test "jason_decode/2 with valid JSON" do
16+ assert Deserializer . jason_decode ( @ valid_json , EnumTest ) ==
17+ { :ok ,
18+ % EnumTest {
19+ enum_string: "UPPER" ,
20+ outerEnum: "placed"
21+ } }
22+ end
23+ end
You can’t perform that action at this time.
0 commit comments