Skip to content

Only generate models and export at root level #1506

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

Closed
alessiomatricardi opened this issue Jan 18, 2024 · 3 comments
Closed

Only generate models and export at root level #1506

alessiomatricardi opened this issue Jan 18, 2024 · 3 comments
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue! stale

Comments

@alessiomatricardi
Copy link

Description

As for now, this tool "translate" the OpenAPI specification and export everything inside a single file.
If the YAML/JSON specification is big enough (eg. we have a microservice which its JSON spec is ~ 2MB) and you need only to obtain the models from, the information overflow is not trascurable.

Proposal

My proposal is to define an option (eg --only-schemas) which export only the component schemas and export them at root level as done in #1260
export type PersonModel = { name: string; surname: string: }

What do you think about?

@alessiomatricardi alessiomatricardi added enhancement New feature or request PRs welcome PRs are welcome to solve this issue! openapi-ts Relevant to the openapi-typescript library labels Jan 18, 2024
@drwpow
Copy link
Contributor

drwpow commented Jan 19, 2024

Partial generation is possible, but tricky.

As I’ve commented in #1260, the proposal to have top-level “friendly names” doesn’t work for many schemas, because you’re allowed to use characters in component names that aren’t JS-safe. So we’d have to rename them somehow, while preventing conflicts.

Further, even having just --only-schemas is tricky, because we can’t just generate #/components/schemas; you’re allowed to use $defs (from JSONSchema), as well as refer to any other object in the document (even #/components/parameters and #/components/requestBodies). So it would actually be trickier having to trace everything, and make sure everything referenced gets loaded properly.

Trying to “tree-shake” an OpenAPI schema ultimately becomes a lot of brittle work for not much benefit. Our tests generate schemas that are several MBs in size in milliseconds, and consuming them in TypeScript is trivial on most machines. Further, you’re not meant to read the output directly; it’s supposed to happen via Intellisense and from reading your OpenAPI docs.


So all that said, I don’t think this is a feature I’d like to pursue. But for related things, such as improving Intellisence (#1462), or if there’s a performance issue, those are both great issues to tackle.

Copy link
Contributor

github-actions bot commented Aug 6, 2024

This issue is stale because it has been open for 90 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

@github-actions github-actions bot added the stale label Aug 6, 2024
Copy link
Contributor

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2024
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! stale
Projects
None yet
Development

No branches or pull requests

2 participants