Skip to content
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

Pass baseId to getSchemaRefs to fix local $ref resolution in a schema without an id. #1725

Merged
merged 2 commits into from Sep 12, 2021

Conversation

rbuckton
Copy link
Contributor

@rbuckton rbuckton commented Aug 1, 2021

What issue does this pull request resolve?

Fixes #1711

What changes did you make?

Pass baseId to getSchemaRefs so that $ref can resolve local references when the parent schema has no $id.

Is there anything that requires more attention while reviewing?

No, though running npm run test-spec results in 156 test failures without my changes, and doesn't seem to currently be wired up to npm test in any way.

Comment on lines +95 to 97
const schId = normalizeId(schema[schemaId] || baseId)
const baseIds: {[JsonPtr in string]?: string} = {"": schId}
const pathPrefix = getFullPath(schId, false)
Copy link
Contributor Author

@rbuckton rbuckton Aug 1, 2021

Choose a reason for hiding this comment

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

Honestly, not even sure schId is necessary since baseId is already computed by Ajv.prototype._addSchema.

Suggested change
const schId = normalizeId(schema[schemaId] || baseId)
const baseIds: {[JsonPtr in string]?: string} = {"": schId}
const pathPrefix = getFullPath(schId, false)
const baseIds: {[JsonPtr in string]?: string} = {"": baseId}
const pathPrefix = getFullPath(baseId, false)

@epoberezkin epoberezkin merged commit 831cb1c into ajv-validator:master Sep 12, 2021
@epoberezkin
Copy link
Member

thank you - in 8.6.3 - it was an annoying one, I'm surprised the fix was so simple ;)

@rbuckton rbuckton deleted the refResolveBaseURI branch November 30, 2021 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

A $ref to a fragment defined with $id in the same document isn't found.
2 participants