我有课堂操作:
public class Operation
{
public string Type { get; set; }
public OperationOptions Options { get; set; }
}
其中的值Type
定义了 的类型Options
。但我必须添加discriminator
到OperationOptions
类型
[KnownType(typeof(EchoOptions))]
[KnownType(typeof(VetDocumentAcceptanceOptions))]
[JsonConverter(typeof(JsonInheritanceConverter), "discriminator")]
public class OperationOptions
{
}
public class EchoOptions : OperationOptions
{
}
public class VetDocumentAcceptanceOptions : OperationOptions
{
}
所以我进入swagger.json:
"OperationOptions": {
"type": "object",
"discriminator": {
"propertyName": "discriminator",
"mapping": {
"EchoOptions": "#/components/schemas/EchoOptions",
"VetDocumentAcceptanceOptions": "#/components/schemas/VetDocumentAcceptanceOptions"
}
}
Discriminator
但我的模型中没有属性OperationOptions
。
有没有办法使用Type
inOperation
作为鉴别器OperationOptions
?