Open alessiomatricardi opened 6 months ago
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.
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 #1260export type PersonModel = { name: string; surname: string: }
What do you think about?