-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create schema uses anyOf
instead of allOf
#2008
Comments
I can't fully recall the details right now but I remember that the semantics of ts and json schema were different so that using allOf with additional properties wasn't semantically equivalent. Try a few examples and may e you find the example I can't recall right now. |
That's right, also a smaller schema is better for any tool that may use it. However, I thought using references instead of literal types should result into a usage of export type Foo = { foo: string };
export type Baz = { baz: string };
export type Bar = { bar: string };
export type ISchema = (Foo | Bar) & Baz; results into: {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Bar": {
"additionalProperties": false,
"properties": {
"bar": {
"type": "string"
}
},
"required": [
"bar"
],
"type": "object"
},
"Baz": {
"additionalProperties": false,
"properties": {
"baz": {
"type": "string"
}
},
"required": [
"baz"
],
"type": "object"
},
"Foo": {
"additionalProperties": false,
"properties": {
"foo": {
"type": "string"
}
},
"required": [
"foo"
],
"type": "object"
},
"ISchema": {
"anyOf": [
{
"additionalProperties": false,
"properties": {
"baz": {
"type": "string"
},
"foo": {
"type": "string"
}
},
"required": [
"baz",
"foo"
],
"type": "object"
},
{
"additionalProperties": false,
"properties": {
"bar": {
"type": "string"
},
"baz": {
"type": "string"
}
},
"required": [
"bar",
"baz"
],
"type": "object"
}
]
}
}
} Is that right too, @domoritz? |
The additional properties false with all of makes the semantics tricky. |
Makes sense. Is the generated schema creating any incompatibilities? |
Hello,
Below is an example where interface could be
Output is
I am wondering why not using allOf instead since it's more efficient and easier to understand especially when using any schema validation lib so output could be such as
Do you guys have any clue on how to improve this ?
Thanks
The text was updated successfully, but these errors were encountered: