Replies: 5 comments 5 replies
-
well, this is a conceptual problem, because technically you do actually can, but the request might be handled by "not found (404)" handler which is a part of the API. It also can be handled by something besides the routing established by the framework itself, which is possible when using However, I understand the confusion.
this is similar to the interface of OctoKit Request. Here is what I can do:
- interface Response extends Record<MethodPath, any>
+ interface Response
- Promise<Response[`${M} ${P}`]>
+ Promise<`${M} ${P}` extends keyof Response ? Response[`${M} ${P}`] : never> And probably this |
Beta Was this translation helpful? Give feedback.
-
I checked how OctoKit behaves in a similar scenario, @HenriJ , which I'd consider an etalon of REST API client, and it turned out that it does not prohibit unknown methods and undeclared routes. It acts exactly the same way as I implemented here — it returns Taking this finding into account, I'd consider the desired behaviour as a feature, not a bug of missing it. |
Beta Was this translation helpful? Give feedback.
-
Interesting, maybe octokit was written before I am trying to understand the trade-off between using the included frontend client generation versus using any other "openapi to client" lib that exist (for example to have react-query hooks auto-generated). Do you have any insight to share ? Also while reading the source code regarding the openapi schema generation, I wondered if using a lib like https://github.com/samchungy/zod-openapi might make it easier ? |
Beta Was this translation helpful? Give feedback.
-
It's not difficult to make it return But I came to conclusion that in order to make this:
You can do that. It's just a longer path to make OpenAPI generated first and then based on it to generate a Typescript client. |
Beta Was this translation helpful? Give feedback.
-
Dear @HenriJ , Could you please install it, try it and let me know if it worked well for you? |
Beta Was this translation helpful? Give feedback.
-
Description
In the current implementation
MethodPath
is the combination of all possible methods with all possible paths.What it means is that I am able to call
client.provide("delete", "/v1/user/retrieve", { id: "10" });
even if there is no delete method linked with this path.
Expected
I should get a typescript error when calling a path that does not provide the requested method.
As a workaround, I implemented my own client that instead of taking a method and a path separately directly takes the full endpoint "get /v1/user/retrieve" (I'm using
keyof type endpointTags
to get the list of available endpoints which is not perfect though).Reproduction
Try to call an endpoint with a method that does not exists.
Context
express-zod-api
version: 20.21.0Beta Was this translation helpful? Give feedback.
All reactions