import { ReferenceObject } from '../origin/reference-object'; import { XResponseObject } from './response-object'; import { HttpStatusCode } from '../origin/http-status-code'; import { SpecExtFieldPattern, SpecificationExtension } from '../origin/specification-extension'; /** * A container for the expected responses of an operation. * The container maps a HTTP response code to the expected response. * * The documentation is not necessarily expected to cover all possible HTTP response codes because * they may not be known in advance. However, documentation is expected to cover a successful * operation response and any known errors. * * The `default` MAY be used as a default response object for all HTTP codes that are not covered * individually by the `Responses Object`. * * The `Responses Object` MUST contain at least one response code, and if only one response code * is provided it SHOULD be the response for a successful operation call. * * ### Responses Object Example * * A 200 response for a successful operation and a default response for others (implying an error): * * - example with JSON * ```json { "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" } } } } } ``` * * - example with YAML * ```yaml '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' ``` * * This object MAY be extended with [Specification Extensions][1]. * * [1]: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#specification-extensions */ export type XResponsesObject = SpecificationExtension & XHttpStatusCodesObject & { /** * The documentation of responses other than the ones declared for specific HTTP response codes. * Use this field to cover undeclared responses. * * [1]: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#reference-object */ default?: XResponseObject | ReferenceObject; }; export type XHttpStatusCodesObject = { [P in HttpStatusCode]?: XResponseObject | ReferenceObject; };