説明
required は必須フィールドの名前を、properties は値の制約を定めます。必須フィールドが別の allOf 分岐などに定義されている場合もあります。
想定される影響
値の制約がないと想定外の型も通ります。追加フィールドを禁止したスキーマが必須フィールドまで拒否すると、どのオブジェクトも通りません。
対処方法
すべての分岐と additionalProperties を確認します。呼び出し元が指定すべきフィールドは required に残し、仕様に応じて値の制約を定義します。
例
info と paths を省略したスキーマの例です。どちらの例でも name は必須です。
変更前
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"Example": {
"type": "object",
"required": [
"name"
],
"properties": {
"age": {
"type": "integer"
}
}
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"Example": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
}
}
}
}
}
}
type: string を追加すると、以前は通った数値などの name が拒否されます。