응답 헤더 정의와 HTTP 의미 점검

응답 형식과 실제 응답 헤더를 구분해 문서화하세요.

설명

응답 미디어 타입은 OpenAPI 3.0의 content나 Swagger 2.0의 produces에 지정하세요. OpenAPI 3.0은 응답 headers에 따로 적은 Content-Type을 무시합니다.

잠재적 영향

문서의 형식이 실제 응답과 다르면 클라이언트가 본문을 해석하지 못할 수 있습니다.

해결 방법

서버가 실제로 보내는 헤더의 이름과 값 형식을 확인하세요. 응답의 Accept는 이후 요청에서 받을 수 있는 형식을 알릴 수 있고, Authorization은 보통 요청 자격 증명을 담습니다.

예시

두 예시 모두 400 응답 본문을 application/json으로 정의합니다.

변경 전

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "500": {
            "description": "500 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "400 response",
            "headers": {
              "Content-Type": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

변경 후

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "500": {
            "description": "500 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "400 response",
            "headers": {
              "Pet": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

두 번째 예시의 Pet은 별도의 문자열 헤더입니다. 서버가 이 메타데이터를 실제로 보낼 때만 정의하세요.

참조