mirror of
				https://github.com/OpenAPITools/openapi-generator.git
				synced 2025-10-31 00:33:49 +00:00 
			
		
		
		
	
							parent
							
								
									68e7d49456
								
							
						
					
					
						commit
						8998d83f99
					
				| @ -91,9 +91,13 @@ 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)) | ||||||
|   end |   end | ||||||
|  | |||||||
| @ -93,9 +93,13 @@ 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)) | ||||||
|   end |   end | ||||||
|  | |||||||
							
								
								
									
										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