cyclosproject / ng-openapi-gen

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

generated models : classes instead of interfaces #161

Closed afarbman closed 3 years ago

afarbman commented 3 years ago

Hi, Is there any flag to make the generated models be classes instead of interfaces? Thx

luisfpg commented 3 years ago

No, they are always interfaces. As interfaces are compile-time only, they don't increase the size of the generated JS bundle.

jmls commented 3 years ago

@luisfpg isn't the size of the bundle the choice of the developer ? I would like to use classes instead of interfaces (perhaps choose per interface / class) as I want to check what sort of parameter is being passed into a method, rather than having to write two methods, one for each parameter type

By default, generate interfaces. However, if a stupid developer wants to use classes instead, why not let them ?

luisfpg commented 3 years ago

You can just customize the object.handlebars template and replace interface by class. However, this will probably stop working in future releases, as it is planned to change from inheritance to composition, so the semantics of OpenAPI are kept (ex: allOf / anyOf with multiple type="object"). This can only be achieved with interfaces, not with classes, as there's no multiple inheritance.