-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgenerateFromOas.ts
More file actions
55 lines (49 loc) · 1.55 KB
/
generateFromOas.ts
File metadata and controls
55 lines (49 loc) · 1.55 KB
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
53
54
55
/*
* Copyright (c) 2025, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import path from "path";
import { execSync } from "child_process";
import { string, boolean } from "@oclif/parser/lib/flags";
// Path relative to project root
export const DEFAULT_CONFIG_BASE_PATH =
"resources/generate-from-oas/config/config.yaml";
export const DEFAULT_CONFIG_PATH = path.join(
__dirname,
"../../",
DEFAULT_CONFIG_BASE_PATH
);
// Path prefixed with package name, short form usable by require()
export const DEFAULT_CONFIG_PACKAGE_PATH = path.join(
"@commerce-apps/raml-toolkit",
path.dirname(DEFAULT_CONFIG_BASE_PATH),
path.basename(DEFAULT_CONFIG_BASE_PATH)
);
export const generateFromOas = (args: {
inputSpec: string;
outputDir: string;
templateDir: string;
configFile?: string;
generator?: string;
skipValidateSpec?: boolean;
flags?: string;
}) => {
const {
inputSpec,
outputDir,
templateDir,
configFile,
generator,
skipValidateSpec,
flags,
} = args;
const skipValidateSpecFlag = skipValidateSpec ? "--skip-validate-spec" : "";
const _configFile = configFile ? configFile : DEFAULT_CONFIG_PATH;
const _generator = generator ? generator : "typescript-fetch";
const _flags = flags ? flags : "";
execSync(
`openapi-generator-cli generate -i ${inputSpec} -o ${outputDir} -t ${templateDir} -g ${_generator} -c ${_configFile} ${skipValidateSpecFlag} ${_flags}`
);
};