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

Error: can't resolve reference http://json-schema.org/draft-07/schema# #47

Open
mikebrant-xdelivery opened this issue Jan 12, 2022 · 2 comments

Comments

@mikebrant-xdelivery
Copy link

It seems as if there is an out-of-the-box compatibility issue with Ajv2020 instances of ajv.

When trying to apply the ajv-merge-patch keywords, I get...

Error: can't resolve reference http://json-schema.org/draft-07/schema# from id # at Object.code (/Users/[redacted]/node_modules/ajv/dist/vocabularies/core/ref.js:21:19) at ...

...which looks like is related to code in /keywords/add_keyword.js of this repo where this metaschema is referenced.

Code to reproduce...

import Ajv2020 from 'ajv/dist/2020.js';
import ajvMergePatch from 'ajv-merge-patch';

const ajv = new Ajv2020();
ajvMergePatch(ajv);

I was able to workaround with the following...

import { readFileSync } from 'fs';

import Ajv2020 from 'ajv/dist/2020.js';
import ajvMergePatch from 'ajv-merge-patch';

const ajv = new Ajv2020();

// required by ajv-merge-patch
const draft7MetaUrl = new URL('../node_modules/ajv/dist/refs/json-schema-draft-07.json', import.meta.url);
const draft7MetaSchema = JSON.parse(readFileSync(draft7MetaUrl, 'utf8'));
ajv.addMetaSchema(draft7MetaSchema);

ajvMergePatch(ajv);

...but figured I would open issue here to raise visibility.

I know that ajv itself indicates there is no cross-compatibility between draft-2020-12 and draft-07 schema within same ajv instance, however this does seems to work. At a minimum, I would find it unexpected that a developer using only draft-2020-12 (or draft-2019 for that matter) schemas within their application and wanting to leverage this extension would get such breakage, with reference to a schema they are not even using.

@fredericosilva
Copy link

Same crash here, It took a while to find the source of the problem.

@kierans
Copy link

kierans commented Mar 7, 2023

A simpler solution is to just require the JSON file.

ajv.addMetaSchema(require("ajv/dist/refs/json-schema-draft-07.json"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants