cyclosproject / ng-openapi-gen

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

Feature/allow interface inheritance as an option #211

Closed ophirKatz closed 2 years ago

ophirKatz commented 2 years ago

Optionally generate typescript base type inheritance. This solves issue #206, where Swashbuckle api generated code for polymorphic types does not use inheritance. This "issue" was introduced by commit 745615e91344e13180387158fa2880b9249d453b, which bumped version from 0.17.3 to 0.18.0. Therefore, some similar features are optionally reintroduced in this PR.

The change allows adding an option in ng-openapi-gen.json which turns polymorphic interface inheritance: "useInterfaceInheritance": true (defaults to false).

A note about testing - the typescript-parser, sadly does not expose a way to check an interface declaration's super types, so the tests added don't bring too much value, but I did test it locally with my own code example. I also made sure setting the flag to true does not break other logic.

luisfpg commented 2 years ago

Hi @ophirKatz , thanks for the PR. However, the original issue was caused by a bug, not by a fundamental problem of generating type type intersections instead of interface inheritance, which are both strictly equivalent. I've fixed the original issue, and will, therefore, close this PR, because we don't want to maintain both styles of generation (inheritance vs intersection).