RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.69k stars 1.24k forks source link

Generated DTOs shouldn't hide base class properties #1568

Open Vivelin opened 6 years ago

Vivelin commented 6 years ago

I have a Swagger document that contains schemas that use allOf to include the base class schema (I used Swashbuckle.AspNetCore.Polymorphism):

  "allOf": [
    {
      "$ref": "#/definitions/<BaseClass>"
    },
    {
      "type": "object",
      "properties": {

While I cannot get a proper example right now, the base class properties are included in both the base class schema and the actual schema.

While Swagger UI handles duplicate properties just fine, NSwag does not. Using Poco for generated DTOs, this results in properties that hide the inherited properties, which causes the base class properties to be null. I tried using Record instead, but the generated constructor contains duplicate parameters, causing compilation errors.

I resolved my issue by filtering out the duplicate properties while generating the Swagger document, but I think NSwag could improve on this area as well. I'm not too familiar with the intricacies of Swagger so I don't know what would be most appropriate, but I suggest simply skipping properties declared in the base class.

RicoSuter commented 6 years ago

I think/hope this is fixed with this PR: https://github.com/RSuter/NJsonSchema/pull/733

RicoSuter commented 5 years ago

Update: Ready for retest in next nswag release (with updated NJS)