UNPKG

2.58 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3function specPath({ integrationUuid, intentName, requestBody, response, oauth2 }) {
4 return {
5 [`/${integrationUuid}/${intentName}`]: {
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(oauth2)
16 ].filter(e => e !== undefined),
17 summary: intentName,
18 requestBody: { content: { 'application/json': { schema: requestBody } } },
19 responses: {
20 '200': { description: intentName, 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}
38exports.specPath = specPath;
39function oauthParam(oauth2) {
40 if (oauth2) {
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}
51function 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/v2/intents/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}
71exports.topOfSpec = topOfSpec;