説明
required にはオブジェクトに必須のプロパティを列挙します。型は properties のほか、参照先や合成したスキーマでも定義できます。
想定される影響
型が不明だと呼び出し側が送る値を選びにくくなります。別の制約でその必須プロパティを禁止すると、両方の条件を満たすオブジェクトは存在しません。
対処方法
適用される定義と additionalProperties を確認してください。必須の名前は required に残し、不足している型と説明を追加します。
例
この OpenAPI 3.0 の抜粋では info と paths を省略しています。
変更前
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "integer"
}
},
"required": [
"code",
"message"
]
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"message": {
"type": "string"
}
},
"required": [
"code",
"message"
]
}
}
}
}
どちらも code と message が必須です。変更前は追加プロパティを許可し、message の型を限定していません。変更後は文字列として定義しています。