vls-openapi-generator 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,44 +35,26 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.generateOpenAPI = void 0;
37
37
  const zod_openapi_1 = require("@anatine/zod-openapi");
38
- const child_process_1 = require("child_process");
39
- const fs_1 = require("fs");
38
+ const node_child_process_1 = require("node:child_process");
39
+ const node_fs_1 = require("node:fs");
40
40
  require("module-alias/register.js");
41
- const path = __importStar(require("path"));
42
- const util_1 = require("util");
41
+ const path = __importStar(require("node:path"));
42
+ const node_util_1 = require("node:util");
43
43
  const zod_1 = require("zod");
44
- const client_cloudformation_1 = require("@aws-sdk/client-cloudformation");
45
44
  const OPENAPI_FILE = path.join(process.cwd(), 'openapi.json');
46
45
  const HANDLERS_DIR = path.join(process.cwd(), 'dist', 'src', 'handlers');
47
46
  const SCHEMAS_DIR = path.join(process.cwd(), 'dist', 'src', 'schemas');
48
47
  const OUTPUT_FILE = path.join(process.cwd(), 'openapi.json');
49
48
  const generateOpenAPI = async () => {
50
- await (0, util_1.promisify)(child_process_1.exec)('rm -rf ./dist');
51
- await (0, util_1.promisify)(child_process_1.exec)('npx tsc');
52
- const handlerFiles = await fs_1.promises.readdir(HANDLERS_DIR).catch(() => []);
49
+ await (0, node_util_1.promisify)(node_child_process_1.exec)('rm -rf ./dist');
50
+ await (0, node_util_1.promisify)(node_child_process_1.exec)('npx tsc');
51
+ const handlerFiles = await node_fs_1.promises.readdir(HANDLERS_DIR).catch(() => []);
53
52
  if (handlerFiles.length === 0) {
54
53
  console.log('No handler found in handlers folder.');
55
54
  return;
56
55
  }
57
56
  console.info('Generating Open API documentation...');
58
- const args = process.argv;
59
- const params = {};
60
- for (let i = 2; i < args.length;) {
61
- const key = args[i].replace('--', '');
62
- params[key] = args[i + 1];
63
- if (!params[key]) {
64
- i++;
65
- continue;
66
- }
67
- if (params[key].startsWith('--')) {
68
- i++;
69
- delete params[key];
70
- }
71
- else {
72
- i += 2;
73
- }
74
- }
75
- const existingOpenAPIFile = JSON.parse(await fs_1.promises.readFile(OPENAPI_FILE, 'utf-8'));
57
+ const existingOpenAPIFile = JSON.parse(await node_fs_1.promises.readFile(OPENAPI_FILE, 'utf-8'));
76
58
  existingOpenAPIFile.paths = {};
77
59
  for (const handler of handlerFiles) {
78
60
  const fileName = path.parse(handler).name;
@@ -94,7 +76,7 @@ const generateOpenAPI = async () => {
94
76
  if (queryParametersSchema) {
95
77
  for (const key in queryParametersComponent.properties) {
96
78
  const properties = queryParametersComponent?.properties;
97
- if (!properties || !properties[key]) {
79
+ if (!properties?.[key]) {
98
80
  continue;
99
81
  }
100
82
  queryParameters.push({
@@ -131,65 +113,10 @@ const generateOpenAPI = async () => {
131
113
  }
132
114
  };
133
115
  }
134
- const partnerName = params['partner-name'];
135
- if (partnerName) {
136
- const developmentURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('development'));
137
- const fetchedDevelopmentURL = await getStackURL(partnerName, 'development');
138
- if (fetchedDevelopmentURL) {
139
- existingOpenAPIFile.servers[developmentURLIndex].url =
140
- fetchedDevelopmentURL[fetchedDevelopmentURL.length - 1] === '/'
141
- ? fetchedDevelopmentURL.slice(0, -1)
142
- : fetchedDevelopmentURL;
143
- }
144
- else {
145
- existingOpenAPIFile.servers[developmentURLIndex].url = 'development url';
146
- }
147
- const productionURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('production'));
148
- const fetchedProductionURL = await getStackURL(partnerName, 'production');
149
- if (fetchedProductionURL) {
150
- existingOpenAPIFile.servers[productionURLIndex].url =
151
- fetchedProductionURL[fetchedProductionURL.length - 1] === '/'
152
- ? fetchedProductionURL.slice(0, -1)
153
- : fetchedProductionURL;
154
- }
155
- else {
156
- existingOpenAPIFile.servers[productionURLIndex].url = 'production url';
157
- }
158
- }
159
- await fs_1.promises.writeFile(OUTPUT_FILE, JSON.stringify(existingOpenAPIFile, undefined, 4));
116
+ await node_fs_1.promises.writeFile(OUTPUT_FILE, JSON.stringify(existingOpenAPIFile, undefined, 4));
160
117
  console.info('Open API documentation generated successfully');
161
118
  };
162
119
  exports.generateOpenAPI = generateOpenAPI;
163
- async function getStackURL(partnerName, environment) {
164
- const stackName = `${partnerName}-${environment}`;
165
- const cloudFormationClient = new client_cloudformation_1.CloudFormationClient();
166
- const describeStacksCommand = new client_cloudformation_1.DescribeStacksCommand({
167
- StackName: stackName
168
- });
169
- const result = await cloudFormationClient.send(describeStacksCommand).catch((err) => {
170
- if (err instanceof client_cloudformation_1.CloudFormationServiceException &&
171
- err.message.includes(`Stack with id ${stackName} does not exist`)) {
172
- return;
173
- }
174
- throw err;
175
- });
176
- if (!result || !result.Stacks) {
177
- console.warn(`Base URL was not found with the given environment. Environment will not be updated. Given environment: ${environment}`);
178
- return;
179
- }
180
- for (const cloudFormationStack of result.Stacks) {
181
- if (!cloudFormationStack.Outputs) {
182
- console.warn(`Output was not found within the given stack. Environment will not be updated. Given environment: ${environment}`);
183
- return;
184
- }
185
- for (const output of cloudFormationStack.Outputs) {
186
- if (output.OutputKey !== 'WebEndpoint' || !output.OutputValue) {
187
- continue;
188
- }
189
- return output.OutputValue;
190
- }
191
- }
192
- }
193
120
  function generateEventResponseComponent(responseType = 'mindbehind-chat-bot-response', eventResponseParametersSchema, eventResponseModulesSchema) {
194
121
  if (responseType === 'mindbehind-chat-bot-response') {
195
122
  return (0, zod_openapi_1.generateSchema)(zod_1.z.object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vls-openapi-generator",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -16,7 +16,6 @@
16
16
  "description": "VLS Open API Generator",
17
17
  "dependencies": {
18
18
  "@anatine/zod-openapi": "^2.2.7",
19
- "@aws-sdk/client-cloudformation": "^3.817.0",
20
19
  "axios": "^1.12.0",
21
20
  "module-alias": "^2.2.3",
22
21
  "openapi-to-postmanv2": "^4.25.0"
@@ -1,17 +1,12 @@
1
1
  import { extendApi, generateSchema, OpenApiZodAny } from '@anatine/zod-openapi';
2
- import { exec } from 'child_process';
3
- import { promises as fs } from 'fs';
2
+ import { exec } from 'node:child_process';
3
+ import { promises as fs } from 'node:fs';
4
4
  import 'module-alias/register.js';
5
- import * as path from 'path';
6
- import { promisify } from 'util';
5
+ import * as path from 'node:path';
6
+ import { promisify } from 'node:util';
7
7
  import { z } from 'zod';
8
8
  import { LambdaConfig, OpenAPIConfig } from './lambda-type';
9
9
  import { OpenAPI } from './openapi-type';
10
- import {
11
- CloudFormationClient,
12
- CloudFormationServiceException,
13
- DescribeStacksCommand
14
- } from '@aws-sdk/client-cloudformation';
15
10
 
16
11
  const OPENAPI_FILE = path.join(process.cwd(), 'openapi.json');
17
12
  const HANDLERS_DIR = path.join(process.cwd(), 'dist', 'src', 'handlers');
@@ -32,26 +27,6 @@ export const generateOpenAPI = async (): Promise<void> => {
32
27
 
33
28
  console.info('Generating Open API documentation...');
34
29
 
35
- const args = process.argv;
36
- const params: Record<string, string> = {};
37
-
38
- for (let i = 2; i < args.length; ) {
39
- const key = args[i].replace('--', '');
40
- params[key] = args[i + 1];
41
-
42
- if (!params[key]) {
43
- i++;
44
- continue;
45
- }
46
-
47
- if (params[key].startsWith('--')) {
48
- i++;
49
- delete params[key];
50
- } else {
51
- i += 2;
52
- }
53
- }
54
-
55
30
  const existingOpenAPIFile = JSON.parse(await fs.readFile(OPENAPI_FILE, 'utf-8')) as OpenAPI;
56
31
 
57
32
  existingOpenAPIFile.paths = {};
@@ -103,14 +78,14 @@ export const generateOpenAPI = async (): Promise<void> => {
103
78
  for (const key in queryParametersComponent.properties) {
104
79
  const properties = queryParametersComponent?.properties;
105
80
 
106
- if (!properties || !properties[key]) {
81
+ if (!properties?.[key]) {
107
82
  continue;
108
83
  }
109
84
 
110
85
  queryParameters.push({
111
86
  name: key,
112
87
  in: 'query',
113
- schema: properties[key] as ReturnType<typeof generateSchema>
88
+ schema: properties[key]
114
89
  } as const);
115
90
  }
116
91
  }
@@ -143,86 +118,11 @@ export const generateOpenAPI = async (): Promise<void> => {
143
118
  };
144
119
  }
145
120
 
146
- const partnerName = params['partner-name'];
147
-
148
- if (partnerName) {
149
- const developmentURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('development'));
150
-
151
- const fetchedDevelopmentURL = await getStackURL(partnerName, 'development');
152
-
153
- if (fetchedDevelopmentURL) {
154
- existingOpenAPIFile.servers[developmentURLIndex].url =
155
- fetchedDevelopmentURL[fetchedDevelopmentURL.length - 1] === '/'
156
- ? fetchedDevelopmentURL.slice(0, -1)
157
- : fetchedDevelopmentURL;
158
- } else {
159
- existingOpenAPIFile.servers[developmentURLIndex].url = 'development url';
160
- }
161
-
162
- const productionURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('production'));
163
-
164
- const fetchedProductionURL = await getStackURL(partnerName, 'production');
165
-
166
- if (fetchedProductionURL) {
167
- existingOpenAPIFile.servers[productionURLIndex].url =
168
- fetchedProductionURL[fetchedProductionURL.length - 1] === '/'
169
- ? fetchedProductionURL.slice(0, -1)
170
- : fetchedProductionURL;
171
- } else {
172
- existingOpenAPIFile.servers[productionURLIndex].url = 'production url';
173
- }
174
- }
175
-
176
121
  await fs.writeFile(OUTPUT_FILE, JSON.stringify(existingOpenAPIFile, undefined, 4));
122
+
177
123
  console.info('Open API documentation generated successfully');
178
124
  };
179
125
 
180
- async function getStackURL(partnerName: string, environment: 'development' | 'production') {
181
- const stackName = `${partnerName}-${environment}`;
182
- const cloudFormationClient = new CloudFormationClient();
183
-
184
- const describeStacksCommand = new DescribeStacksCommand({
185
- StackName: stackName
186
- });
187
-
188
- const result = await cloudFormationClient.send(describeStacksCommand).catch((err) => {
189
- if (
190
- err instanceof CloudFormationServiceException &&
191
- err.message.includes(`Stack with id ${stackName} does not exist`)
192
- ) {
193
- return;
194
- }
195
-
196
- throw err;
197
- });
198
-
199
- if (!result || !result.Stacks) {
200
- console.warn(
201
- `Base URL was not found with the given environment. Environment will not be updated. Given environment: ${environment}`
202
- );
203
-
204
- return;
205
- }
206
-
207
- for (const cloudFormationStack of result.Stacks) {
208
- if (!cloudFormationStack.Outputs) {
209
- console.warn(
210
- `Output was not found within the given stack. Environment will not be updated. Given environment: ${environment}`
211
- );
212
-
213
- return;
214
- }
215
-
216
- for (const output of cloudFormationStack.Outputs) {
217
- if (output.OutputKey !== 'WebEndpoint' || !output.OutputValue) {
218
- continue;
219
- }
220
-
221
- return output.OutputValue;
222
- }
223
- }
224
- }
225
-
226
126
  function generateEventResponseComponent(
227
127
  responseType: OpenAPIConfig['responseType'] = 'mindbehind-chat-bot-response',
228
128
  eventResponseParametersSchema?: OpenApiZodAny,