스키마 조합의 직접 자기 참조 점검

같은 데이터에 반복 적용되는 직접 자기 참조를 검토하고 필요한 재귀 구조와 구분하세요.

설명

allOf에서 같은 스키마를 다시 참조하면 도구가 같은 값을 반복해서 처리할 수 있습니다.

잠재적 영향

스키마 검증이 느려지거나 문서·코드 생성이 실패할 수 있습니다.

해결 방법

직접 자기 참조를 제거하거나 공통 필드를 별도 스키마로 분리하세요. 트리의 자식 노드처럼 재귀 구조가 필요하다면 사용 중인 도구가 이를 처리하고 모델이 의도한 데이터를 허용하는지 확인하세요.

예시

첫 번째 예시의 ExtendedErrorModel은 allOf 안에서 자기 자신을 참조합니다.

변경 전

json
{
  "openapi": "3.0.0",
  "components": {
    "schemas": {
      "ExtendedErrorModel": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ExtendedErrorModel"
          },
          {
            "type": "object",
            "properties": {
              "rootCause": {
                "type": "string"
              }
            }
          }
        ]
      }
    }
  }
}

변경 후

json
{
  "openapi": "3.0.0",
  "components": {
    "schemas": {
      "ErrorModel": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          }
        }
      },
      "ExtendedErrorModel": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ErrorModel"
          },
          {
            "type": "object",
            "properties": {
              "rootCause": {
                "type": "string"
              }
            }
          }
        ]
      }
    }
  }
}

수정한 예시는 message를 정의한 ErrorModel을 참조하고 확장 모델에 rootCause를 유지합니다. 두 필드가 실제 오류 응답에 맞는지 확인하세요.

참조