Skip to content

Commit fd691be

Browse files
committed
feat: add scripts to run generator with custom config.json file
1 parent 7444b59 commit fd691be

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

bin/saddleback.cli.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const path = require('path');
6+
const { program } = require('commander');
7+
const pkg = require('../package.json');
8+
9+
const params = program
10+
.name('saddlebackOpenApi')
11+
.usage('[options]')
12+
.version(pkg.version)
13+
.option('-i, --input <value>', 'OpenAPI specification, can be a path, url or string content (required)')
14+
.option('-o, --output <value>', 'Output directory (required)')
15+
.option('-c, --config <value>', 'Path to the config file')
16+
.parse(process.argv)
17+
.opts();
18+
19+
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
20+
const config = require(path.resolve(params.config || `./openapi.config.json`));
21+
22+
if (OpenAPI) {
23+
OpenAPI.generateCustomSpec({
24+
input: params.input,
25+
output: params.output,
26+
...config,
27+
})
28+
.then(() => {
29+
process.exit(0);
30+
})
31+
.catch(error => {
32+
console.error(error);
33+
process.exit(1);
34+
});
35+
}

openapi.config.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"input": "./test/spec/saddlebackApi.json",
3+
"output": "./test/test/saddleback/",
4+
"httpClient": "axios",
5+
"clientName": "TestAxiosClassName",
6+
"useOptions": true,
7+
"useUnionTypes": false,
8+
"exportCore": true,
9+
"exportServices": true,
10+
"exportModels": true,
11+
"exportSchemas": false,
12+
"indent": "4",
13+
"postfix": "",
14+
"filterMethod": "greedy",
15+
"filterArray": ["/api/agreement", "/api/agreement/{id}", "/api/share-page/compare-results"]
16+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
"main": "dist/index.js",
3535
"types": "types/index.d.ts",
3636
"bin": {
37-
"openapi": "bin/index.js"
37+
"openapi": "bin/index.js",
38+
"saddlebackOpenapi": "bin/saddleback.cli.js"
3839
},
3940
"files": [
4041
"bin/index.js",
42+
"bin/saddleback.cli.js",
4143
"dist/index.js",
4244
"types/index.d.ts"
4345
],

0 commit comments

Comments
 (0)