cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Generate model for typed forms #256

Closed aceleghin closed 1 year ago

aceleghin commented 1 year ago

I have just discovered the typed forms in Angular (type-forms) and I am asking if it is possible to generate an interface like:

interface LoginForm { email: FormControl<string>; password?: FormControl<string>; }

So in that case I can just use the generated interface to build the Form, and I can skip to create the interface on my own.

luisfpg commented 1 year ago

I think that this is out of scope for the generator. It is a common case to have forms not 100% the same as the models, so the generated code would not always be right. Whenever the application grows, you'll find more and more cases which you need a slightly different form model than your model. An example: In our own API (https://demo.cyclos.org/api) all date ranges are passed in as array, whereas in our frontend (https://github.com/cyclosproject/cyclos4-ui) ranges are flattened in the form with 2 different properties. There are other examples too in our codebase.