설명
components.links에 정의한 링크가 응답에서 참조되지 않으면 해당 응답과 후속 작업의 관계를 설명하는 데 사용되지 않습니다. 필요한 링크는 응답의 links에 연결하고 불필요한 정의는 정리하세요.
잠재적 영향
- 응답 이후에 호출할 수 있는 작업의 관계가 문서에 제대로 드러나지 않을 수 있습니다.
- 사용하지 않는 링크 정의 때문에 문서와 실제 API 흐름을 비교하기 어려워집니다.
해결 방법
응답의 links에 이름을 지정한 항목을 만들고 링크 컴포넌트의 $ref를 넣으세요. 링크와 대상 작업이 존재하는지 확인하세요. 필요 없는 정의는 다른 문서나 도구의 사용 여부를 확인한 뒤 제거하세요.
예시
첫 예제는 APIRepository를 정의하지만 응답에서 참조하지 않습니다.
변경 전
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": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MyObject"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"links": {
"APIRepository": {
"operationId": "listVersionsv2"
}
}
}
}
변경 후
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": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MyObject"
}
}
}
},
"links": {
"repository": {
"$ref": "#/components/links/APIRepository"
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyObject": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"links": {
"APIRepository": {
"operationId": "listVersionsv2"
}
}
}
}
변경 후에는 응답의 links.repository가 APIRepository를 참조합니다. 예제 링크는 같은 listVersionsv2 작업을 가리키며, 클라이언트가 이를 자동 호출하도록 만드는 설정은 아닙니다.