Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[change] allow empty schemas to be validated as wildcards #419

Merged
merged 2 commits into from Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/open_api_spex/cast.ex
Expand Up @@ -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 #418
zoten marked this conversation as resolved.
Show resolved Hide resolved
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})

Expand Down
4 changes: 1 addition & 3 deletions test/cast_test.exs
Expand Up @@ -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
Expand Down