You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, it's only possible to generate all the models, services, etc. into the same folder using the -o/--output <path> option.
This proposal would be to add options to specify different target folders for API clients and interfaces. E.g. I could specify that models should go into libs/api-models/src/generated, while services would go into libs/api-clients/src/generated.
Motivation
The motivation is that it's a good practice to clearly separate interface from implementation (in this context, it means separating classes from non-runtime types). And sometimes the best way to achieve this separation is to represent it in the folder structure.
Real world example
My specific example is a large Nx monorepo, where we split the code into different libraries and enforce boundaries between them with Nx's tags and linting rule. Currently, all the API client code is generated into an api-sdk library, which we've tagged as type:data-access because it contains data layer logic. Other libraries are tagged as type:feature, type:ui or type:util (according to Nx recommendations), and our rules prevent type:ui or type:util libraries importing from type:data-access (to prevent mixing presentation and data layers).
The problem is that, because all the generated API code is in the same library, the same strict rule applies to both models and services. We want to prevent a presentational component from importing an API client. But we don't mind a presentational component importing an API model, because it's only a type definition. Because of the linting rule, we sometimes have to create artificial workarounds like creating duplicate types for the UI layer, which works fine for type-safety (assignments are checked structurally), because it feels like unnecessary boilerplate to maintain.
The text was updated successfully, but these errors were encountered:
Proposal
Currently, it's only possible to generate all the models, services, etc. into the same folder using the
-o/--output <path>
option.This proposal would be to add options to specify different target folders for API clients and interfaces. E.g. I could specify that models should go into
libs/api-models/src/generated
, while services would go intolibs/api-clients/src/generated
.Motivation
The motivation is that it's a good practice to clearly separate interface from implementation (in this context, it means separating classes from non-runtime types). And sometimes the best way to achieve this separation is to represent it in the folder structure.
Real world example
My specific example is a large Nx monorepo, where we split the code into different libraries and enforce boundaries between them with Nx's tags and linting rule. Currently, all the API client code is generated into an
api-sdk
library, which we've tagged astype:data-access
because it contains data layer logic. Other libraries are tagged astype:feature
,type:ui
ortype:util
(according to Nx recommendations), and our rules preventtype:ui
ortype:util
libraries importing fromtype:data-access
(to prevent mixing presentation and data layers).The problem is that, because all the generated API code is in the same library, the same strict rule applies to both models and services. We want to prevent a presentational component from importing an API client. But we don't mind a presentational component importing an API model, because it's only a type definition. Because of the linting rule, we sometimes have to create artificial workarounds like creating duplicate types for the UI layer, which works fine for type-safety (assignments are checked structurally), because it feels like unnecessary boilerplate to maintain.
The text was updated successfully, but these errors were encountered: