I have a polymorphic model:
public class CreateOrderRequest
{
public List<CreateOrderItem> OrderItems { get; set; }
}
/// <summary>
/// Identifies a new item within an order
/// </summary>
[JsonConverter(typeof(CreateOrderLineJsonConvertor))]
[KnownType("GetKnownTypes")]
public class CreateOrderItem
{
public string OrderContext { get; set; }
public string OrderItemType { get; set; }
public static Type[] GetKnownTypes()
{
return new[]
{
typeof(OrderItemType1), typeof(OrderItemType2)
};
}
}
public class OrderItemType1: CreateOrderItem
{
public string Type1Prop {get;set;}
}
public class OrderItemType2: CreateOrderItem
{
public string Type2Prop {get;set;}
}
Using NSwag (NSwag.AspNetCore) according to the documentation, I expected this to be enough so that documentation indicated / contained the order item types? But no...
Have i completely missed the point of what NSwag requires? I have the OrderItemType property. Do i need to get a discriminator involved? Where is this documented?
TIA
You need
[JsonConverter(typeof(JsonInheritanceConverter), "discriminator")]
on the base class so that the discriminator is added.
See https://github.com/RSuter/NJsonSchema/wiki/Inheritance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With