forked from loafle/openapi-generator-original
parent
68e7d49456
commit
8998d83f99
@ -91,8 +91,12 @@ defmodule {{moduleName}}.Deserializer do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp to_struct(map_or_list, module)
|
defp to_struct(value, module)
|
||||||
defp to_struct(nil, _), do: nil
|
defp to_struct(nil, _), do: nil
|
||||||
|
|
||||||
|
defp to_struct(binary, module) when is_binary(binary) and is_atom(module) do
|
||||||
|
module.decode(binary)
|
||||||
|
end
|
||||||
|
|
||||||
defp to_struct(list, module) when is_list(list) and is_atom(module) do
|
defp to_struct(list, module) when is_list(list) and is_atom(module) do
|
||||||
Enum.map(list, &to_struct(&1, module))
|
Enum.map(list, &to_struct(&1, module))
|
||||||
|
@ -93,8 +93,12 @@ defmodule OpenapiPetstore.Deserializer do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp to_struct(map_or_list, module)
|
defp to_struct(value, module)
|
||||||
defp to_struct(nil, _), do: nil
|
defp to_struct(nil, _), do: nil
|
||||||
|
|
||||||
|
defp to_struct(binary, module) when is_binary(binary) and is_atom(module) do
|
||||||
|
module.decode(binary)
|
||||||
|
end
|
||||||
|
|
||||||
defp to_struct(list, module) when is_list(list) and is_atom(module) do
|
defp to_struct(list, module) when is_list(list) and is_atom(module) do
|
||||||
Enum.map(list, &to_struct(&1, module))
|
Enum.map(list, &to_struct(&1, module))
|
||||||
|
23
samples/client/petstore/elixir/test/outer_enum_test.exs
Normal file
23
samples/client/petstore/elixir/test/outer_enum_test.exs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
defmodule OuterEnumTest do
|
||||||
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
|
alias OpenapiPetstore.Deserializer
|
||||||
|
alias OpenapiPetstore.Model.EnumTest
|
||||||
|
|
||||||
|
@valid_json """
|
||||||
|
{
|
||||||
|
"enum_string": "UPPER",
|
||||||
|
"outerEnum": "placed"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
@tag timeout: :infinity
|
||||||
|
test "jason_decode/2 with valid JSON" do
|
||||||
|
assert Deserializer.jason_decode(@valid_json, EnumTest) ==
|
||||||
|
{:ok,
|
||||||
|
%EnumTest{
|
||||||
|
enum_string: "UPPER",
|
||||||
|
outerEnum: "placed"
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user