Open
Description
Context:
Boolean JSON schemas are true
and false
:
true
passes the validation of any input.false
fails the validation of any input.
Consider the specs as references:
- https://datatracker.ietf.org/doc/html/draft-wright-json-schema-00#section-4.4
- https://datatracker.ietf.org/doc/html/draft-wright-json-schema-01#section-4.4
- https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-00#section-4.3.1
- https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-01#section-4.3.1
- https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-02#section-4.3.2
- https://json-schema.org/draft/2020-12/json-schema-core.html#name-boolean-json-schemas
How do we apply this in the library:
I would suggest the following changes:
- Whenever a
true
JSON Schema is transpiled to a type, the transpiled type should beany
orunknown
(depending on the config). - Whenever a
false
JSON Schema is transpiled to a type, the transpiled type should benever
Examples:
{
"$schema": "http://json-schema.org/draft/2020-12/schema",
"type": "object",
"additionalProperties": false,
"properties": {
"color": true,
"kind": true,
"number": false
},
"required": ["color, kind", "number"]
}
should be transpiled to something like:
export interface Foo {
color: unknown;
kind: unknown;
number: never;
}
I know, number: never
feels ugly, but never
is probably the type which works nicely not only in this simple example but also in more complex ones.
Current behavior:
Boolean JSON schemas are transpiled into their boolean types:
{
"$schema": "http://json-schema.org/draft/2020-12/schema",
"title": "Example Schema",
"type": "object",
"properties": {
"foo": true
},
"required": ["foo"]
}
is transpiled into:
export interface ExampleSchema {
foo: true
[k: string]: unknown
}
instead of
export interface ExampleSchema {
foo: unknown
[k: string]: unknown
}