From b433a22874c32e9eafc3a1c48eee714d41148133 Mon Sep 17 00:00:00 2001 From: Angelika Tyborska Date: Thu, 4 Jan 2024 12:51:06 +0100 Subject: [PATCH 1/3] Add failing test --- test/cast/all_of_test.exs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/cast/all_of_test.exs b/test/cast/all_of_test.exs index a491dc25..93487faa 100644 --- a/test/cast/all_of_test.exs +++ b/test/cast/all_of_test.exs @@ -355,6 +355,8 @@ 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, %OpenApiSpex.CastAllOfTest.CatSchema{fur: true, meow: true}} = + cast(value: value, schema: CatSchema.schema()) end end From e54b55f3681bd3132a51ac1517f37e8e8d976a82 Mon Sep 17 00:00:00 2001 From: Angelika Tyborska Date: Thu, 4 Jan 2024 12:51:20 +0100 Subject: [PATCH 2/3] Cast result of AllOf cast into a struct --- lib/open_api_spex/cast/all_of.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From dc41bf7e15e6c9c4ae5bbacedb0277a016729f23 Mon Sep 17 00:00:00 2001 From: Angelika Tyborska Date: Tue, 16 Jan 2024 19:27:35 +0100 Subject: [PATCH 3/3] Shorter module name --- test/cast/all_of_test.exs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/cast/all_of_test.exs b/test/cast/all_of_test.exs index 93487faa..9f2fbabe 100644 --- a/test/cast/all_of_test.exs +++ b/test/cast/all_of_test.exs @@ -356,7 +356,6 @@ defmodule OpenApiSpex.CastAllOfTest do test "with schema having x-type" do value = %{fur: true, meow: true} - assert {:ok, %OpenApiSpex.CastAllOfTest.CatSchema{fur: true, meow: true}} = - cast(value: value, schema: CatSchema.schema()) + assert {:ok, %CatSchema{fur: true, meow: true}} = cast(value: value, schema: CatSchema.schema()) end end