vls-openapi-generator 1.8.2 → 1.9.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.
- package/dist/generate-openapi.js +19 -3
- package/dist/lambda-type.d.ts +1 -0
- package/package.json +1 -1
- package/src/generate-openapi.ts +26 -4
- package/src/lambda-type.ts +1 -0
package/dist/generate-openapi.js
CHANGED
|
@@ -77,6 +77,9 @@ const generateOpenAPI = async () => {
|
|
|
77
77
|
}
|
|
78
78
|
const { bodySchema, queryParametersSchema, eventResponseParametersSchema, eventResponseModulesSchema, OPENAPI_CONFIG: openAPIConfig } = (await Promise.resolve(`${path.join(SCHEMAS_DIR, fileName + '.js')}`).then(s => __importStar(require(s))).catch(() => ({})));
|
|
79
79
|
const { LAMBDA_CONFIG } = (await Promise.resolve(`${path.join(HANDLERS_DIR, `${fileName}.js`)}`).then(s => __importStar(require(s))));
|
|
80
|
+
if (openAPIConfig.isDocumentationNeeded !== undefined && !openAPIConfig.isDocumentationNeeded) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
80
83
|
const bodyComponent = (0, zod_openapi_1.generateSchema)(bodySchema ?? zod_1.z.never(), undefined, '3.0');
|
|
81
84
|
const queryParametersComponent = (0, zod_openapi_1.generateSchema)(queryParametersSchema ?? zod_1.z.never(), undefined, '3.0');
|
|
82
85
|
const eventResponseComponent = (0, zod_openapi_1.generateSchema)(zod_1.z.object({
|
|
@@ -143,6 +146,9 @@ const generateOpenAPI = async () => {
|
|
|
143
146
|
? fetchedDevelopmentURL.slice(0, -1)
|
|
144
147
|
: fetchedDevelopmentURL;
|
|
145
148
|
}
|
|
149
|
+
else {
|
|
150
|
+
existingOpenAPIFile.servers[developmentURLIndex].url = 'development url';
|
|
151
|
+
}
|
|
146
152
|
const productionURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('production'));
|
|
147
153
|
const fetchedProductionURL = await getStackURL(partnerName, 'production');
|
|
148
154
|
if (fetchedProductionURL) {
|
|
@@ -151,18 +157,28 @@ const generateOpenAPI = async () => {
|
|
|
151
157
|
? fetchedProductionURL.slice(0, -1)
|
|
152
158
|
: fetchedProductionURL;
|
|
153
159
|
}
|
|
160
|
+
else {
|
|
161
|
+
existingOpenAPIFile.servers[productionURLIndex].url = 'production url';
|
|
162
|
+
}
|
|
154
163
|
}
|
|
155
164
|
await fs_1.promises.writeFile(OUTPUT_FILE, JSON.stringify(existingOpenAPIFile, undefined, 4));
|
|
156
165
|
console.info('Open API documentation generated successfully');
|
|
157
166
|
};
|
|
158
167
|
exports.generateOpenAPI = generateOpenAPI;
|
|
159
168
|
async function getStackURL(partnerName, environment) {
|
|
169
|
+
const stackName = `${partnerName}-${environment}`;
|
|
160
170
|
const cloudFormationClient = new client_cloudformation_1.CloudFormationClient();
|
|
161
171
|
const describeStacksCommand = new client_cloudformation_1.DescribeStacksCommand({
|
|
162
|
-
StackName:
|
|
172
|
+
StackName: stackName
|
|
173
|
+
});
|
|
174
|
+
const result = await cloudFormationClient.send(describeStacksCommand).catch((err) => {
|
|
175
|
+
if (err instanceof client_cloudformation_1.CloudFormationServiceException &&
|
|
176
|
+
err.message.includes(`Stack with id ${stackName} does not exist`)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
throw err;
|
|
163
180
|
});
|
|
164
|
-
|
|
165
|
-
if (!result.Stacks) {
|
|
181
|
+
if (!result || !result.Stacks) {
|
|
166
182
|
console.warn(`Base URL was not found with the given environment. Environment will not be updated. Given environment: ${environment}`);
|
|
167
183
|
return;
|
|
168
184
|
}
|
package/dist/lambda-type.d.ts
CHANGED
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');
|
|
@@ -70,6 +74,10 @@ export const generateOpenAPI = async (): Promise<void> => {
|
|
|
70
74
|
LAMBDA_CONFIG?: LambdaConfig;
|
|
71
75
|
};
|
|
72
76
|
|
|
77
|
+
if (openAPIConfig.isDocumentationNeeded !== undefined && !openAPIConfig.isDocumentationNeeded) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
73
81
|
const bodyComponent = generateSchema(bodySchema ?? z.never(), undefined, '3.0');
|
|
74
82
|
const queryParametersComponent = generateSchema(queryParametersSchema ?? z.never(), undefined, '3.0');
|
|
75
83
|
const eventResponseComponent = generateSchema(
|
|
@@ -148,6 +156,8 @@ export const generateOpenAPI = async (): Promise<void> => {
|
|
|
148
156
|
fetchedDevelopmentURL[fetchedDevelopmentURL.length - 1] === '/'
|
|
149
157
|
? fetchedDevelopmentURL.slice(0, -1)
|
|
150
158
|
: fetchedDevelopmentURL;
|
|
159
|
+
} else {
|
|
160
|
+
existingOpenAPIFile.servers[developmentURLIndex].url = 'development url';
|
|
151
161
|
}
|
|
152
162
|
|
|
153
163
|
const productionURLIndex = existingOpenAPIFile.servers.findIndex((x) => x.url.includes('production'));
|
|
@@ -159,6 +169,8 @@ export const generateOpenAPI = async (): Promise<void> => {
|
|
|
159
169
|
fetchedProductionURL[fetchedProductionURL.length - 1] === '/'
|
|
160
170
|
? fetchedProductionURL.slice(0, -1)
|
|
161
171
|
: fetchedProductionURL;
|
|
172
|
+
} else {
|
|
173
|
+
existingOpenAPIFile.servers[productionURLIndex].url = 'production url';
|
|
162
174
|
}
|
|
163
175
|
}
|
|
164
176
|
|
|
@@ -167,15 +179,25 @@ export const generateOpenAPI = async (): Promise<void> => {
|
|
|
167
179
|
};
|
|
168
180
|
|
|
169
181
|
async function getStackURL(partnerName: string, environment: 'development' | 'production') {
|
|
182
|
+
const stackName = `${partnerName}-${environment}`;
|
|
170
183
|
const cloudFormationClient = new CloudFormationClient();
|
|
171
184
|
|
|
172
185
|
const describeStacksCommand = new DescribeStacksCommand({
|
|
173
|
-
StackName:
|
|
186
|
+
StackName: stackName
|
|
174
187
|
});
|
|
175
188
|
|
|
176
|
-
const result = await cloudFormationClient.send(describeStacksCommand)
|
|
189
|
+
const result = await cloudFormationClient.send(describeStacksCommand).catch((err) => {
|
|
190
|
+
if (
|
|
191
|
+
err instanceof CloudFormationServiceException &&
|
|
192
|
+
err.message.includes(`Stack with id ${stackName} does not exist`)
|
|
193
|
+
) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
throw err;
|
|
198
|
+
});
|
|
177
199
|
|
|
178
|
-
if (!result.Stacks) {
|
|
200
|
+
if (!result || !result.Stacks) {
|
|
179
201
|
console.warn(
|
|
180
202
|
`Base URL was not found with the given environment. Environment will not be updated. Given environment: ${environment}`
|
|
181
203
|
);
|