Open EelcoHoogendoorn opened 5 years ago
I've seen this without the nullable aspect. It seems to have recently broken. Possibly due to a TypeScript update.
Hey guys, I have encountered the same issue :
Initial type to convert
interface MissingNull {
prop: string | null
}
Output json schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"prop": {
"type": "string"
}
},
"type": "object"
}
Expected behavior
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"prop": {
"type": ["string", "null"]
}
},
"type": "object"
}
Is there any investigation on this issue?
Thanks!
cc @ForbesLindesay
Actually, when using the --strictNullChecks
option the correct json schema is outputed
As you discovered, this is expected behavior given the Typescript semantics.
same for me,--strictNullChecks not work
Please describe the minimal program you encounter the issue with.
/**
* @minimum 1
* @TJS-type integer
*/
type natural = number;
interface Schema {
n1: natural | null;
n2: natural;
}
Becomes:
"Schema": {
"type": "object",
"properties": {
"n1": {
"type": [
"null",
"number"
]
},
"n2": {
"minimum": 1,
"type": "integer"
}
},
"required": [
"n1",
"n2"
]
},
While I would expect:
"Schema": {
"type": "object",
"properties": {
"n1": {
"type": {
"anyOf": [
{
type: "null"
},
{
"minimum": 1,
"type": "integer"
}
]
},
"n2": {
"minimum": 1,
"type": "integer"
}
},
"required": [
"n1",
"n2"
]
},
Any updates?
This results in json for a plain unannotated number being generated. With @nullable, it does work correctly.