설명
components.schemas에 모델을 정의하는 것만으로 요청이나 응답의 데이터 형식이 정해지지는 않습니다. 필요한 스키마를 사용하는 위치와 연결하고, 불필요한 모델을 정리하세요.
잠재적 영향
사용하지 않는 모델이 문서나 생성 코드에 남아 실제 데이터 구조를 파악하기 어려워질 수 있습니다.
해결 방법
요청, 응답, 매개변수와 다른 모델의 사용 여부를 확인하세요. 간접 사용이나 외부 문서의 참조도 확인한 뒤 불필요한 스키마만 제거하세요.
예시
다음 예시는 응답 본문에서 사용하는 MyObject를 유지하고 미사용 MyObject2를 제거합니다.
변경 전
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"MyObject2": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
}
변경 후
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
}