openapi-typescript
openapi-typescript copied to clipboard
client["/endpoint"].GET style call pattern to enable go-to-definition
Description
Navigating from call site to docs (aka generated typing) today is quite inconvenient as vscode is not able to navigate from the path argument parameter to the type def. I would love to be able to use cmd+click to be able to go straight to the generated types for the specific endpoint. This is similar to how trpc would work
Proposal
Before
client.GET('/endpoint', { params: {} })
After
client['/endpoint'].GET({ params: {} })
This way you can cmd+click on the /endpoint part in VSCode to go straight to defintion
We can keep both call styles too (just like TRPC) for backward compat.
Checklist
- [x] I’m willing to open a PR for this (see CONTRIBUTING.md)
I’m all for better Intellisence and VS Code integration, but how would the runtime work? Would client have to be a getter method? And would this be able to use openapi-typescript’s types as-generated? I’d be curious to see a PoC on how this could work from both a runtime and type inference side, even with a simple schema.
Sure. This it how it is used.
https://github.com/trpc/trpc/blob/44a1b58a3f21dae230cf290a71d93614d469e63b/examples/next-minimal-starter/src/pages/index.tsx#L8
This is how trpc implements it. I believe it uses native javascript Proxy object to accomplish it with explicitly casted typing
https://github.com/trpc/trpc/blob/44a1b58a3f21dae230cf290a71d93614d469e63b/packages/client/src/createTRPCClient.ts#L126-L145
And I don't see any reason to change openapi-typescript. I believe it should work as is.
This is fixed in #1791 / openapi-fetch 0.11.0.