-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
RFC: Add "examples"
to OpenAPI schema
#261
Comments
It is already possible to provide a description to a field using - .input(z.object({ name: z.string().openapi({ description: "Your full name", example: "Sonny Moore" }) /* 👈 */, greeting: z.string() }))
+ .input(z.object({ name: z.string().describe('Your full name') /* 👈 */, greeting: z.string() })) As you are not the first one to ask for this feature, I think we should add an .meta({
openapi: {
method: 'GET',
path: '/say-hello/{name}',
// 👇 Any thoughts on this API?
examples: {
input: [{ name: 'Sonny Moore', greeting: 'Hello' }],
output: [{ greeting: 'Hello Sonny Moore!' }]
}
}
}) PS. one of my fave songs of all time 👉 https://www.youtube.com/watch?v=AM3J4428cyc |
"examples"
to OpenAPI schema
I literally was about to file this as an issue. And the propsed api was pretty close to what i was going to suggest. The documentation that came out of this project was very nice and required very little effort from me, but this is what the swagger editor does when it tried to generate an example for one of my routes. The logoUrl and thumbnailUrl are the result of using a regex validator: |
Somebody finally got one of my skrill references! Instead of doing just the example what if we allowed the Maybe
I guess certain fields of |
Any update on when this might happen? I'd love to be able to use this instead of patching the json object i get back from the call. |
This is now supported! const appRouter = t.router({
queryExample: t.procedure
.meta({
openapi: {
method: 'GET',
path: '/query-example/{name}',
example: {
request: { name: 'James', greeting: 'Hello' },
response: { output: 'Hello James' },
},
},
})
.input(z.object({ name: z.string(), greeting: z.string() }))
.output(z.object({ output: z.string() }))
.query(({ input }) => ({
output: `${input.greeting} ${input.name}`,
})), |
I'm looking for a way to add openapi annotations to inputs and outputs.. something like:
The
zod-to-openapi
extension enables the openapi annotation, but you have to then manually create each path.What would great is a mashup of
trpc-openapi
andzod-to-openapi
.I think this would be possible by swapping out the
zod-to-json-schema
library with the generator inzod-to-openapi
.If there's interest in this I might be able to spend some time on it.
The text was updated successfully, but these errors were encountered: