Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export component's and path's types with friendly names #1598

Closed
1 task done
enkot opened this issue Mar 27, 2024 · 1 comment
Closed
1 task done

Export component's and path's types with friendly names #1598

enkot opened this issue Mar 27, 2024 · 1 comment
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!

Comments

@enkot
Copy link

enkot commented Mar 27, 2024

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 #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 #1260 (comment). This can be solved by adding a number as a suffix to the duplicate name.

Checklist

@enkot enkot added enhancement New feature or request PRs welcome PRs are welcome to solve this issue! openapi-ts Relevant to the openapi-typescript library labels Mar 27, 2024
@enkot enkot changed the title Export component's and path's types Export component's and path's types with friendly names Mar 27, 2024
@enkot enkot mentioned this issue Mar 27, 2024
10 tasks
@drwpow
Copy link
Contributor

drwpow commented Jun 24, 2024

Just for cleanup: this already exists at #1414; closing this to track that.

This solution has been frequently-requested, but is fraught with problems and gotchas (since OpenAPI allows so many characters that are not valid JS identifiers, not to mention conflicts, it makes this approach non-deterministic and full of edge cases that amount to a significant amount of work, to result in what is only a cosmetic difference of what’s available in the library today.

The current status of this is if someone can open a PR that meets full requirements this will be accepted, but so far it’s been too much work to take on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!
Projects
None yet
Development

No branches or pull requests

2 participants