Skip to main content

HttpOperationResponse

Package: @opra/common

HttpOperationResponse represents a single declared response shape on an HttpOperation. It extends HttpMediaType (adding status codes, optional response parameters, and a partial flag) and describes the body type, content type, and status codes the adapter uses to encode the handler's return value.


Inheritance

DocumentElement
└── HttpMediaType
└── HttpOperationResponse

All HttpMediaType properties (type, contentType, multipartFields, size limits, etc.) are inherited. See HttpMediaType.


Additional properties

PropertyTypeDescription
statusCodeHttpStatusRange[]One or more status code ranges this response covers.
parametersHttpParameter[]Response headers or other parameters declared on this response.
partialboolean | 'deep' | undefinedIf set, response fields may be partially present. 'deep' applies recursively.
ownerHttpOperationThe operation this response belongs to.

Methods

findParameter(name, location?)

Finds a response parameter by name and optional location. Name matching is case-insensitive.

response.findParameter('x-request-id', 'header');
findParameter(
paramName: string,
location?: 'query' | 'path' | 'header' | 'cookie'
): HttpParameter | undefined

toJSON(options?)

Returns an OpraSchema.HttpOperationResponse plain object for schema export. Status codes are serialized as a single number when there is only one exact code, or as an array of ranges otherwise.

toJSON(options?: ApiDocument.ExportOptions): OpraSchema.HttpOperationResponse

Accessing responses programmatically

const op = document.httpApi.findOperation('/customers', 'get');

for (const resp of op.responses) {
for (const range of resp.statusCode) {
console.log(range.toString()); // e.g. '200', '400-499'
}
console.log(resp.type?.name); // e.g. 'Customer'
console.log(resp.partial); // true | 'deep' | undefined
}

HttpOperation · HttpMediaType · HttpStatusRange · HttpParameter