Responsesオブジェクト
操作の予期される応答のコンテナー。コンテナーは、HTTP 応答コードを予期される応答にマップします。
HTTP 応答コードは事前にわかっていない可能性があるため、このドキュメントでは、考えられるすべての HTTP 応答コードがカバーされているとは限りません。ただし、ドキュメントには、成功した操作の応答と既知のエラーが含まれることが期待されます。
defaultは、Responses Object で個別にカバーされていないすべての HTTP コードのデフォルトの応答オブジェクトとして使用できます (MAY) 。
Responses Objectには応答コードが少なくとも 1 つ含まれていなければなりません (MUST)。応答コードが 1 つだけ提供される場合、それは成功したオペレーション呼び出しに対する応答である必要があります (SHOULD) 。
固定フィールド
| フィールド名 | タイプ | 説明 |
|---|---|---|
| デフォルト | 応答オブジェクト| 参照オブジェクト | 特定の HTTP 応答コードに対して宣言された応答以外の応答のドキュメント。このフィールドは、宣言されていない応答をカバーするために使用します。 |
パターン化されたフィールド
| フィールドパターン | タイプ | 説明 |
|---|---|---|
| HTTPステータスコード | 応答オブジェクト| 参照オブジェクト | 任意のHTTP ステータス コードをプロパティ名として使用できますが、その HTTP ステータス コードに対して予期される応答を記述するために使用できるプロパティはコードごとに 1 つだけです。JSON と YAML 間の互換性を確保するために、このフィールドは引用符で囲む必要があります (たとえば、「200」)。応答コードの範囲を定義するには、このフィールドに大文字のワイルドカード文字Xを含めることができます (MAY) 。たとえば、2XX は[200-299]の間にあるすべての応答コードを表します。次の範囲定義のみが許可されます: 1XX、2XX、3XX、4XXおよび5XX。応答が明示的なコードを使用して定義されている場合、明示的なコード定義は、そのコードの範囲定義よりも優先されます。 |
このオブジェクトは、仕様拡張機能を使用して拡張できます。
Responsesオブジェクトの例
成功した操作の場合は 200 応答、その他の場合はデフォルトの応答 (エラーを意味します):
{ "200": { "description": "a pet to be returned", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Pet" } } } }, "default": { "description": "Unexpected error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorModel" } } } }}
'200': description: a pet to be returned content: application/json: schema: $ref: '#/components/schemas/Pet'default: description: Unexpected error content: application/json: schema: $ref: '#/components/schemas/ErrorModel
応答オブジェクト
API 操作からの単一の応答 (設計時、 links応答に基づく静的な操作を含む) を記述します。
固定フィールド
| フィールド名 | タイプ | 説明 |
|---|---|---|
| 説明 | string | 必須。応答の説明。CommonMark 構文はリッチ テキスト表現に使用できます (MAY)。 |
| ヘッダー | Map[ string,ヘッダー オブジェクト | 参照オブジェクト] | ヘッダー名をその定義にマップします。RFC7230 では、ヘッダー名は大文字と小文字を区別しないと述べています。応答ヘッダーが"Content-Type" という名前で定義されている場合、それは無視されます(SHALL)。 |
| コンテンツ | Map[ string,メディア タイプ オブジェクト] | 潜在的な応答ペイロードの説明を含むマップ。キーはメディア タイプまたはメディア タイプの範囲であり、値はそれを説明します。複数のキーに一致する応答の場合、最も具体的なキーのみが適用されます。例: text/plain は text/* をオーバーライドします |
| リンク | Map[ string,リンク オブジェクト| 参照オブジェクト] | 応答からたどることができる操作リンクのマップ。マップのキーは、コンポーネント オブジェクトの名前の命名制約に従っている、リンクの短縮名です。 |
このオブジェクトは、仕様拡張機能を使用して拡張できます。
応答オブジェクトの例
複合型の配列の応答:
{
"description": "A complex object array response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/VeryComplexType"
}
}
}
}
}
description: A complex object array response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/VeryComplexType'
文字列型の応答:
{
"description": "A simple string response",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
}
description: A simple string response
representations:
text/plain:
schema:
type: string
ヘッダー付きのプレーンテキスト応答:
{
"description": "A simple string response",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
},
"headers": {
"X-Rate-Limit-Limit": {
"description": "The number of allowed requests in the current period",
"schema": {
"type": "integer"
}
},
"X-Rate-Limit-Remaining": {
"description": "The number of remaining requests in the current period",
"schema": {
"type": "integer"
}
},
"X-Rate-Limit-Reset": {
"description": "The number of seconds left in the current period",
"schema": {
"type": "integer"
}
}
}
}
description: A simple string response
content:
text/plain:
schema:
type: string
example: 'whoa!'
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
schema:
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
schema:
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
schema:
type: integer
戻り値のない応答:
{
"description": "object created"
}
description: object created