You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
getUserById: loggedInProcedure.meta({openapi: {tags: [USER_TAG],method: 'GET',path: '/users/{id}',/* 👈 */contentTypes: ['application/json'],summary: 'Gets user by ID',protect: true,errors: [{type: 'NOT_FOUND',errorMessage: 'User not found.',},],},}).input(UsersSchema.getUserByIdParamsSchema)/* 👈 z.object({ id: z.string().uuid() } */.output(UsersSchema.getUserByIdDTOSchema).query(async({ input })=>{returnUsersService.getUserById(input);}),
AND
getUserClaim: loggedInProcedure.meta({openapi: {tags: [USER_TAG],method: 'GET',path: '/users/claim',/* 👈 */contentTypes: ['application/json'],summary: 'Gets the current user to be claimed',protect: true,errors: [],},}).input(UsersSchema.getUserClaimParamsSchema)/* 👈 z.void() */.output(UsersSchema.getUserClaimDTOSchema).query(async({ ctx })=>{returnUsersService.getUserClaim({id: ctx.user.id});}),
When you try to access the '/users/claim' route, trpc-openapi checks all of the routes, one by one, to check if there is a one that matches the endpoint you are trying to reach. If the matching route is found, searching stops(it searches until it finds). I believe both your endpoint declarations (listed above) match the endpoint you are trying to reach so the first one wins.
It looks similar to endpoint declaration in pure express.js where, if you have two routes declarations, and one is a subset of the other, you need to declare them from the most specific to the most broad.
In your case ‘/users/{id}’ is broader than ‘/users/claim’ because there is enormous combination of string you can theoretically use as id (eg “claim”) vs single word “claim”. An example of even more broad endpoint declaration is ‘/’.
in my understanding’ if you declare endpoint ‘/’ and put it before your two declarations, it will shadow/take precedence over your two endpoint declarations because it matches the ‘/users/claim’ as your endpoints and is declared first.
hope it helps anyhow. For further ingestion, look for ‘dynamic path segments’ or something like that in express.js docs.
I will check later if I’m 100% sure about that shadowing.
Happy coding!
I have two API endpoints:
AND
And when I try to hit
/users/claim
I get:
It works if I remove the
/users/{id}
endpoint OR if I put the path:/users/claim
on top of/users/{id}
Any ideas as to why this happens? Thanks!
The text was updated successfully, but these errors were encountered: