cloudflare / chanfana

OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!
https://chanfana.pages.dev
MIT License
302 stars 40 forks source link

Add support for `nullable` at least in request body params #87

Closed gimenete closed 1 year ago

gimenete commented 1 year ago

I've found myself needing a request body param to be either a string or null in a PATCH request. There's a required option, which means the param can be omited, but what I need is a explicit way to set a value as null, specially because I'm using PATCH to do partial updates or records in the database.

So far I've been using empty strings as a way to indicate that, but it's not ideal. It's confusing for the users of my API.

Thanks!

G4brym commented 1 year ago

Hey @gimenete thats a issue that is being fixed in the new v1.0 version, this new version also brings support for zod everywhere

in the pre release optional parameters missing will be let undefined in the validated data object

i'm not sure when are we going to release this new version, but you can already try it out by installing the prerelease version in the pr here

We are already using this new pre release version for our production workloads, and i don't expect the api to change anymore before the release

gimenete commented 1 year ago

Cool. I'm not sure when I'll be able to give it a try, but this is great news! Thanks!

G4brym commented 1 year ago

Hey @gimenete, i've just published the new v1.0.0 release that fixes this issue, now every optional parameter that is not received by the endpoint is let undefined Migration guide to 1.0.0 available here