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

Fixes: Null and undefined value handling #286

Open sudowoodo200 opened 4 months ago

sudowoodo200 commented 4 months ago

Three fixes

  1. When there is a default value, the TS type will be optional. When .default() is used, Zod infers the input field to be optional, even if the field is required. This makes sense because we are parsing inputs. The strictly correct way is to build two types, Type and TypeInput. But it is bloated. This serves its purpose.
  2. Scattered nullable additions that we forgot before
  3. ZodSchema chaining for "oneOf" types. I suspect there are more bugs like this, but for future fixes.

This should now work on both the full petstore.yaml example and the gigantic openai specs

One JSDoc test is failing. I'm not sure what's going on.

vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
openapi-zod-client-rim4 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 14, 2024 1:25pm