Skip to content

fix(ibm-valid-schema-example): support circular references in schemas #737

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

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from

Conversation

dpopp07
Copy link
Contributor

@dpopp07 dpopp07 commented Apr 7, 2025

PR summary

This rule would previously fail if it tried to validate the example for
a schema that contains a circular reference (i.e. defines a schema cycle)
because the ref resolver leaves these schemas with unresolved refs.
The JSON Schema validator tries to resolve the references but can't find
them, so it fails. This commit unconditionally adds the components from
the OpenAPI definition to the schema so that the JSON Schema parser can
find references if it needs to.

PR Checklist

General checklist

Please make sure that your PR fulfills the following requirements:

dpopp07 added 3 commits April 7, 2025 11:40
The Spectral 'context' object contains processed data about the
OpenAPI definition being validated, including the resolved and
unresolved versions of the definition and information about
references. We use these objects in rule functions and they need
to be extracted from deeply nested fields in the spectral context.
Rather than always needing to remember or look up the fields,
this commit allows us to use simple helper functions to get the
data we need.

Signed-off-by: Dustin Popp <[email protected]>
This rule would previously fail if it tried to validate the example for
a schema that contains a circular reference (i.e. defines a schema cycle)
because the ref resolver leaves these schemas with unresolved refs.
The JSON Schema validator tries to resolve the references but can't find
them, so it fails. This commit unconditionally adds the components from
the OpenAPI definition to the schema so that the JSON Schema parser can
find references if it needs to.

Signed-off-by: Dustin Popp <[email protected]>
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.

1 participant