Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ defmodule {{moduleName}}.Deserializer do
end
end

defp to_struct(map_or_list, module)
defp to_struct(value, module)
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
Enum.map(list, &to_struct(&1, module))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ defmodule OpenapiPetstore.Deserializer do
end
end

defp to_struct(map_or_list, module)
defp to_struct(value, module)
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
Enum.map(list, &to_struct(&1, module))
Expand Down
23 changes: 23 additions & 0 deletions samples/client/petstore/elixir/test/outer_enum_test.exs
Original file line number Diff line number Diff line change
@@ -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