You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generating a schema for a union type creates a schema that accepts anything if the value for the discriminator is not one of the values in the union. For example:
Typescript types:
/** * @discriminator type */exporttypeUnion=A|B;exporttypeA={type: "A",a: string,}exporttypeB={type: "B",b: string,}
Currently the schema would validate against for example this JSON while it should not be accepted:
{
"type": "C",
"c": "this is a string"
}
Note that the type Union does not require the discriminator value to be one of the constants defined in the type and expected by the if keyword. This problem can be fixed by requiring the Union type to have a type that is either "a" or "b" like so:
"properties": {
"type": {
"enum": ["a", "b"]
}
},
The text was updated successfully, but these errors were encountered:
mvanniekerkSQ
added a commit
to mvanniekerkSQ/ts-json-schema-generator
that referenced
this issue
Dec 8, 2022
Generating a schema for a union type creates a schema that accepts anything if the value for the discriminator is not one of the values in the union. For example:
Typescript types:
Gives the following output:
Currently the schema would validate against for example this JSON while it should not be accepted:
Note that the type
Union
does not require the discriminator value to be one of the constants defined in the type and expected by theif
keyword. This problem can be fixed by requiring theUnion
type to have a type that is either "a" or "b" like so:The text was updated successfully, but these errors were encountered: