UNPKG

2.26 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3function specPath({ buid, functionName, requestBody, response, oauth }) {
4 return {
5 [`/${buid}/${functionName}`]: {
6 post: {
7 parameters: [oauthParam(oauth)].filter(e => e !== undefined),
8 summary: functionName,
9 requestBody: { content: { 'application/json': { schema: requestBody } } },
10 responses: {
11 '200': { description: functionName, content: { 'application/json': { schema: response } } },
12 '401': {
13 description: 'Access forbidden',
14 content: {
15 'application/json': { schema: { type: 'object', properties: { error: { type: 'string' } } } }
16 }
17 },
18 '403': {
19 description: 'Unauthorized',
20 content: {
21 'application/json': { schema: { type: 'object', properties: { error: { type: 'string' } } } }
22 }
23 }
24 },
25 security: [
26 {
27 'API Key': []
28 }
29 ]
30 }
31 }
32 };
33}
34exports.specPath = specPath;
35function oauthParam(oauth) {
36 if (oauth) {
37 return {
38 name: 'authId',
39 schema: { type: 'string', format: 'uuid' },
40 in: 'query',
41 description: 'User Identifier',
42 required: true
43 };
44 }
45 return;
46}
47function topOfSpec(integrationName) {
48 return {
49 openapi: '3.0.0',
50 info: {
51 title: integrationName
52 },
53 servers: [{ url: 'https://int.bearer.sh/api/v4/functions/backend/' }],
54 tags: [],
55 components: {
56 securitySchemes: {
57 'API Key': {
58 type: 'apiKey',
59 in: 'header',
60 name: 'Authorization',
61 description: 'You can find your **Bearer API Key** [here](https://app.bearer.sh/keys).'
62 }
63 }
64 }
65 };
66}
67exports.topOfSpec = topOfSpec;