astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)
openapi-zod-client.vercel.app
717 stars 80 forks source link

Type intersections using allOf with required keys does not result in required properties #291

Open mithodin opened 3 months ago

mithodin commented 3 months ago

Describe the bug I think this a regression of the issue described in https://github.com/astahmer/openapi-zod-client/issues/260 (which is closed as resolved). When intersecting two schemas using allOf, where one of the schemas adds a required constraint to a property defined by the other scheme, the constraint is not represented in the generated code.

Minimal reproduction https://openapi-zod-client.vercel.app/?doc=PYBwpgdghiCWBcACAzAOgAyuQKFhAZsPNoogC6xkA2YSAogB5QC2IN2IUZAFgM7GkA9GTC8yA0ogDmYcSUmkATqJDAIvURIWkATOnRbtpAMZqREOUaMw2sY11hrBAK15rDVyb2PcwzKB6ekgAkyvhIAOQAxIKmrGqQZLyC3r7%2ByQAqAJ7gAEIR2HGqEIn88ql%2BUGUK2eAAgoFkObSIwABGzmDGZPIKIIqgYIoUmr3aAWNGTeBIeCIyipOSbYEK0y1zYAtjtWC5gVBUVADy4UukALTkzUjtnd3nksoAjgCusMoAJqvaV1CPV1CYHCiGisWA8RKFmSFXSgl2dQiQA

Expected behavior In the given example, I would expect the resulting types to be

const TypeA = z.object({ a: z.number().int(), b: z.number().int() }).partial().passthrough();
const TypeB = TypeA.required({ a: true });

or something to the same effect.