vls-openapi-generator 1.2.2 → 1.3.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.d.ts +1 -0
- package/dist/generate-openapi.js +26 -61
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22 -0
- package/dist/lambda-type.js +1 -2
- package/dist/openapi-type.js +1 -2
- package/dist/postman-service.d.ts +13 -0
- package/dist/postman-service.js +24 -0
- package/dist/upload-openapi.d.ts +2 -0
- package/dist/upload-openapi.js +28 -0
- package/package.json +5 -4
- package/src/generate-openapi.ts +9 -9
- package/src/index.ts +28 -0
- package/src/postman-service.ts +38 -0
- package/src/upload-openapi.ts +40 -0
- package/tsconfig.json +2 -2
package/dist/generate-openapi.js
CHANGED
|
@@ -1,73 +1,44 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
const zod_openapi_1 = require("@anatine/zod-openapi");
|
|
38
|
-
const child_process_1 = require("child_process");
|
|
39
|
-
const fs_1 = require("fs");
|
|
40
|
-
require("module-alias/register.js");
|
|
41
|
-
const path = __importStar(require("path"));
|
|
42
|
-
const util_1 = require("util");
|
|
43
|
-
const zod_1 = require("zod");
|
|
2
|
+
import { extendApi, generateSchema } from '@anatine/zod-openapi';
|
|
3
|
+
import { exec } from 'child_process';
|
|
4
|
+
import { promises as fs } from 'fs';
|
|
5
|
+
import 'module-alias/register.js';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { promisify } from 'util';
|
|
8
|
+
import { z } from 'zod';
|
|
44
9
|
const OPENAPI_FILE = path.join(process.cwd(), 'openapi.json');
|
|
45
10
|
const HANDLERS_DIR = path.join(process.cwd(), 'dist', 'src', 'handlers');
|
|
46
11
|
const SCHEMAS_DIR = path.join(process.cwd(), 'dist', 'src', 'schemas');
|
|
47
12
|
const OUTPUT_FILE = path.join(process.cwd(), 'openapi.json');
|
|
48
|
-
const
|
|
13
|
+
export const generateOpenAPI = async () => {
|
|
14
|
+
const args = process.argv;
|
|
15
|
+
const params = {};
|
|
16
|
+
for (let i = 2; i < args.length; i += 2) {
|
|
17
|
+
const key = args[i].replace('--', '');
|
|
18
|
+
params[key] = args[i + 1];
|
|
19
|
+
}
|
|
49
20
|
console.info('Generating Open API documentation...');
|
|
50
|
-
await
|
|
51
|
-
await
|
|
52
|
-
const handlerFiles = await
|
|
53
|
-
const existingOpenAPIFile = JSON.parse(await
|
|
21
|
+
await promisify(exec)('rm -rf ./dist');
|
|
22
|
+
await promisify(exec)('npx tsc');
|
|
23
|
+
const handlerFiles = await fs.readdir(HANDLERS_DIR);
|
|
24
|
+
const existingOpenAPIFile = JSON.parse(await fs.readFile(OPENAPI_FILE, 'utf-8'));
|
|
54
25
|
for (const handler of handlerFiles) {
|
|
55
26
|
const fileName = path.parse(handler).name;
|
|
56
|
-
const { bodySchema, queryParametersSchema, eventResponseParametersSchema, eventResponseModulesSchema, OPENAPI_CONFIG: openAPIConfig } = (await
|
|
57
|
-
const bodyComponent =
|
|
58
|
-
const queryParametersComponent =
|
|
59
|
-
const eventResponseComponent =
|
|
27
|
+
const { bodySchema, queryParametersSchema, eventResponseParametersSchema, eventResponseModulesSchema, OPENAPI_CONFIG: openAPIConfig } = (await import(path.join(SCHEMAS_DIR, fileName + '.js')).catch(() => ({})));
|
|
28
|
+
const bodyComponent = generateSchema(bodySchema ?? z.never(), undefined, '3.0');
|
|
29
|
+
const queryParametersComponent = generateSchema(queryParametersSchema ?? z.never(), undefined, '3.0');
|
|
30
|
+
const eventResponseComponent = generateSchema(z.object({
|
|
60
31
|
...(eventResponseParametersSchema
|
|
61
32
|
? { params: eventResponseParametersSchema }
|
|
62
|
-
: { params:
|
|
33
|
+
: { params: z.object({}) }),
|
|
63
34
|
...(eventResponseModulesSchema
|
|
64
35
|
? { modules: eventResponseModulesSchema }
|
|
65
36
|
: {
|
|
66
|
-
modules:
|
|
37
|
+
modules: extendApi(z.array(z.unknown()), {
|
|
67
38
|
example: []
|
|
68
39
|
})
|
|
69
40
|
}),
|
|
70
|
-
fallback:
|
|
41
|
+
fallback: z.boolean().default(false)
|
|
71
42
|
}), undefined, '3.0');
|
|
72
43
|
const queryParameters = [];
|
|
73
44
|
if (queryParametersSchema) {
|
|
@@ -110,11 +81,5 @@ const generateTemplate = async () => {
|
|
|
110
81
|
}
|
|
111
82
|
};
|
|
112
83
|
}
|
|
113
|
-
await
|
|
84
|
+
await fs.writeFile(OUTPUT_FILE, JSON.stringify(existingOpenAPIFile, undefined, 4));
|
|
114
85
|
};
|
|
115
|
-
generateTemplate()
|
|
116
|
-
.then(() => console.info('Open API documentation generated successfully'))
|
|
117
|
-
.catch((error) => {
|
|
118
|
-
console.error(error);
|
|
119
|
-
process.exit(1);
|
|
120
|
-
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lambda-type';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { generateOpenAPI } from './generate-openapi';
|
|
2
|
+
import { uploadOpenAPI } from './upload-openapi';
|
|
3
|
+
export * from './lambda-type';
|
|
4
|
+
try {
|
|
5
|
+
await generateOpenAPI();
|
|
6
|
+
console.info('Open API documentation generated successfully');
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
console.error(error);
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
if (process.argv.includes('--upload')) {
|
|
13
|
+
console.info('Uploading Open API documentation to Postman...');
|
|
14
|
+
try {
|
|
15
|
+
await uploadOpenAPI();
|
|
16
|
+
console.info('Open API documentation uploaded successfully');
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.error(error);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
}
|
package/dist/lambda-type.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/openapi-type.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OpenAPI } from './openapi-type';
|
|
2
|
+
export declare class PostmanService {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(apiKey: string);
|
|
5
|
+
getCollections: () => Promise<{
|
|
6
|
+
collections: {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}[];
|
|
10
|
+
}>;
|
|
11
|
+
deleteCollection: (collectionID: string) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
12
|
+
createCollection: (payload: OpenAPI) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
export class PostmanService {
|
|
3
|
+
constructor(apiKey) {
|
|
4
|
+
this.getCollections = async () => {
|
|
5
|
+
return (await this.client.get('/collections')).data;
|
|
6
|
+
};
|
|
7
|
+
this.deleteCollection = async (collectionID) => {
|
|
8
|
+
return await this.client.delete(`/collections/${collectionID}`);
|
|
9
|
+
};
|
|
10
|
+
this.createCollection = async (payload) => {
|
|
11
|
+
return await this.client.post('/import/openapi', {
|
|
12
|
+
type: 'json',
|
|
13
|
+
input: payload
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
this.client = axios.create({
|
|
17
|
+
baseURL: 'https://api.getpostman.com',
|
|
18
|
+
headers: {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
'X-Api-Key': apiKey
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import 'module-alias/register.js';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { PostmanService } from './postman-service';
|
|
5
|
+
const OPENAPI_FILE = path.join(process.cwd(), 'openapi.json');
|
|
6
|
+
export const uploadOpenAPI = async () => {
|
|
7
|
+
const args = process.argv;
|
|
8
|
+
const params = {};
|
|
9
|
+
for (let i = 2; i < args.length; i += 2) {
|
|
10
|
+
const key = args[i].replace('--', '');
|
|
11
|
+
params[key] = args[i + 1];
|
|
12
|
+
}
|
|
13
|
+
const postmanToken = params['postman-token'];
|
|
14
|
+
const stackName = params['stack-name'];
|
|
15
|
+
if (!params['postman-token']) {
|
|
16
|
+
throw new Error('Postman token is missing.');
|
|
17
|
+
}
|
|
18
|
+
if (!params['stack-name']) {
|
|
19
|
+
throw new Error('Stack name is missing.');
|
|
20
|
+
}
|
|
21
|
+
const postmanService = new PostmanService(postmanToken);
|
|
22
|
+
const stackCollection = (await postmanService.getCollections()).collections.find((x) => x.name === stackName);
|
|
23
|
+
if (stackCollection) {
|
|
24
|
+
await postmanService.deleteCollection(stackCollection.id);
|
|
25
|
+
}
|
|
26
|
+
const existingOpenAPIFile = JSON.parse(await fs.readFile(OPENAPI_FILE, 'utf-8'));
|
|
27
|
+
await postmanService.createCollection(existingOpenAPIFile);
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vls-openapi-generator",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "dist/
|
|
5
|
-
"types": "dist/
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"check-format": "prettier . --check",
|
|
8
8
|
"fix-format": "prettier . --write",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"description": "VLS Open API Generator",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@anatine/zod-openapi": "^2.2.7",
|
|
19
|
+
"axios": "^1.7.9",
|
|
19
20
|
"module-alias": "^2.2.3"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
@@ -33,6 +34,6 @@
|
|
|
33
34
|
"typescript-eslint": "^8.9.0"
|
|
34
35
|
},
|
|
35
36
|
"bin": {
|
|
36
|
-
"vls-openapi-generator": "dist/
|
|
37
|
+
"vls-openapi-generator": "dist/index.js"
|
|
37
38
|
}
|
|
38
39
|
}
|
package/src/generate-openapi.ts
CHANGED
|
@@ -15,7 +15,15 @@ const HANDLERS_DIR = path.join(process.cwd(), 'dist', 'src', 'handlers');
|
|
|
15
15
|
const SCHEMAS_DIR = path.join(process.cwd(), 'dist', 'src', 'schemas');
|
|
16
16
|
const OUTPUT_FILE = path.join(process.cwd(), 'openapi.json');
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
export const generateOpenAPI = async (): Promise<void> => {
|
|
19
|
+
const args = process.argv;
|
|
20
|
+
const params: Record<string, string> = {};
|
|
21
|
+
|
|
22
|
+
for (let i = 2; i < args.length; i += 2) {
|
|
23
|
+
const key = args[i].replace('--', '');
|
|
24
|
+
params[key] = args[i + 1];
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
console.info('Generating Open API documentation...');
|
|
20
28
|
|
|
21
29
|
await promisify(exec)('rm -rf ./dist');
|
|
@@ -109,11 +117,3 @@ const generateTemplate = async (): Promise<void> => {
|
|
|
109
117
|
|
|
110
118
|
await fs.writeFile(OUTPUT_FILE, JSON.stringify(existingOpenAPIFile, undefined, 4));
|
|
111
119
|
};
|
|
112
|
-
|
|
113
|
-
generateTemplate()
|
|
114
|
-
.then(() => console.info('Open API documentation generated successfully'))
|
|
115
|
-
.catch((error) => {
|
|
116
|
-
console.error(error);
|
|
117
|
-
|
|
118
|
-
process.exit(1);
|
|
119
|
-
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { generateOpenAPI } from './generate-openapi';
|
|
2
|
+
import { uploadOpenAPI } from './upload-openapi';
|
|
3
|
+
|
|
4
|
+
export * from './lambda-type';
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
await generateOpenAPI();
|
|
8
|
+
|
|
9
|
+
console.info('Open API documentation generated successfully');
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(error);
|
|
12
|
+
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (process.argv.includes('--upload')) {
|
|
17
|
+
console.info('Uploading Open API documentation to Postman...');
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
await uploadOpenAPI();
|
|
21
|
+
|
|
22
|
+
console.info('Open API documentation uploaded successfully');
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error(error);
|
|
25
|
+
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import axios, { Axios } from 'axios';
|
|
2
|
+
import { OpenAPI } from './openapi-type';
|
|
3
|
+
|
|
4
|
+
export class PostmanService {
|
|
5
|
+
private client: Axios;
|
|
6
|
+
|
|
7
|
+
constructor(apiKey: string) {
|
|
8
|
+
this.client = axios.create({
|
|
9
|
+
baseURL: 'https://api.getpostman.com',
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
'X-Api-Key': apiKey
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public getCollections = async () => {
|
|
18
|
+
return (
|
|
19
|
+
await this.client.get<{
|
|
20
|
+
collections: {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
}[];
|
|
24
|
+
}>('/collections')
|
|
25
|
+
).data;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
public deleteCollection = async (collectionID: string) => {
|
|
29
|
+
return await this.client.delete(`/collections/${collectionID}`);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
public createCollection = async (payload: OpenAPI) => {
|
|
33
|
+
return await this.client.post('/import/openapi', {
|
|
34
|
+
type: 'json',
|
|
35
|
+
input: payload
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import 'module-alias/register.js';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { OpenAPI } from './openapi-type';
|
|
5
|
+
import { PostmanService } from './postman-service';
|
|
6
|
+
|
|
7
|
+
const OPENAPI_FILE = path.join(process.cwd(), 'openapi.json');
|
|
8
|
+
|
|
9
|
+
export const uploadOpenAPI = async (): Promise<void> => {
|
|
10
|
+
const args = process.argv;
|
|
11
|
+
const params: Record<string, string> = {};
|
|
12
|
+
|
|
13
|
+
for (let i = 2; i < args.length; i += 2) {
|
|
14
|
+
const key = args[i].replace('--', '');
|
|
15
|
+
params[key] = args[i + 1];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const postmanToken = params['postman-token'];
|
|
19
|
+
const stackName = params['stack-name'];
|
|
20
|
+
|
|
21
|
+
if (!params['postman-token']) {
|
|
22
|
+
throw new Error('Postman token is missing.');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!params['stack-name']) {
|
|
26
|
+
throw new Error('Stack name is missing.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const postmanService = new PostmanService(postmanToken);
|
|
30
|
+
|
|
31
|
+
const stackCollection = (await postmanService.getCollections()).collections.find((x) => x.name === stackName);
|
|
32
|
+
|
|
33
|
+
if (stackCollection) {
|
|
34
|
+
await postmanService.deleteCollection(stackCollection.id);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const existingOpenAPIFile = JSON.parse(await fs.readFile(OPENAPI_FILE, 'utf-8')) as OpenAPI;
|
|
38
|
+
|
|
39
|
+
await postmanService.createCollection(existingOpenAPIFile);
|
|
40
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
26
|
|
|
27
27
|
/* Modules */
|
|
28
|
-
"module": "
|
|
28
|
+
"module": "ES2022" /* Specify what module code is generated. */,
|
|
29
29
|
"rootDir": "src" /* Specify the root folder within your source files. */,
|
|
30
|
-
|
|
30
|
+
"moduleResolution": "node10" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
|
31
31
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
32
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
33
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|