Open bertrand-caron opened 2 years ago
Note that I was previously using typescript-json-schema
which handled this well (but not other things :S), in case that helps narrow down the issue.
Thanks for filing the issue. You might be able to narrow down the issue a bit more. Then, you could look into the corresponding code to see what may cause this bug.
Hi @domoritz , thanks a lot for the quick response :)
Is there anything more that you would like me to provide? I feel like my example is minimal, well-defined and self-contained.
Just for completeness, this is the expected schema (same as B
, but with the property a2
omitted from both B1
and B2
):
$ yarn run --silent ts-json-schema-generator --path A.ts --type C
{
"$ref": "#/definitions/B",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"B": {
"anyOf": [
{
"$ref": "#/definitions/B1"
},
{
"$ref": "#/definitions/B2"
}
]
},
"B1": {
"additionalProperties": false,
"properties": {
"a1": {
"type": "string"
},
"b1": {
"type": "string"
}
},
"required": [
"a1",
"b1"
],
"type": "object"
},
"B2": {
"additionalProperties": false,
"properties": {
"a1": {
"type": "string"
},
"b2": {
"type": "string"
}
},
"required": [
"a1",
"b2"
],
"type": "object"
}
}
}
Thanks a lot.
This looks related to an issue I reported a while ago: https://github.com/vega/ts-json-schema-generator/issues/952
Thanks for finding a potential duplicate. It's hard to know until looking further into it but once someone can take a closer look, we can see whether they are the same.
I came across the same problem and just had to refactor my code to use a union plus an intersection, instead of Omit
. It can make the types a bit more complicated but the schema comes out cleaner if the various intermediate types have names.
Looking for a resolution to this issue. Occurs when using Pick
with Exclude
or when using Omit
.
Currently, Pick
, Exclude
and Omit
are not fully supported by this library. I'm happy to review pull requests :)
Probably also related to https://github.com/vega/ts-json-schema-generator/issues/189
Hi,
I have the following example which seems to return erroneous results:
The JSON schema for type
C
should be a type union, but is not:Note that the type
B
seems to be correctly handled:Note that I am running
"ts-json-schema-generator": "0.96.0"
and"typescript": "4.3.5"
.