spectral icon indicating copy to clipboard operation
spectral copied to clipboard

fix(core): make JSON Schemas at `packages/core/src/ruleset/meta` valid

Open jviotti opened this issue 10 months ago • 3 comments

Plus add a GitHub Action that uses sourcemeta/jsonschema to perform some basic smoke tests to prevent regressions.

Fixes: https://github.com/stoplightio/spectral/issues/2787

jviotti avatar Feb 25 '25 01:02 jviotti

I tried to setup a basic GitHub Action to prevent regressions here, but as I sent the PR, I'm now realising you use CircleCI. Happy to revise the PR to just fix the schemas.

jviotti avatar Feb 25 '25 01:02 jviotti

Ah, looking at the CircleCI failures, you seem to be using AJV (https://ajv.js.org). That explains why the schemas were invalid. AJV, despite being quite popular, is one of the least compliant JSON Schema validators we are aware of, with significant deviations from the specification. See Bowtie, the official JSON Schema project that ranks implementations by compliance and the amount of failures we record for AJV across versions of JSON Schema: https://bowtie.report/#/implementations/js-ajv.

I also touched on AJV on my talk at the last JSON Schema Conference (see https://www.youtube.com/watch?v=wJ7bK22n3IU) and how it can lead you to inadvertently write invalid schemas.

Screenshot 2025-02-24 at 9 38 07 pm

jviotti avatar Feb 25 '25 01:02 jviotti

the reason you're seeing the failure for $id ... 2020-12 is because Ajv requires a different import from the base version. The default import is for draft-07

If you want to use 2020-12, you need to import ajv/dist/2020

jeremyfiel avatar Feb 25 '25 15:02 jeremyfiel