-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow overriding default .meta() and .getMeta() data types. #3
Conversation
Updated #2, please, check again. Can you give me an example use case for overwriting |
Ok, use case. For example, I use zod for validation in controllers and also want to have some openApi related data stored inside every instance of ZodType: const Input = z.object({
page: z.number().meta({ example: 5 }),
perPage: z.number().meta({ example: 50 }),
}); And I want to have autocompletion when I call In most of cases within a single project all metadata will have that type, so it is possible to be defined as a default data type. But in some rare cases I will store in meta some data having another data structure, like
P.S. Of course, as an alternative, it is possible to define a pair of helper functions for each use case, like |
I see. You may want to follow these issues then: One problem with the To be honest, the only property I needed (that I didn't already have from z.object({ firstName: ..., lastName: ... })
.meta({ [Symbol.for('openpi:refId')]: 'User' }) Let me know if #2 is doing it for you. |
@IvanovES if you want to be my guinea pig I rewrote zod-to-openapi to support auto registering schemas: https://github.com/samchungy/zod-openapi. Very similar API but I went with a different approach |
@samchungy This is exactly what I hoped for when I first discovered Though, please remove PS. I may have spoken too soon. You may still be able to have your Anyway, good job! |
Good feedback. I'll have a look at removing it |
Hello, Emil! Please consider approach that allows to define default metadata interface and also allows to override
.meta()
argument type and.getMeta()
return type by using generics!