-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
base: main
Are you sure you want to change the base?
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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]!) }; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 }; | ||
} |
There was a problem hiding this comment.
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)?
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.