설명
OpenAPI 3.0의 components.links는 응답과 후속 작업의 관계를 재사용 가능한 링크로 정의합니다. 존재하지 않는 링크를 $ref로 참조하면 문서 도구가 그 관계를 해석하지 못할 수 있습니다.
잠재적 영향
- 응답 이후에 호출할 수 있는 작업의 안내가 누락될 수 있습니다.
- 참조 오류로 문서 검증이나 코드 생성이 실패할 수 있습니다.
해결 방법
링크 $ref를 실제 components.links 정의와 일치시키세요. 응답의 links에는 이름을 지정한 항목 안에 참조를 넣고, 링크가 가리키는 작업도 존재하는지 확인하세요. 외부 참조를 사용하면 대상 문서도 함께 검증하세요.
예시
첫 예제의 links.repository는 정의되지 않은 APIWrongRepository를 참조합니다.
변경 전
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/APIWrongRepository"
}
}
}
}
}
}
},
"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"
}
}
}
}
변경 후에는 APIRepository를 참조합니다. 이 예제의 링크는 같은 listVersionsv2 작업을 가리키며, 링크 선언만으로 클라이언트가 해당 작업을 자동 호출하지는 않습니다.