-
-
Notifications
You must be signed in to change notification settings - Fork 882
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
Reference resolution issue in v7 #1414
Comments
is it specific to async loading, or it happened for schema added with addSchema as well? |
@epoberezkin It is indeed also broken if I use const Ajv = require("ajv").default;
const instance = new Ajv({
loadSchema: () => undefined,
});
instance.addSchema({
$id: "http://two/",
title: "Properties",
type: "object",
properties: {
bar: {
$ref: "#/definitions/bar",
},
},
definitions: {
bar: {
type: "string",
},
},
});
instance.compile(
{
$id: "http://one/",
type: "object",
properties: {
foo: {
$ref: "#/definitions/foo",
},
},
definitions: {
foo: {
$ref: "http://two/",
},
},
},
false
);
|
compileAsync
base URL confusion with asynchronously loaded references in v7
@solymosi thank you I can reproduce: https://runkit.com/esp/601700c43e06c0001a957eff It indeed happens in v7 and not in v6 - good catch. |
I'm using version 7.0.3.
Consider the following piece of code:
For whatever reason when processing the lazy loaded schema
http://two/
Ajv thinks that the base URL is stillhttp://one/
and tries to resolve thebar
property reference accordingly, resulting in this error:This problem is new in version 7, it first popped up after upgrading from version 6.
I've spent several hours debugging this issue and it seems like that changing this line:
https://github.com/ajv-validator/ajv/blob/v7.0.3/lib/compile/index.ts#L265
to
solves the issue in this particular case. I don't have enough knowledge of the codebase to be able to tell if this is the proper fix though, i.e. whether it could break something else.
If
#/definitions/foo
is inlined:then everything works as expected.
The text was updated successfully, but these errors were encountered: