-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[swagger-zod] readOnly properties are omitted using .and
, creating a intersection of never
and original type
#943
Comments
Not sure what we can do here with that |
Another option is to use So you could just replace what is generated now with |
Extend only works on another object so we need to remove the |
@stijnvanhulle this actually makes sense since zod implements This will probably just be a type-only implementation which could be achieved with Maybe something like below which will result in a partial readonly typed object:
I can have a look at creating a PR if you want, sometime this week |
That might be a good option in some cases. However it’s a little unclear to me what the goal is. My goal is to have a validator that excludes readOnly properties so I can validate a form. I don’t really care if the form object actually contains those properties because my backend will ignore them. I’m trying to avoid defining a whole other set of objects in my schema that exclude those readOnly fields. I don't need a type to enforce the read only status on a given object. Perhaps that’s useful for others cases tho. |
Based on specification here:
I'd expect the property to not be visible in the request schema, only the response schema. The zod |
I have the same problem. Readonly turn to If you look at the type def generated by the swagget-ts plugin it interpret it as im my case the omit should be more appropriate. Where i do not need to expose this option in the request body. Made a little test for alternative implementation
|
What version of
kubb
is running?kubb/2.13.0 darwin-arm64 node-v20.11.1
What platform is your computer?
No response
What version of external packages are you using(
@tanstack-query
,MSW
,React
,Vue
, ...)zod: 3.22.4
What steps can reproduce the bug?
I have some readOnly properties, and the resulting zod schema attempts to omit them by using
.and(z.object({ id: z.never() })
. This results in an intersection which means both schemas have to pass. For a never and some other type, that isn't possible so the validation always fails. See https://zod.dev/?id=and for more on.and
zod has an
.omit
function that might be a better fit here: https://zod.dev/?id=pickomitHow often does this bug happen?
Every time
What is the expected behavior?
No response
Swagger/OpenAPI file?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: