설명
components.links의 링크는 응답에서 참조해야 그 응답 이후 호출할 수 있는 작업을 설명합니다.
잠재적 영향
참조가 빠지면 API 사용자가 문서에서 다음 작업을 찾기 어렵습니다.
해결 방법
응답의 links에 이름을 지정한 항목을 만들고 그 안에 $ref를 두세요. 링크와 대상 작업이 있는지 확인하세요. 미사용 정의는 다른 문서나 도구에서도 쓰지 않을 때만 삭제하세요.
예시
변경 전
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"
}
}
}
}
200 응답의 links.repository가 APIRepository를 참조합니다. 이 예시의 링크는 같은 listVersionsv2 작업을 가리키며, 호출 여부는 클라이언트가 결정합니다.