설명
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의 타입은 정하지 않았습니다. 변경 후에는 문자열로 정의합니다.