openapi-typescript
openapi-typescript copied to clipboard
Export component's and path's types with friendly names
Description
First of all, I want to thank you for this great lib! :) To make it even better, I suggest exporting component types and paths like open-api-generator does.
Proposal
The first attempt to implement this is here https://github.com/drwpow/openapi-typescript/pull/1260. The idea is to generate types like this: Components:
export type SchemaSimpleUser = components["schemas"]["simple-user"];
export type SchemaInstallation = components["schemas"]["installation"];
...
export type ResponseNotFound = components["responses"]["not_found"];
export type ResponseRequiresAuthentication = components["responses"]["requires_authentication"];
...
export type ParameterPerPage = components["parameters"]["per-page"];
export type ParameterPage = components["parameters"]["page"];
...
export type HeaderLink = components["headers"]["link"];
export type HeaderXRateLimitLimit = components["headers"]["x-rate-limit-limit"];
Paths:
export type RequestEnterpriseAdminListGlobalWebhooks = paths["/admin/hooks"]["get"]["parameters"];
export type RequestEnterpriseAdminGetGlobalWebhook = paths["/admin/hooks/{hook_id}"]["get"]["parameters"];
It would be also nice to generate types for requestBody and responses, but not sure how to properly handle content type (application/json, application/yaml etc.)
We also need to resolve the duplication issue described in this comment https://github.com/drwpow/openapi-typescript/pull/1260#issuecomment-1658694431. This can be solved by adding a number as a suffix to the duplicate name.
Checklist
- [x] I’m willing to open a PR for this (see CONTRIBUTING.md)