Support const for OpenAPI 3.1 schemas (parse + runtime + ConstIn30 rule) - #200
Merged
Conversation
…R12) - Schema gains a `const` accessor via openapi_attr_values - Rules::ConstIn30 flags the keyword on 3.0 documents - validate_schema short-circuits to a ValidateError when const is present and value != schema.const; uses raw_schema.key? so an intentional const: null is honored
`const` on a 3.0 document warns and raises (JSON Schema 2020-12 keyword with no 3.0 equivalent); the same keyword on a 3.1 document stays clean.
takayamaki
marked this pull request as ready for review
August 11, 2026 07:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuing the OpenAPI 3.1 work from #152.
OpenAPI 3.1 adopts the JSON Schema 2020-12
constkeyword, which pins a value to exactly one constant.3.0 does not recognize it (the closest 3.0 idiom is a single-element
enum).This PR adds parse support, runtime validation, and version-mismatch detection.
Parse layer
constis parsed as a plain value and exposed as an accessor onSchema:Following the permissive-parse strategy agreed in #152,
the parse layer accepts
constregardless of the declared OpenAPI version.Runtime validation
constis checked before type dispatch invalidate_schema,so it applies uniformly across primitives, arrays, and objects:
Detection inspects
raw_schemakey presence,so an intentional
const: nullstill constrains the value to null.SpecValidator rule
ConstIn30reports a violation for each schema in a 3.0 document that usesconst: