Skip to content

Commit

Permalink
Fix dialyzer; only support custom fmt validator as root option
Browse files Browse the repository at this point in the history
  • Loading branch information
arjan committed Nov 10, 2023
1 parent 72184a0 commit bf8e4dd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ The custom function can also be an anonymous function:
ExJsonSchema.Schema.resolve(%{"format" => "custom"}, custom_format_validator: fn format, data -> true end)
```

> Note that the anonymous function version of the custom validator is only available in the option to Schema.resolve/2 and not as Application config, as using anonymous functions as configuration is not allowed.
[format-spec]: https://json-schema.org/understanding-json-schema/reference/string.html#format

## License
Expand Down
2 changes: 1 addition & 1 deletion lib/ex_json_schema/schema/root.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ defmodule ExJsonSchema.Schema.Root do
location: :root | String.t(),
definitions: %{String.t() => ExJsonSchema.Schema.resolved()},
version: non_neg_integer | nil,
custom_format_validator: {module(), atom()} | nil
custom_format_validator: {module(), atom()} | (String.t(), any() -> boolean | {:error, any()}) | nil
}
end
1 change: 0 additions & 1 deletion lib/ex_json_schema/validator/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ defmodule ExJsonSchema.Validator.Format do
defp do_validate(%Root{custom_format_validator: nil}, format, data) do
case Application.fetch_env(:ex_json_schema, :custom_format_validator) do
:error -> []
{:ok, validator} when is_function(validator, 2) -> validate_with_custom_validator(validator, format, data)
{:ok, validator = {_mod, _fun}} -> validate_with_custom_validator(validator, format, data)
end
end
Expand Down

0 comments on commit bf8e4dd

Please sign in to comment.