diff --git a/lib/open_api_spex/cast.ex b/lib/open_api_spex/cast.ex index f8a97a54..7d24e524 100644 --- a/lib/open_api_spex/cast.ex +++ b/lib/open_api_spex/cast.ex @@ -170,6 +170,13 @@ defmodule OpenApiSpex.Cast do def cast(%__MODULE__{schema: %{type: :array}} = ctx), do: Array.cast(ctx) + # Explicit nil types are considered as wildcards, as in + # properties + # value: {} + # See https://json-schema.org/understanding-json-schema/basics.html#id1 + def cast(%__MODULE__{schema: %{type: nil}, value: value} = _ctx), + do: {:ok, value} + def cast(%__MODULE__{schema: %{type: _other}} = ctx), do: error(ctx, {:invalid_schema_type}) diff --git a/test/cast_test.exs b/test/cast_test.exs index 0fcc1075..82542d35 100644 --- a/test/cast_test.exs +++ b/test/cast_test.exs @@ -12,9 +12,7 @@ defmodule OpenApiSpec.CastTest do assert error.reason == :invalid_schema_type assert error.type == :nope - assert {:error, [error]} = cast(value: "string", schema: %Schema{type: nil}) - assert error.reason == :invalid_schema_type - assert error.type == nil + assert {:ok, "string"} = cast(value: "string", schema: %Schema{type: nil}) end # Note: full tests for primitives are covered in Cast.PrimitiveTest