설명
고정된 객체 필드는 properties에 이름과 타입을 정의하고, 반드시 필요한 필드는 required에 넣으세요.
잠재적 영향
필드를 정의해도 목록 밖의 필드는 기본적으로 허용됩니다.
해결 방법
추가 필드까지 거부해야 하면 additionalProperties: false를 설정하세요. 키가 바뀌는 맵은 additionalProperties에 값의 스키마를 지정하세요. 필수 필드를 뺀 객체와 추가 필드가 있는 객체로 각각 검증하세요.
예시
두 예시 모두 petType이 필수입니다. 두 번째는 code, message, petType의 타입을 지정하고 그 밖의 필드를 거부합니다.
변경 전
json
{
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"required": [
"petType"
]
}
}
}
}
변경 후
json
{
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"additionalProperties": false,
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"petType": {
"type": "string"
}
},
"required": [
"petType"
]
}
}
}
}