Closed E-gy closed 1 year ago
O boy. This one's really pushing it, thanks a lot for your detailed bug report. Properly determining which props should be required seems like a good issue we can fix first. I have no idea how the references are mixed up, I suspect this is the reason why some schemas are not even generated, but I'm curious to know how that would happen. Maybe our circular dependency resolver is giving up when it shouldn't?
Current workaround:
K3+
types into J
types)unused
method (in a controller), declared before everything;
in body or return, reference all the intermediate types@Hidden
to remove from docsThankfully @Hidden
removes the method from docs, and does not intefere with types construction/exploration, so the docs, and validation get generated successfully.
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 asrequired
. (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 configurationThis 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.