Replies: 1 comment
-
I realised this has been supported for a long time after the merge of this PR #1876 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone,
Currently we generate TypeScript definitions from OpenAPI specs. These definitions include deeply nested paths like
components["schemas"]["Example"]
. This depends for sure on the project complexity. Using theExample
type within the code is really unhandy, except to manually destruct this into a static type again in a separate file. This makes the code quite unreadable and IDE autocompletion and type-checking become less intuitive or the developer has a lot of manually effort maintaining the types.The following two options I frequently see in our projects:
What I currently do, instead of the two above options, I automatically extract the nested type paths like components["schemas"]["Example"] into standalone, static type definitions (e.g.,
export interface Example { ... }
), providing a more concise, flat hierarchy of types for easier usage.I would personally add an option:
--flat-schema
, including the--enum
option already. This would flatten the components["schemas"] Dtos and generate enums from type unions.Currently I basically to this by traversing through the AST and extracting the types and interfaces from the generated types file:
At the end I have two files, one is the generated
api.d.ts
and second thetypes.d.ts
. The developer would then reference in the code only the interfaces, types and enums from the types.d.ts. From e.g. this:to this:
I would like to suggest adding such functionality. If needed I can share the function. Any thoughts on this?
Best regards,
reQ
Beta Was this translation helpful? Give feedback.
All reactions