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
{{ message }}
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.
As you can see, Bar uses allOf to extend Foo by narrowing the value for name and by adding an additional sub-property of data.
Problem 1
The presence of data in Bar seems to override the data property of Foo, so that only bar is present, not fooandbar.
All other JSON schema parsers I've used successfully merges properties when using allOf, for example ReDoc, swagger-to-ts, and json-schema-to-typescript, so that objects mixed using allOf are merged.
For large schemas re-used in multiple sub-schemas, this results in much more verbose types with less readability.
Question: Is the behaviour of allOf well defined in the specification or is there room for interpretation? I've been trying several tools for creating TS types from my OpenAPI specs and it seems each one has its own set of quirks (some don't handle oneOf inside allOf, some support oneOf directly in another schema without allOf, ...), so it's been a real pain, but all the other ones seem to handle deep merging of schemas with allOf. So is this a bug or is this how dtsgen interprets the specification?
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I found several strange things related to merging of properties with
allOf
.Consider the following document:
This generates the following:
As you can see,
Bar
usesallOf
to extendFoo
by narrowing the value forname
and by adding an additional sub-property ofdata
.Problem 1
The presence of
data
inBar
seems to override thedata
property ofFoo
, so that onlybar
is present, notfoo
andbar
.All other JSON schema parsers I've used successfully merges properties when using
allOf
, for example ReDoc,swagger-to-ts
, andjson-schema-to-typescript
, so that objects mixed usingallOf
are merged.Expected result:
Furthermore, if I extract the type of
data
as a schema of its own, like this:Then the
Data
type is referenced correctly forFoo
:If
data
had been merged, I would have expectedBar.data
to be typed asData & {bar?: string;}
, like this:Problem 2.
As a workaround to the first problem, I explicitly add an
allOf
also for the data property:Then
Bar.data
at least contains bothfoo
andbar
, butfoo
is inlined instead of using an union withData
.Actual result:
Expected result:
For large schemas re-used in multiple sub-schemas, this results in much more verbose types with less readability.
Question: Is the behaviour of
allOf
well defined in the specification or is there room for interpretation? I've been trying several tools for creating TS types from my OpenAPI specs and it seems each one has its own set of quirks (some don't handleoneOf
insideallOf
, some supportoneOf
directly in another schema withoutallOf
, ...), so it's been a real pain, but all the other ones seem to handle deep merging of schemas withallOf
. So is this a bug or is this howdtsgen
interprets the specification?The text was updated successfully, but these errors were encountered: