1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | function specPath({ integrationUuid, functionName, requestBody, response, oauth }) {
|
4 | return {
|
5 | [`/${integrationUuid}/${functionName}`]: {
|
6 | post: {
|
7 | parameters: [
|
8 | {
|
9 | in: 'header',
|
10 | name: 'authorization',
|
11 | schema: { type: 'string' },
|
12 | description: 'API Key',
|
13 | required: true
|
14 | },
|
15 | oauthParam(oauth)
|
16 | ].filter(e => e !== undefined),
|
17 | summary: functionName,
|
18 | requestBody: { content: { 'application/json': { schema: requestBody } } },
|
19 | responses: {
|
20 | '200': { description: functionName, content: { 'application/json': { schema: response } } },
|
21 | '401': {
|
22 | description: 'Access forbidden',
|
23 | content: {
|
24 | 'application/json': { schema: { type: 'object', properties: { error: { type: 'string' } } } }
|
25 | }
|
26 | },
|
27 | '403': {
|
28 | description: 'Unauthorized',
|
29 | content: {
|
30 | 'application/json': { schema: { type: 'object', properties: { error: { type: 'string' } } } }
|
31 | }
|
32 | }
|
33 | }
|
34 | }
|
35 | }
|
36 | };
|
37 | }
|
38 | exports.specPath = specPath;
|
39 | function oauthParam(oauth) {
|
40 | if (oauth) {
|
41 | return {
|
42 | name: 'authId',
|
43 | schema: { type: 'string', format: 'uuid' },
|
44 | in: 'query',
|
45 | description: 'User Identifier',
|
46 | required: true
|
47 | };
|
48 | }
|
49 | return;
|
50 | }
|
51 | function topOfSpec(integrationName) {
|
52 | return {
|
53 | openapi: '3.0.0',
|
54 | info: {
|
55 | description: `openapi definition file for ${integrationName}`,
|
56 | version: '0.0.1',
|
57 | title: integrationName,
|
58 | contact: { email: 'bearer@bearer.sh' },
|
59 | license: { name: 'MIT' }
|
60 | },
|
61 | servers: [{ url: 'https://int.bearer.sh/api/v3/functions/backend/' }],
|
62 | tags: [
|
63 | {
|
64 | name: 'integration',
|
65 | description: `List of endpoints providing backend to backend integration with ${integrationName}`,
|
66 | externalDocs: { description: 'Find out more', url: 'https://www.bearer.sh' }
|
67 | }
|
68 | ]
|
69 | };
|
70 | }
|
71 | exports.topOfSpec = topOfSpec;
|