ajv-validator / ajv

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
https://ajv.js.org
MIT License
13.83k stars 876 forks source link

Why does AJV contain its own types for JSON Schema instead of using an external package #2312

Open isqua opened 1 year ago

isqua commented 1 year ago

What version of Ajv are you using? Does the issue happen if you use the latest version?

8.12.0

Your typescript code

import type { JSONSchemaType } from "ajv";

Describe the change that should be made to address the issue?

Hello everyone! First of all, thanks to all the maintainers for your contribution!

I would just like to know why ajv contains its own definitions for JSON Schema. JSON Schema is a Standard, so its types should be the same in different applications. Common types would help to glue different packages. It may look like this:

import Ajv from "ajv";
import schemaBuilder from "some-schema-builder-package";

import type { JSONSchemaType } from "some-common-schema-package";

const ajv = new Ajv();

const mySchema: JSONSchemaType<MyEntity> = schemaBuilder<MyEntity>(/* ... */);
const validate = ajv.compile(mySchema);

But now I have to redefine package typings to make types from ajv and different packages "match" to each other.

On the json-schema.org website I found typescript-json-schema package, which imports types from @types/json-schema package.

Why doesn't ajv use @types/json-schema package?

Are you going to resolve the issue?

Apparently, this is an ideological issue, so I’m not able to solve it.

heath-freenome commented 3 months ago

@isqua From what I can tell @types/json-schema only goes up to JSON Schema version 7. There are two more version since then, which AJV supports. I have already created an issue to at least export their types to a separate, installable package.