1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ResponseObjectMapper = void 0;
|
4 | const lodash_1 = require("lodash");
|
5 | const utils_1 = require("../utils");
|
6 | const mimetype_content_wrapper_1 = require("./mimetype-content-wrapper");
|
7 | class ResponseObjectMapper {
|
8 | constructor() {
|
9 | this.mimetypeContentWrapper = new mimetype_content_wrapper_1.MimetypeContentWrapper();
|
10 | }
|
11 | toArrayRefObject(response, name, produces) {
|
12 | return Object.assign(Object.assign({}, response), this.mimetypeContentWrapper.wrap(produces, {
|
13 | schema: {
|
14 | type: 'array',
|
15 | items: {
|
16 | $ref: utils_1.getSchemaPath(name)
|
17 | }
|
18 | }
|
19 | }));
|
20 | }
|
21 | toRefObject(response, name, produces) {
|
22 | return Object.assign(Object.assign({}, response), this.mimetypeContentWrapper.wrap(produces, {
|
23 | schema: {
|
24 | $ref: utils_1.getSchemaPath(name)
|
25 | }
|
26 | }));
|
27 | }
|
28 | wrapSchemaWithContent(response, produces) {
|
29 | if (!response.schema) {
|
30 | return response;
|
31 | }
|
32 | const content = this.mimetypeContentWrapper.wrap(produces, {
|
33 | schema: response.schema
|
34 | });
|
35 | return Object.assign(Object.assign({}, lodash_1.omit(response, 'schema')), content);
|
36 | }
|
37 | }
|
38 | exports.ResponseObjectMapper = ResponseObjectMapper;
|