aws-lambda-api-tools 0.1.3 → 0.1.4

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.
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+
3
+ /*
4
+ Usage:
5
+ npm run generate-swagger --args path/to/config/file output/directory
6
+ */
7
+
8
+ const minimist = require('minimist');
9
+ const path = require('path');
10
+ const argv = minimist(process.argv.slice(2));
11
+ const fs = require('fs');
12
+
13
+ if (argv._.length === 0) {
14
+ argv._ = [undefined, undefined];
15
+ } else if (argv._.length === 1) {
16
+ argv._.push(undefined);
17
+ }
18
+
19
+ console.log(JSON.stringify(argv._));
20
+
21
+ const [configFile = './dist/routes-config.js', outputFile = './route-modules-oas.json'] = argv._;
22
+
23
+ const swaggerModulePath = path.join('.', '../dist/lib/swagger-route-specification-generator');
24
+ const { generateRouteSwaggerSpec } = require(swaggerModulePath);
25
+
26
+ const configFilePath = path.join(process.cwd(), configFile);
27
+ console.log(`config file path: ${configFilePath}`);
28
+ const { config, routesBaseUrlPath } = require(configFilePath);
29
+
30
+ const swaggerSpec = { paths: {}, components: {} };
31
+ const swaggerPaths = {};
32
+ const swaggerModels = {};
33
+
34
+ config.routes.filter(r => r.generateOpenApiDocs).forEach(r => {
35
+
36
+ const routeHandlerModulePath = r.handlerPath.replace(process.cwd(), '.').replace('src/', 'dist/');
37
+
38
+ const loadedModule = require(path.join(process.cwd(), routeHandlerModulePath));
39
+ const { routeSchema } = loadedModule.default || loadedModule;
40
+
41
+ const { path: swaggerPathAndMethodSpec, components } = generateRouteSwaggerSpec(routeSchema, r);
42
+ swaggerPathAndMethodSpec.tags = [routesBaseUrlPath.replace('/','.')];
43
+ let pathMethodItems = swaggerSpec.paths[r.path];
44
+ if (!pathMethodItems) {
45
+ pathMethodItems = swaggerSpec.paths[r.path] = {};
46
+ }
47
+ pathMethodItems[r.method.toLowerCase()] = swaggerPathAndMethodSpec;
48
+ swaggerSpec.paths[r.path] = { ...swaggerSpec.paths[r.path], ...pathMethodItems };
49
+ swaggerSpec.components.schemas = { ...swaggerSpec.components.schemas, ...components.schemas };
50
+ });
51
+ fs.writeFileSync(path.join(process.cwd(), outputFile), JSON.stringify(swaggerSpec));
52
+ console.log(JSON.stringify(swaggerSpec));
53
+
54
+ // require('../lib')(argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-lambda-api-tools",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": {