UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const util_1 = require("../util");
4const body_parser_1 = require("./body-parser");
5const headers_parser_1 = require("./headers-parser");
6const parser_helpers_1 = require("./parser-helpers");
7function parseDefaultResponse(method, typeTable, lociTable) {
8 var _a;
9 method.getDecoratorOrThrow("defaultResponse");
10 const headersParam = parser_helpers_1.getParamWithDecorator(method, "headers");
11 const bodyParam = parser_helpers_1.getParamWithDecorator(method, "body");
12 const headers = [];
13 if (headersParam) {
14 const headersResult = headers_parser_1.parseHeaders(headersParam, typeTable, lociTable);
15 if (headersResult.isErr())
16 return headersResult;
17 headers.push(...headersResult.unwrap());
18 }
19 let body;
20 if (bodyParam) {
21 const bodyResult = body_parser_1.parseBody(bodyParam, typeTable, lociTable);
22 if (bodyResult.isErr())
23 return bodyResult;
24 body = bodyResult.unwrap();
25 }
26 return util_1.ok({
27 headers,
28 description: (_a = parser_helpers_1.getJsDoc(method)) === null || _a === void 0 ? void 0 : _a.getDescription().trim(),
29 body
30 });
31}
32exports.parseDefaultResponse = parseDefaultResponse;