-
Notifications
You must be signed in to change notification settings - Fork 509
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
Deeply nested wide mapped types on enums do not resolve (sometimes) #681
Comments
O boy. |
Current workaround:
Thankfully |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days |
Nesting mapped types eventually [deeply] does not correctly resolve the schema - not marking top-level props as
required
; sometimes causing a crash, depending on the breadth of nested types; and in oddly specific configurations, it's weird.Sorting
I'm submitting a ...
I confirm that I
Setup
We'll use the following mapped types setup:
and the extended
Basically,
K
types are mapped directly (without referring to smallerK
),J
are mapped to lowerJ
.Using a union type instead of enum
does not, and should not, change the behaviour.
Using different enums for every layer does not change the behaviour.
Sometimes it does, see (far) below. Correction: it does not indeed.To generate the schema, i'm putting all types in the same request body, but they can be put anywhere, we just need to use the types so they get included in the schema really,
To demonstrate a particular problem with
J
nesting however,K1
andnested
must not be referenced outsideJ
types:Expected Behavior
For the
K
types, deeper types should get nested the same way as shallower types (or perhaps they should rely on additional schemas, if OpenAPI has depth limits).And the properties should be marked as
required
.(repeated sections stripped to keep the issue somewhat readable)
For
J
types, deeper types should literally reference shallower types for nesting (and the properties be markedrequired
on every depth level):Current Behavior
Alright, so, for the shallow types (
K1
,K2
) andJ
types* everything works mostly as expected -the properties at first level of the schema are not marked as required.
Deep
K
types -K3
,K4
cause a crash [for both docs and routes generation], but not always. Which level crashes actually depends on the breadth - the primary setup generatesK3
fine and crashes onK4
, but the extended setup crashes onK3
(andK4
). The crash is the same in both cases (just replaceK4
forK3
):Finally, there's another thing. For some oddly specific configurations,
J
nesting generates schemas that loop on itself, instead of, well, going to lower levels.I haven't yet been able to determine a consistent/minimal type structure that produces this behaviour, and i will update the issue once i do.Best way to put it is "the nested type right after last nested type that is not reffered to outside of shallower nested types gets recursed on itself". Here's what i mean:
For the last referencing configuration
This is the generated spec:
Notice how
K1
refers to itself instead ofcontained
:Now, if we change remove
J2
,J3
from initial referencing:The spec generated is following:
Once again,
J3
loops on itself, but also schemas forJ2
andK1
are not even generatedBy extending
J
types down toJ7
, and referencing selectively from the request, we can see the looping consistently "in action":→
Context (Environment)
Version of the library: 3.0.8
Version of NodeJS: 13.11.0
Breaking change?
I don't think so.
The text was updated successfully, but these errors were encountered: