Skip to content

Always make all references absolute in nested bundled schemas #4683

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 1 commit into
base: main
Choose a base branch
from

Conversation

GlassOfWhiskey
Copy link
Contributor

This commit adjusts all internal references of a bundled schema to be absolute, allowing subschemas to be correctly resolved.

Reasons for making this change

Field renderers often resolve references on subsets of the original subschema, with are always validated against the whole root schema. However, bundled schemas may contain relative references, which should be resolved against an internal $id field. To resolve this problem, all references in nested bundled schema are now transformed into absolute references, so that they are always resolvable against the root schema.

This commit adjusts all internal references of a bundled schema to
be absolute, allowing subschemas to be correctly resolved.
@@ -16,6 +16,13 @@ should change the heading of the (upcoming) version to include a major version b

-->

# 6.0.0-beta.11
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# 6.0.0-beta.11
# 6.0.0-beta.12

const currentURI = get(schema, ID_KEY, baseURI);
// Make all other references absolute
if (REF_KEY in schema) {
schema = { ...schema, [REF_KEY]: UriResolver.resolve(currentURI, schema[REF_KEY]!) };
Copy link
Member

Choose a reason for hiding this comment

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

So we are manipulating the root schema here or the lower-level schema as we are calling retrieveSchema()? Honestly, with a few changes to the createSchemaUtils() and Form in core, we could probably run this code over the rootSchema once and cache it in the schemaUtils object. And then use that schema within the Form by updating the getRegistry() function and update the schema in the state within Form to pick up the cached, updated rootSchema from the schemaUtils. Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I just updated the Form in core to always use the rootSchema in schemaUtils in this PR so all you have to do is modify the schemaUtils to cache the modified rootSchema having made references absolute.

Comment on lines +153 to +160
if (
rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2019_09 ||
rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12
) {
return { [ALL_OF_KEY]: [remaining, subSchema] } as S;
} else {
return { ...remaining, ...subSchema };
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have different logic for different standard versions? Is the allOf option more correct (and could we use it for draft-07)?

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.

3 participants