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

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

Open
isqua opened this issue Jul 25, 2023 · 1 comment

Comments

@isqua
Copy link

isqua commented Jul 25, 2023

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
Copy link

heath-freenome commented Jul 26, 2024

@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.

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

No branches or pull requests

2 participants