beezler
beezler

Reputation: 646

SwaggerUI and Swashbuckle recognize polymorphic / derived types

I am creating a Rest API using C# and WebAPI. I am using Swashbuckle to add a Swagger UI to the API and AutoRest to generate a client. This all works fine, until I introduce polymorphism / inheritance to my model. Swagger UI is only creating definitions for the base classes, which results in my AutoRest client only having base types in the interface.

Are there attributes needed on my model to allow Swashbuckle / Swagger to recognize the derived types?

Upvotes: 4

Views: 3880

Answers (1)

Benjamin Soulier
Benjamin Soulier

Reputation: 2263

Swagger / OpenAPI specification does support polymorphism.

SwashBuckle, which generates a Swagger document dynamically, as stated on Swashbuckle versions feature comparision, does not support polymorphism from version 5.0.

The only way you could handle polymorphism here would be to build your own code once Swagger model has been completely generated, using the IDocumentFilter interface to modify generated definitions.

Upvotes: 7

Related Questions