fix(schema): apply additive JSON Schema semantics to $ref sibling getters#2921
Open
aqeelat wants to merge 2 commits into
Open
fix(schema): apply additive JSON Schema semantics to $ref sibling getters#2921aqeelat wants to merge 2 commits into
aqeelat wants to merge 2 commits into
Conversation
OpenApiSchemaReference previously used reference-first fallback (Reference.X ?? Target?.X) for all keyword getters. Per JSON Schema 2020-12, assertion keywords alongside are additive, not overrides. This change revises the getter policy into three tiers: Losslessly combinable scalars compute effective values: - MinLength/MinItems/MinProperties: Math.Max(target, sibling) - MaxLength/MaxItems/MaxProperties: Math.Min(target, sibling) - ReadOnly/WriteOnly: true if either source is true - AdditionalPropertiesAllowed/UnevaluatedProperties: false if either is false Non-lossless keywords remain reference-first convenience accessors: - Type, Format, Properties, Items, Required, OneOf/AnyOf/Not, If/Then/Else, etc. - Maximum/Minimum/ExclusiveMaximum/ExclusiveMinimum (raw JSON number strings, not parsed to avoid precision loss) - Contains/MinContains/MaxContains (kept aligned as a group) Annotation keywords remain reference-first (unchanged): - Description, Title, Default, Deprecated, Examples, Extensions, ContentEncoding, etc. Serialization is unchanged: siblings still round-trip on JsonSchemaReference. Fixes microsoft#2919
|
I'm not entirely sure the |
…erence-first Per feedback from @handrews on microsoft#2921: additionalProperties and unevaluatedProperties are location-sensitive applicators whose behavior depends on their exact schema location and adjacent keywords. They cannot be safely collapsed into a single effective boolean. Revert both from AND logic back to reference-first convenience accessors, matching the non-lossless keyword bucket.
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.
Summary
OpenApiSchemaReferencepreviously used reference-first fallback (Reference.X ?? Target?.X) for all keyword getters, which made additive assertion keywords look like overrides of the referenced schema.Per JSON Schema 2020-12, assertion keywords alongside
$refare additive — both the sibling constraint and the target constraint apply. A siblingminProperties: 2does not relax a targetminProperties: 5.This change revises the getter policy into three tiers based on feedback from @handrews in #2919.
Changes
Losslessly combinable scalars compute effective values:
MinLength,MinItems,MinPropertiesMath.Max(target, sibling)MaxLength,MaxItems,MaxPropertiesMath.Min(target, sibling)ReadOnly,WriteOnlytrueif either source istrueAdditionalPropertiesAllowed,UnevaluatedPropertiesfalseif either source isfalseNon-lossless keywords remain reference-first convenience accessors:
Type,Format,Properties,Items,Required,OneOf/AnyOf/Not,If/Then/Else, etc.Maximum/Minimum/ExclusiveMaximum/ExclusiveMinimum— raw JSON number strings, not parsed to avoid precision lossContains/MinContains/MaxContains— kept aligned as a groupAnnotation keywords remain reference-first (unchanged):
Description,Title,Default,Deprecated,Examples,Extensions,ContentEncoding, etc.Serialization is unchanged:
$refsiblings still round-trip onJsonSchemaReference.Design rationale
Properties,Items) cannot be collapsed into a single effective value withoutallOfcomposition. Target-preferred was considered but drops sibling constraints; reference-first keeps authored values visible and preserves setter/getter stability.maximum/minimum) are stored as strings to preserve arbitrary JSON number precision. Parsing todecimalfor comparison risks choosing the wrong stricter bound on high-precision values, so these stay reference-first.Required/AllOfmerge attempts were reverted after review — mutable collection wrappers violated standardISet/IListsemantics (mutations disappeared). These stay reference-first.Fixes #2919