How do I include subclasses in Swagger API documentation/ OpenAPI specification using Swashbuckle?

前端 未结 5 751
情书的邮戳
情书的邮戳 2020-11-30 00:44

I have an Asp.Net web API 5.2 project in c# and generating documentation with Swashbuckle.

I have model that contain inheritance something like having an Animal prop

5条回答
  •  甜味超标
    2020-11-30 01:05

    As of this merge into Swashbuckle.AspNetCore, you can get basic support for polymorphic schemas by using:

    services.AddSwaggerGen(c =>
    {
        c.GeneratePolymorphicSchemas();
    }
    

    You can also express your derived types via attributes present in the Annotations library:

    [SwaggerSubTypes(typeof(SubClass), Discriminator = "value")]
    

    This article goes into further detail as to how you can deserialize derived types using Newtonsoft.

提交回复
热议问题