diff --git a/lib/open_api_spex/cast/all_of.ex b/lib/open_api_spex/cast/all_of.ex index 372d55b5..e0f49ced 100644 --- a/lib/open_api_spex/cast/all_of.ex +++ b/lib/open_api_spex/cast/all_of.ex @@ -34,14 +34,14 @@ defmodule OpenApiSpex.Cast.AllOf do cast_all_of(%{ctx | schema: %{schema | allOf: [nested_schema | remaining]}}, result) end - defp cast_all_of(%{schema: %{allOf: []}, errors: []} = ctx, acc) do + defp cast_all_of(%{schema: %{allOf: [], "x-struct": module}, errors: []} = ctx, acc) + when not is_nil(module) do with :ok <- Utils.check_required_fields(ctx, acc) do - {:ok, acc} + {:ok, struct(module, acc)} end end - defp cast_all_of(%{schema: %{allOf: [], errors: [], "x-struct": module}} = ctx, acc) - when not is_nil(module) do + defp cast_all_of(%{schema: %{allOf: []}, errors: []} = ctx, acc) do with :ok <- Utils.check_required_fields(ctx, acc) do {:ok, acc} end diff --git a/test/cast/all_of_test.exs b/test/cast/all_of_test.exs index a491dc25..9f2fbabe 100644 --- a/test/cast/all_of_test.exs +++ b/test/cast/all_of_test.exs @@ -355,6 +355,7 @@ defmodule OpenApiSpex.CastAllOfTest do test "with schema having x-type" do value = %{fur: true, meow: true} - assert {:ok, _} = cast(value: value, schema: CatSchema.schema()) + + assert {:ok, %CatSchema{fur: true, meow: true}} = cast(value: value, schema: CatSchema.schema()) end end