forked from acacode/swagger-typescript-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·52 lines (46 loc) · 2.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
// Copyright (c) 2019-present acacode
// Node module: swagger-typescript-api
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
// Repository https://github.com/acacode/swagger-typescript-api
const program = require("commander");
const { resolve } = require("path");
const { generateApi } = require("./src");
const { version } = require("./package.json");
program
.version(version, "-v, --version", "output the current version")
.description("Generate api via swagger scheme.\nSupports OA 3.0, 2.0, JSON, yaml.")
.requiredOption("-p, --path <path>", "path/url to swagger scheme")
.option("-o, --output <output>", "output path of typescript api file", "./")
.option("-n, --name <name>", "name of output typescript api file", "Api.ts")
.option("-t, --templates <path>", "path to folder containing templates")
.option(
"-d, --default-as-success",
'use "default" response status code as success response too.\n' +
'some swagger schemas use "default" response status code as success response type by default.',
false,
)
.option(
"-r, --responses",
"generate additional information about request responses\n" +
"also add typings for bad responses",
false,
)
.option("--union-enums", 'generate all "enum" types as union types (T1 | T2 | TN)', false)
.option("--route-types", "generate type definitions for API routes", false)
.option("--no-client", "do not generate an API class", false);
program.parse(process.argv);
const { path, output, name, templates, unionEnums, routeTypes, client, defaultAsSuccess, responses } = program;
generateApi({
name,
url: path,
generateRouteTypes: routeTypes,
generateClient: client,
defaultResponseAsSuccess: defaultAsSuccess,
generateUnionEnums: unionEnums,
generateResponses: responses,
input: resolve(process.cwd(), path),
output: resolve(process.cwd(), output || "."),
templates: resolve(templates ? process.cwd() : __dirname, templates || "./src/templates"),
});