You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It works when my data is an integer 1234 or a string "my_id". But it doesn't work when it is an integer inside a string "1234". It triggers this error:
Value does not conform to schema:
Failed to cast value to one of: more than one schemas validate at .../id
I think that the reason is here. In the module Cast.Integer, we convert the value to integer when it is a binary containing an integer. Consequently, the two clauses of my oneOf are valid.
defmodule StrictIntegerValidation do
@moduledoc """
Ensure that we have really an integer, and not an integer inside a string
"""
def cast(ctx) do
if is_integer(ctx.value) do
{:ok, ctx.value}
else
{:error, "Not strictly integer"}
end
end
end
OpenApiSpex.schema(%{
oneOf: [
%Schema{type: :string},
%Schema{type: :integer, "x-validate": StrictIntegerValidation}
]
})
Hi!
I would like to define a field
id
as an integer or a string. Thus I write this schema:It works when my data is an integer
1234
or a string"my_id"
. But it doesn't work when it is an integer inside a string"1234"
. It triggers this error:I think that the reason is here. In the module
Cast.Integer
, we convert the value to integer when it is a binary containing an integer. Consequently, the two clauses of myoneOf
are valid.open_api_spex/lib/open_api_spex/cast/integer.ex
Lines 17 to 22 in 531607c
Is there a workaround or can we remove this function clause?
I tried with
anyOf
instead ofoneOf
but in that case I have this error:Thank you
The text was updated successfully, but these errors were encountered: