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

passing a symbol for "format" silently disables validation #197

Open
Roguelazer opened this issue Nov 7, 2024 · 1 comment
Open

passing a symbol for "format" silently disables validation #197

Roguelazer opened this issue Nov 7, 2024 · 1 comment

Comments

@Roguelazer
Copy link

JSONSchemer.schema({'format' => 'date'}).valid?("foo")
JSONSchemer.schema({'format' => :date}).valid?("foo")

This is very surprising! I feel like fetch_format might want to cast the input to a string. What do you think?

@davishmcclurg
Copy link
Owner

I agree it's annoying. format isn't a special case, though, so changing this would mean supporting symbols for all schema values. I reluctantly added support for symbol schema keys (ie, {format: 'date'} works), but keys are more constrained than values. I'm still open to supporting symbol values, though likely not soon.

In the mean time, if you have schemas that may not be valid, you can use JSONSchemer.valid_schema? to check them:

>> JSONSchemer.valid_schema?({'format' => 'date'})
=> true
>> JSONSchemer.valid_schema?({'format' => :date})
=> false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants