Skip to content

Support boolean schemas (OpenAPI 3.1) - #216

Merged
geemus merged 11 commits into
ota42y:masterfrom
takayamaki:boolean-schema
Oct 20, 2026
Merged

geemus merged 11 commits into
ota42y:masterfrom
takayamaki:boolean-schema

Conversation

@takayamaki

Copy link
Copy Markdown
Contributor

Part of #215 (item 1).

A boolean schema (true or false in place of a schema object) crashed the loader with NoMethodError.
For example, prefixItems with items: false could not be loaded.

Changes

  • A boolean schema is now loaded as a Schema with no keywords set.
    schema.items and other schema attributes still return a Schema, so code that walks the schema tree keeps working.
  • In validation, true accepts any value, including null.
    false rejects any value with the new FalseSchemaError.
  • The new SpecValidator rule BooleanSchemaIn30 reports a boolean schema in a 3.0 document.
    3.0 allows a boolean only for additionalProperties.

additionalProperties: true / false does not change.
It is still loaded as a plain boolean.

I did not load boolean schemas as plain values, like additionalProperties.
Then schema attributes could return true or false, and code that calls methods on them would break.

A schema of true or false crashed the loader with NoMethodError, because it read keywords from the raw value as a Hash.
A boolean schema is now a Schema with no keywords set.
items: false after prefixItems now rejects an element past the prefix.
The new FalseSchemaError reports the schema that rejected the value.
These already pass with the previous two changes.
A Schema with no keywords rejected null through the nil validator.
3.0 allows a boolean only for additionalProperties.
These already pass, including additionalProperties: false in a 3.0 document.
@takayamaki
takayamaki marked this pull request as ready for review October 19, 2026 18:00

@geemus geemus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm, thanks!

@geemus
geemus merged commit d6433a5 into ota42y:master Oct 20, 2026
14 checks passed
@takayamaki takayamaki mentioned this pull request Oct 20, 2026
1 of 8 tasks
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

Successfully merging this pull request may close these issues.

2 participants