Replies: 7 comments
-
Hello @miki725 , could you please clarify what kind of things could go to such annotations to be useful for the client in order to request the endpoint? |
Beta Was this translation helpful? Give feedback.
-
one use-case is when API has different levels of auth. for example most routes use regular API auth token, however some require special API token for staff/admin/etc. as the auth could be enforced by the API, that metadata is not visible to the client via generated types and therefore the client can attempt to make a request even if its guaranteed to fail (e.g. regular user attempting to call admin-only endpoint). by allowing to annotate each route, it can let the client know more information about the endpoint such as auth requirements which cannot be inferred from types alone |
Beta Was this translation helpful? Give feedback.
-
Thank you for the explanation, @miki725 . I wouldn't like to add another method for However, from my understanding the problem, I'd like to find a way to export at least I think that if you tag your endpoints with the required token type, and if this information will be available as a dictionary in the generated client, this might come helpful. export const endpointTags = {
"get /v1/user/retrieve": [ "user", "regularToken" ] as const,
"delete v1/user/:id": [ "user", "adminToken" ] as const,
} Similar to existing I'm going to think on it a bit. Please let me know if I'm missing something. |
Beta Was this translation helpful? Give feedback.
-
Check this out, @miki725 : Would this come handy for your goals? |
Beta Was this translation helpful? Give feedback.
-
yes that will def be useful |
Beta Was this translation helpful? Give feedback.
-
🚀 11.6.0, @miki725 |
Beta Was this translation helpful? Give feedback.
-
thank you so much for adding the feature and shipping it 🎉 |
Beta Was this translation helpful? Give feedback.
-
it would be useful to add annotations which will persist in the generated client similarly to how route can be annotated for the generated docs (e.g.
tags
)express-zod-api/example/example.client.ts
Lines 114 to 118 in 602f6f3
currently generated client only has a single js-exported constant
jsonEndpoints
which enumerates all endpoints where the value istrue
. it would be nice to be able to add custom annotations to either the same constant or another exported constant with custom metadata about the endpoint the client can take into account when making requests to the api. perhaps something like:Beta Was this translation helpful? Give feedback.
All reactions