Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 736
beezler Avatar asked Mar 11 '23 03:03

beezler


1 Answers

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.

like image 147
Benjamin Soulier Avatar answered May 01 '23 08:05

Benjamin Soulier