Repository navigation
Conversation
…e allOf and array items Required-property validation only ran on top-level component schemas, so an object defined inline inside an allOf (or anyOf/oneOf) composition, or as the items of an array schema, was never checked. The check now recurses into the sub-schemas of compositions and array items and reports missing required properties under the name of the composing model. Sub-schemas that are pure $ref are skipped: referenced component schemas are already validated on their own, which also avoids duplicate errors when a parser resolves refs inline. A visited set keeps the traversal finite for shared or cyclic schema structures. Rule options semantics are unchanged.
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
The required-property check inside compositions only looked at each
branch's own properties, so valid partial branches were reported as
missing required properties: a parent with properties {id, name} plus
oneOf [{required: [id]}, {required: [name]}], or allOf [$ref: Base,
{required: [id]}], produced 'property id should be present' although
the property is declared elsewhere in the composition.
Required names are now checked against every property name declared
across the composition tree rooted at the checked schema: the schema
itself plus all its allOf/anyOf/oneOf members, transitively, following
$ref members through the component schemas they point to. A required
name present in any branch is known and no longer reported; names
declared nowhere are still reported. Array items keep their own
composition scope, since they describe different instances.
See the review discussion on PR OpenAPITools#809
(OpenAPITools#809 (comment)).
Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
In OpenAPI 3.1 a schema may declare keywords next to its $ref, e.g.
{$ref: '#/components/schemas/Base', required: [id]}, or the same with
properties or compositions. collectCompositionPropertyNames treated any
$ref as a short-circuit and returned only the referenced component's
names, discarding the referencing schema's own siblings, so a required
name declared only in those siblings was reported as missing.
The names collected from the resolved component schema are now merged
with the referencing schema's own properties and composition members
instead of replacing them, and a $ref member's sibling keywords are
validated in place: its own required list is checked against the
composition-wide known names while the referenced component schema
keeps being validated under its own name. The visited guard is
unchanged.
See the review discussion on PR OpenAPITools#809
(OpenAPITools#809 (comment)).
Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
This branch has not been deployed
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.
Description
Fixes #407.
Required-property validation only ran on top-level component schemas. When a model was composed with
allOfand one of the sub-schemas was defined inline (an anonymoustype: objectwith its ownrequiredlist), that inline model was never traversed, so missing required properties went unreported.Reproduction
From the issue — this spec passes validation today, although the inline object requires
somethingwhich it does not define:With this change it reports:
Changes
validateModelRequiredPropertiesnow recurses into the sub-schemas of a model:allOf/anyOf/oneOfcompositionsitemsof array schemasErrors on inline models are reported under the name of the composing component model. Semantics of the existing rule options (e.g.
validateModelRequiredProperties) are unchanged.Sub-schemas that are pure
$refare skipped: the referenced component schemas are already validated on their own, and skipping avoids duplicate errors when a parser resolves references inline. A visited set keeps the traversal finite for shared or cyclic schema structures.Required names are checked against every property name declared across the whole composition tree rooted at the checked schema — the schema itself plus all its
allOf/anyOf/oneOfmembers, transitively, following$refmembers through the component schemas they point to. A valid composition may declare a required property in any of its branches instead of the composing schema itself (e.g. partialoneOfbranches like{required: [id]}/{required: [name]}over a parent declaring{id, name}, orallOf: [{$ref: Base}, {required: [id]}]withiddeclared inBase), so a required name present in any branch is known and not reported. Required names declared nowhere in the composition are still reported, and arrayitemskeep their own composition scope, since they describe different instances.Tests
Added cases to
OpenApiSpecStyleValidatorTest:allOfwith a missing required property produces the same error as a top-level modelallOfthat satisfies its constraints produces no errors (no false positives)itemswith a missing required property is reported as welloneOfbranches with the required properties declared on the composing schema produce no errors (review example)allOf: [{$ref: Base}, {required: [id]}]withiddeclared in the referencedBaseproduces no errors (review example)oneOfandallOf/$refcases) are still reportedAll 25 tests of the class pass (
libandclimodules green, full./gradlew spotlessApply testbuild on JDK 17).Summary by cubic
Fixes missing required-property validation for inline models defined inside
allOf/anyOf/oneOfcompositions and arrayitems. Previously only top-level component schemas were checked, so an anonymoustype: objectwith arequiredlist nested in a composition never got validated.items, reporting errors under the composing model's name, with a visited set to keep traversal finite for cyclic or shared schemas.$ref'd schemas and OpenAPI 3.1$refsibling keywords, so valid partial branches aren't reported; names declared nowhere still are.itemsvalidation.Written for commit 6f63115. Summary will update on new commits.