aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sra-spec/src/responses.ts
blob: cd7352058a0125b6d54c2880e178419874997a58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { ResponsesObject } from '@loopback/openapi-v3-types';

import { errorResponses } from './errors';
import { headers } from './headers';

export const generateResponses = (schemaName?: string, example?: any, description: string = 'OK'): ResponsesObject => {
    const responses = {
        '200': {
            headers,
            description,
            content: {},
        },
        ...errorResponses,
    };
    if (schemaName) {
        responses['200'].content = {
            'application/json': {
                schema: { $ref: `#/components/schemas/${schemaName}` },
                example,
            },
        };
    }
    return responses;
};