vls-openapi-generator 1.8.1 → 1.8.3

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.
@@ -138,12 +138,24 @@ const generateOpenAPI = async () => {
138
138
  const developmentURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('development'));
139
139
  const fetchedDevelopmentURL = await getStackURL(partnerName, 'development');
140
140
  if (fetchedDevelopmentURL) {
141
- existingOpenAPIFile.servers[developmentURLIndex].url = fetchedDevelopmentURL;
141
+ existingOpenAPIFile.servers[developmentURLIndex].url =
142
+ fetchedDevelopmentURL[fetchedDevelopmentURL.length - 1] === '/'
143
+ ? fetchedDevelopmentURL.slice(0, -1)
144
+ : fetchedDevelopmentURL;
145
+ }
146
+ else {
147
+ existingOpenAPIFile.servers[developmentURLIndex].url = 'development url';
142
148
  }
143
149
  const productionURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('production'));
144
150
  const fetchedProductionURL = await getStackURL(partnerName, 'production');
145
151
  if (fetchedProductionURL) {
146
- existingOpenAPIFile.servers[productionURLIndex].url = fetchedProductionURL;
152
+ existingOpenAPIFile.servers[productionURLIndex].url =
153
+ fetchedProductionURL[fetchedProductionURL.length - 1] === '/'
154
+ ? fetchedProductionURL.slice(0, -1)
155
+ : fetchedProductionURL;
156
+ }
157
+ else {
158
+ existingOpenAPIFile.servers[productionURLIndex].url = 'production url';
147
159
  }
148
160
  }
149
161
  await fs_1.promises.writeFile(OUTPUT_FILE, JSON.stringify(existingOpenAPIFile, undefined, 4));
@@ -151,12 +163,19 @@ const generateOpenAPI = async () => {
151
163
  };
152
164
  exports.generateOpenAPI = generateOpenAPI;
153
165
  async function getStackURL(partnerName, environment) {
166
+ const stackName = `${partnerName}-${environment}`;
154
167
  const cloudFormationClient = new client_cloudformation_1.CloudFormationClient();
155
168
  const describeStacksCommand = new client_cloudformation_1.DescribeStacksCommand({
156
- StackName: `${partnerName}-${environment}`
169
+ StackName: stackName
170
+ });
171
+ const result = await cloudFormationClient.send(describeStacksCommand).catch((err) => {
172
+ if (err instanceof client_cloudformation_1.CloudFormationServiceException &&
173
+ err.message.includes(`Stack with id ${stackName} does not exist`)) {
174
+ return;
175
+ }
176
+ throw err;
157
177
  });
158
- const result = await cloudFormationClient.send(describeStacksCommand);
159
- if (!result.Stacks) {
178
+ if (!result || !result.Stacks) {
160
179
  console.warn(`Base URL was not found with the given environment. Environment will not be updated. Given environment: ${environment}`);
161
180
  return;
162
181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vls-openapi-generator",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -7,7 +7,11 @@ import { promisify } from 'util';
7
7
  import { z } from 'zod';
8
8
  import { LambdaConfig, OpenAPIConfig } from './lambda-type';
9
9
  import { OpenAPI } from './openapi-type';
10
- import { CloudFormationClient, DescribeStacksCommand } from '@aws-sdk/client-cloudformation';
10
+ import {
11
+ CloudFormationClient,
12
+ CloudFormationServiceException,
13
+ DescribeStacksCommand
14
+ } from '@aws-sdk/client-cloudformation';
11
15
 
12
16
  const OPENAPI_FILE = path.join(process.cwd(), 'openapi.json');
13
17
  const HANDLERS_DIR = path.join(process.cwd(), 'dist', 'src', 'handlers');
@@ -144,7 +148,12 @@ export const generateOpenAPI = async (): Promise<void> => {
144
148
  const fetchedDevelopmentURL = await getStackURL(partnerName, 'development');
145
149
 
146
150
  if (fetchedDevelopmentURL) {
147
- existingOpenAPIFile.servers[developmentURLIndex].url = fetchedDevelopmentURL;
151
+ existingOpenAPIFile.servers[developmentURLIndex].url =
152
+ fetchedDevelopmentURL[fetchedDevelopmentURL.length - 1] === '/'
153
+ ? fetchedDevelopmentURL.slice(0, -1)
154
+ : fetchedDevelopmentURL;
155
+ } else {
156
+ existingOpenAPIFile.servers[developmentURLIndex].url = 'development url';
148
157
  }
149
158
 
150
159
  const productionURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('production'));
@@ -152,7 +161,12 @@ export const generateOpenAPI = async (): Promise<void> => {
152
161
  const fetchedProductionURL = await getStackURL(partnerName, 'production');
153
162
 
154
163
  if (fetchedProductionURL) {
155
- existingOpenAPIFile.servers[productionURLIndex].url = fetchedProductionURL;
164
+ existingOpenAPIFile.servers[productionURLIndex].url =
165
+ fetchedProductionURL[fetchedProductionURL.length - 1] === '/'
166
+ ? fetchedProductionURL.slice(0, -1)
167
+ : fetchedProductionURL;
168
+ } else {
169
+ existingOpenAPIFile.servers[productionURLIndex].url = 'production url';
156
170
  }
157
171
  }
158
172
 
@@ -161,15 +175,25 @@ export const generateOpenAPI = async (): Promise<void> => {
161
175
  };
162
176
 
163
177
  async function getStackURL(partnerName: string, environment: 'development' | 'production') {
178
+ const stackName = `${partnerName}-${environment}`;
164
179
  const cloudFormationClient = new CloudFormationClient();
165
180
 
166
181
  const describeStacksCommand = new DescribeStacksCommand({
167
- StackName: `${partnerName}-${environment}`
182
+ StackName: stackName
168
183
  });
169
184
 
170
- const result = await cloudFormationClient.send(describeStacksCommand);
185
+ const result = await cloudFormationClient.send(describeStacksCommand).catch((err) => {
186
+ if (
187
+ err instanceof CloudFormationServiceException &&
188
+ err.message.includes(`Stack with id ${stackName} does not exist`)
189
+ ) {
190
+ return;
191
+ }
192
+
193
+ throw err;
194
+ });
171
195
 
172
- if (!result.Stacks) {
196
+ if (!result || !result.Stacks) {
173
197
  console.warn(
174
198
  `Base URL was not found with the given environment. Environment will not be updated. Given environment: ${environment}`
175
199
  );