Swashbuckleはポリモーフィズムを正しく実装していないようですが、私はサブクラスについての作者の考え方をパラメータとして理解しています(もし、アクションがAnimalクラスを期待し、dogオブジェクトまたはcatオブジェクト2つの異なるアクションが必要です。)しかし、戻り値の型としてAnimalを返すのは正しいと考えられ、オブジェクトはDogまたはCat型になる可能性があります。
私のAPIを記述し、正しいguidlinesに沿って適切なJSONスキーマを生成するには(自分でディスクリミネータを記述する方法には注意してください。独自のディスクリミネータがあれば、特にその部分を変更する必要があります)次のように文書とスキーマフィルタは:。
{
"definitions": {
"Pet": {
"type": "object",
"discriminator": "petType",
"properties": {
"name": {
"type": "string"
},
"petType": {
"type": "string"
}
},
"required": [
"name",
"petType"
]
},
"Cat": {
"description": "A representation of a cat",
"allOf": [
{
"$ref": "#/definitions/Pet"
},
{
"type": "object",
"properties": {
"huntingSkill": {
"type": "string",
"description": "The measured skill for hunting",
"default": "lazy",
"enum": [
"clueless",
"lazy",
"adventurous",
"aggressive"
]
}
},
"required": [
"huntingSkill"
]
}
]
},
"Dog": {
"description": "A representation of a dog",
"allOf": [
{
"$ref": "#/definitions/Pet"
},
{
"type": "object",
"properties": {
"packSize": {
"type": "integer",
"format": "int32",
"description": "the size of the pack the dog is from",
"default": 0,
"minimum": 0
}
},
"required": [
"packSize"
]
}
]
}
}
}
どれでも運がこれを把握:前のコードはポリモーフィズムのサポートのセクション」のモデルで、hereを指定された実装は何
これは、基本的には次のようなものを作り出します出る? – Craig
まだもう一度それを調べなければならないでしょう。 –