vls-openapi-generator 1.8.2 → 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.
- package/dist/generate-openapi.js +16 -3
- package/package.json +1 -1
- package/src/generate-openapi.ts +22 -4
package/dist/generate-openapi.js
CHANGED
|
@@ -143,6 +143,9 @@ const generateOpenAPI = async () => {
|
|
|
143
143
|
? fetchedDevelopmentURL.slice(0, -1)
|
|
144
144
|
: fetchedDevelopmentURL;
|
|
145
145
|
}
|
|
146
|
+
else {
|
|
147
|
+
existingOpenAPIFile.servers[developmentURLIndex].url = 'development url';
|
|
148
|
+
}
|
|
146
149
|
const productionURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('production'));
|
|
147
150
|
const fetchedProductionURL = await getStackURL(partnerName, 'production');
|
|
148
151
|
if (fetchedProductionURL) {
|
|
@@ -151,18 +154,28 @@ const generateOpenAPI = async () => {
|
|
|
151
154
|
? fetchedProductionURL.slice(0, -1)
|
|
152
155
|
: fetchedProductionURL;
|
|
153
156
|
}
|
|
157
|
+
else {
|
|
158
|
+
existingOpenAPIFile.servers[productionURLIndex].url = 'production url';
|
|
159
|
+
}
|
|
154
160
|
}
|
|
155
161
|
await fs_1.promises.writeFile(OUTPUT_FILE, JSON.stringify(existingOpenAPIFile, undefined, 4));
|
|
156
162
|
console.info('Open API documentation generated successfully');
|
|
157
163
|
};
|
|
158
164
|
exports.generateOpenAPI = generateOpenAPI;
|
|
159
165
|
async function getStackURL(partnerName, environment) {
|
|
166
|
+
const stackName = `${partnerName}-${environment}`;
|
|
160
167
|
const cloudFormationClient = new client_cloudformation_1.CloudFormationClient();
|
|
161
168
|
const describeStacksCommand = new client_cloudformation_1.DescribeStacksCommand({
|
|
162
|
-
StackName:
|
|
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;
|
|
163
177
|
});
|
|
164
|
-
|
|
165
|
-
if (!result.Stacks) {
|
|
178
|
+
if (!result || !result.Stacks) {
|
|
166
179
|
console.warn(`Base URL was not found with the given environment. Environment will not be updated. Given environment: ${environment}`);
|
|
167
180
|
return;
|
|
168
181
|
}
|
package/package.json
CHANGED
package/src/generate-openapi.ts
CHANGED
|
@@ -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 {
|
|
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');
|
|
@@ -148,6 +152,8 @@ export const generateOpenAPI = async (): Promise<void> => {
|
|
|
148
152
|
fetchedDevelopmentURL[fetchedDevelopmentURL.length - 1] === '/'
|
|
149
153
|
? fetchedDevelopmentURL.slice(0, -1)
|
|
150
154
|
: fetchedDevelopmentURL;
|
|
155
|
+
} else {
|
|
156
|
+
existingOpenAPIFile.servers[developmentURLIndex].url = 'development url';
|
|
151
157
|
}
|
|
152
158
|
|
|
153
159
|
const productionURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('production'));
|
|
@@ -159,6 +165,8 @@ export const generateOpenAPI = async (): Promise<void> => {
|
|
|
159
165
|
fetchedProductionURL[fetchedProductionURL.length - 1] === '/'
|
|
160
166
|
? fetchedProductionURL.slice(0, -1)
|
|
161
167
|
: fetchedProductionURL;
|
|
168
|
+
} else {
|
|
169
|
+
existingOpenAPIFile.servers[productionURLIndex].url = 'production url';
|
|
162
170
|
}
|
|
163
171
|
}
|
|
164
172
|
|
|
@@ -167,15 +175,25 @@ export const generateOpenAPI = async (): Promise<void> => {
|
|
|
167
175
|
};
|
|
168
176
|
|
|
169
177
|
async function getStackURL(partnerName: string, environment: 'development' | 'production') {
|
|
178
|
+
const stackName = `${partnerName}-${environment}`;
|
|
170
179
|
const cloudFormationClient = new CloudFormationClient();
|
|
171
180
|
|
|
172
181
|
const describeStacksCommand = new DescribeStacksCommand({
|
|
173
|
-
StackName:
|
|
182
|
+
StackName: stackName
|
|
174
183
|
});
|
|
175
184
|
|
|
176
|
-
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
|
+
});
|
|
177
195
|
|
|
178
|
-
if (!result.Stacks) {
|
|
196
|
+
if (!result || !result.Stacks) {
|
|
179
197
|
console.warn(
|
|
180
198
|
`Base URL was not found with the given environment. Environment will not be updated. Given environment: ${environment}`
|
|
181
199
|
);
|