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

fix: support for Boolean JSON Schema #63

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion schemas/2.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@
"$ref": "http://json-schema.org/draft-07/schema#"
},
{
"type": "object",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd not remove this line but instead, I'd do the following:

"schema": { // Current line 359
  "oneOf": [
    { "type": "boolean" },
    { "allOf": [ // Current line 360
        ...

Copy link
Member Author

@magicmatatjahu magicmatatjahu Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's one the solution, but when we will remove the type from second schema, then we infer the type from http://json-schema.org/draft-07/schema and it is:

"type": ["object", "boolean"],

https://github.com/json-schema-org/json-schema-spec/blob/draft-07/schema.json#L39

Copy link
Member Author

@magicmatatjahu magicmatatjahu Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that oneOf can only complicate (already complex) our JSON Schema

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Forgot that type can take an array. Go for it then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fore sure not removing the type: object line because that would mean we accept anything and that's not true.

Copy link
Member Author

@magicmatatjahu magicmatatjahu Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the "type": ["object", "boolean"] is inferred from the http://json-schema.org/draft-07/schema allOf combined schema means that for every sub schema input data must be valid, so if I removed the type from the second schema then I have allowed types for first schema object and boolean and for second I have allowed of course everything, but then, as I wrote, the http://json-schema.org/draft-07/schema schema only allows the [object, boolean], so at the end if someone put as input the number type it will be invalid:

  • first schema - invalid
  • second schema - valid

If someone put boolean or object it will be always valid :)

You can test it with this simple schema:

{
  allOf: [
    {
      type: ['object', 'boolean'] 
    },
    {}
  ],
}

in the https://www.jsonschemavalidator.net/

Copy link
Member Author

@magicmatatjahu magicmatatjahu Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for you I will write in the second schema the object, boolean type 😘

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh sorry, I didn't notice. Nevermind, it's fine as it is 👍

"patternProperties": {
"^x-[\\w\\d\\.\\-\\_]+$": {
"$ref": "#/definitions/specificationExtension"
Expand Down