-
Notifications
You must be signed in to change notification settings - Fork 404
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
Fix boolean json schemas #515
Conversation
Hey @bcherny, this should do the trick to support boolean JSON schemas. Do you have any test cases in mind? I added a couple of cases but I'm open to add / remove more :) |
if (isBoolean(schema)) { | ||
return parseBooleanSchema(schema, keyName, options) | ||
} | ||
|
||
return parseLiteral(schema, keyName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I don't know what to do here. In theory we should omit anything at this point instead of parsing the literal, but I don't want to introduce too many changes in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be a little cleaner to move the parseBooleanSchema
into parseLiteral
, since true
/false
are literals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be a mistake. Parsing true
and false
as schemas is not the same as parsing them as values. Depending on the context, true
and false
are schemas or values.
A simple example would be the true
boolean schema vs a true
enum value. They should not be parsed as the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great -- thanks for the contribution! Couple of minor suggestions. Could you also please add test cases for top-level true
/false
schemas?
ie.
export const input = true
export const input = false
if (isBoolean(schema)) { | ||
return parseBooleanSchema(schema, keyName, options) | ||
} | ||
|
||
return parseLiteral(schema, keyName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be a little cleaner to move the parseBooleanSchema
into parseLiteral
, since true
/false
are literals.
Hey @bcherny, when adding the root boolean schema case, it seems the ref parser can not dereference it, it throws an error instead. I can have a look at it, but seems the parser is expecting an object instead of a boolean value. Would it be ok if I submit a pr in the parser repo? I think some sort of conditional logic to handle boolean schemas would do the trick. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for the contribution!
Published 13.0.0. |
Added
NEVER
schema type.Changed