-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
Description
If I have
defmodule Status do
use JSV.Schema
def json_schema, do: string_enum_to_atom([:pending, :processing, :completed, :failed])
end
defschema(Cart, "My cart",
status: Status,
)shouldn't these both work:
JSV.validate(%{ "status" => :pending }, Status, []) # => {:error ... }
JSV.validate(%{ "status" => "pending" }, Status, []) # => {:ok, ...}Also
defschema(Test, "datetimes",
inserted_at: datetime(description: "Creation timestamp"),
updated_at: datetime(description: "Last update timestamp")
)
JSV.validate(%{ "inserted_at" => ~U[2026-01-07 18:27:13.988187Z] }, Status, []) # => {:error ... }
JSV.validate(%{ "inserted_at" => "2026-01-07 18:27:13.988187Z" }, Status, []) # => {:ok ... }I similarly to the atom example, I expect a date struct to be ok validate if the schema is datetime.
Is validate not the right thing for doing what I am trying to do? is there a better method? I feel I am trying to achieve something with this that was never intended, let me know and I can close this