ajv-validator / ajv-validator/ajv
Using $schema to validate against meta-schema is protocol-sensitive. Should it?
- Lingua principale
- TypeScript
- Stelle
- 14.8k
- Fork
- 1k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I'd like feedback on whether this is an issue and, if yes, what an optimal solution would be.
**What version of Ajv are you using?**
8.20.0
**What problem do you want to solve?**
$schema is an (optional) field in a user-defined schema. AJV uses it to validate the schema itself against a meta-schema.
For example, if a schema begins with
```
{
"$schema": "http://json-schema.org/draft-07/schema#",
```
AJV validates it against JSON Schema, draft 07, which is one of the popular meta-schemas.
The problem: AJV treats this field as protocol-sensitive. If a user gives the same schema address starting with `https`, AJV cannot retrieve the meta-schema and throws an error:
`Uncaught Error: no schema with key or ref "https://json-schema.org/draft-07/schema#"`
In this case, the route is identical; URLs differ only in protocol. A browser is able to retrieve draft 7 JSON Schema using any of these two URLs - and https is generally considered to be preferable, so users are likely to use https by default. However, only one of these URLs can be recognized by AJV - and it's not https.
**What do you think is the correct solution to the problem?**
A contributing factor is that the site of JSON Schema refers to *draft 7* at its dedicated page by using *https*:
https://json-schema.org/draft-07
...but the schema itself uses the `id` with *http*.
This schema comes bundled with AJV at `ajv/dist/refs/json-schema-draft-07.json`. One option is to make AJV treat these URLs as referring to the same meta-schema for metas bundled with it.
However, this may potentially have unintended consequences that I am not aware of. What do you think?
**Will you be able to implement it?**
Yes.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.