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
Path params #2
Comments
I did initially consider adding I'm open for adding support if there is a use-case though, could you explain your requirement for |
I think using path parameters for identifying an item within collection is a common (best) practice.
We currently already have a couple of rest endpoints with path parameters and we are now trying to migrate them to What do you think about my proposed solution? It seems the model remains quite straightforward, where |
Ok, let's support this! Breaking changeInput for queries are restricted to I don't think isn't a huge issue (currently in alpha) but just wanted to raise. Usagetrpc.router()
.query('getUserById', {
meta: { openapi: { enabled: true, method: 'GET', path: '/user/{userId}' } },
input: z.object({ // validated as ZodObject({ [string]: ZodString })
userId: z.string(), // `userId` is required in schema because it is used in path
teamId: z.string(),
}),
output: ...,
resolve: ...,
})
.mutation('updateUserById', {
meta: { openapi: { enabled: true, method: 'PUT', path: '/user/{userId}' } },
input: z.object({ // validated as ZodObject({ [string]: ZodType })
userId: z.string(), // `userId` is required in schema & validated as ZodString
details: z.object({
name: z.string(),
}),
}),
output: ...,
resolve: ...,
}) Obviously paths with multiple parameters should be supported too e.g.
A quick scan of your PR looks great, I will review properly and add to docs + some tests tomorrow. Thanks @dodas! |
Great! Happy to hear this. |
Hi @dodas, support for Please can you upgrade to |
Perfect, thanks!! |
Hey @jlalmes, this is a great little library!
I am exploring possibilities and as far as I can understand, there is currently no way to define a
path
parameter.Consider the petstore swagger example, the
uploadFile
haspetId
parameter, which is part of the path.Could we try to extract the path params by looking for curly braces in
meta.openapi.path
, and then find param with the same name ininput
and mark that param asfrom: "path"
instead offrom: "query"
?WIP attempt to implement the above approach: v0.1.0...dodas:feat/path-parameters
Have you thought about supporting this use case?
I am happy to discuss this and potentially take a stab at implementing it.
Thanks!
The text was updated successfully, but these errors were encountered: