Open maximpn opened 4 months ago
Pinging @elastic/security-detections-response (Team:Detections and Resp)
Pinging @elastic/security-solution (Team: SecuritySolution)
Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management)
Epic: https://github.com/elastic/security-team/issues/9723 (internal) Relates to: https://github.com/elastic/kibana/issues/186066
Summary
https://github.com/elastic/kibana/pull/186221 added support for local circular references code generation. Zod's discriminated union works only with object schemas which means ZodObject` type.
We need to tune code generation to support circular discriminated unions as well.
Details
Let's consider the following OpenAPI spec where
DiscriminatedUnionSchema
is a circular discriminated union schemaCode generation produces the following code
but there is a problem
It's clear that discriminated union doesn't support
z.lazy()
but removing it doesn't fix the problemTo have it fixed
SchemaA
should be typed asZodObject
. It can achieved either by typing it directly withZodObject
or omitZodType
for it. It's enough to have type hinting for only one zod schemas in a cycle to have types properly inferred. The valid TS code will look like