Repository navigation
Using JSON Schema draft 2020-12 in a browser (no node) #2576
Replies: 1 comment
|
Two separate things are going on here.
esm.sh handles both fine: import Ajv2020 from "https://esm.sh/ajv@8.17.1/dist/2020";
import addFormats from "https://esm.sh/ajv-formats@3.0.1";
const ajv = new Ajv2020({ allErrors: false, strict: false });
addFormats(ajv);
const validate = ajv.compile(schema); // schema with "$schema": "https://json-schema.org/draft/2020-12/schema"I loaded exactly those two URLs as ES modules and compiled a 2020-12 schema with Pin the versions in the URL like above, so a CDN update doesn't change things under you. |
Uh oh!
There was an error while loading. Please reload this page.
Is it possible to use AJV to validate against the 2020-12 draft when not using node? If so, how?
I have this in my JS Module:
But I get this error:
I tried using things like:
import Ajv from 'https://cdn.skypack.dev/ajv@8/dist/2020';And:
import Ajv from 'https://cdn.skypack.dev/pin/ajv@v8.17.1-UKm50DkWEnJMoj3nYxxl/mode=imports,min/unoptimized/dist/2020.js' But they both produce errors reading from data.json:Uncaught SyntaxError: Unexpected token ':' (at data.json:2:8)`The data.json is in loaded from https://cdn.skypack.dev/-/ajv@v8.17.1-UKm50DkWEnJMoj3nYxxl/dist=es2019,mode=imports/unoptimized/dist/refs/data.json
I tried to add the schema as a meta-schema using:
But then I get this error:
So I thought, maybe iterate through the draft, find all the references, and add them as meta-schemas first, but that fails with the same error as the first attempt (I think because they all start with "$schema": "https://json-schema.org/draft/2020-12/schema").
Any way to get this to work?
All reactions