Closed maximpn closed 2 weeks 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)
https://github.com/elastic/kibana/pull/186221 addresses local circular references. In general case we'll need support non local references as well.
The task was implemented in https://github.com/elastic/kibana/pull/186221 and https://github.com/elastic/kibana/pull/187061.
Epic: https://github.com/elastic/security-team/issues/9723 (internal)
Summary
kbn-openapi-generator
package generates Zod schemas and related TS types from OpenAPI specification. It fails to handle recursive schemas. Code generation finished successfully but TS can't infer a proper type. See a related Zod documentation section.We need to add support for recursive OpenAPI schemas.
Details
OpenAPI specification allows to use references to decompose and simplify schema declarations. References can also be used to declare a recursive schema with arbitrary recursive chain length.
An example recursive schema looks like
The generated output has
SchemaA
andSchemaB
types inferred asany
Ideas to fix
As per Zod documentation section the problem can be resolved by explicitly declaring TS type and specifying it via
z.ZodType<>
. Additionallyz.lazy()
helps to resolveSchemaB
is used before its declaration issue. So the following TS file is valid and doesn't cause any issues