UNPKG

@opra/common

Version:
48 lines (47 loc) 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpOperationResponse = void 0; const objects_1 = require("@jsopen/objects"); const http_media_type_js_1 = require("./http-media-type.js"); const http_status_range_js_1 = require("./http-status-range.js"); /** * @class HttpOperationResponse */ class HttpOperationResponse extends http_media_type_js_1.HttpMediaType { constructor(owner, init) { super(owner, init); this.parameters = []; this.statusCode = (Array.isArray(init.statusCode) ? init.statusCode : [init.statusCode]).map(x => typeof x === 'object' ? new http_status_range_js_1.HttpStatusRange(x.start, x.end) : new http_status_range_js_1.HttpStatusRange(x)); this.partial = init.partial; } findParameter(paramName, location) { paramName = paramName.toLowerCase(); for (const prm of this.parameters) { if ((!location || location === prm.location) && ((prm.name instanceof RegExp && prm.name.test(paramName)) || prm.name === paramName)) { return prm; } } } toJSON(options) { const statusCode = this.statusCode.map(x => x.toJSON()); const out = (0, objects_1.omitUndefined)({ ...super.toJSON(options), statusCode: statusCode.length === 1 && typeof statusCode[0] === 'number' ? statusCode[0] : statusCode, partial: this.partial, }); if (this.parameters.length) { out.parameters = []; for (const prm of this.parameters) { out.parameters.push(prm.toJSON(options)); } } return out; } } exports.HttpOperationResponse = HttpOperationResponse;