Skip to content

Commit 8152fa7

Browse files
committed
Generator command
1 parent 86bc49e commit 8152fa7

File tree

8 files changed

+129
-2
lines changed

8 files changed

+129
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
additionalProperties:
2+
paramNaming: original

src/commands/generate.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
export { GenerateCommand as default } from "../generate-from-oas";

src/diff/diffCommand.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, salesforce.com, inc.
2+
* Copyright (c) 2025, salesforce.com, inc.
33
* All rights reserved.
44
* SPDX-License-Identifier: BSD-3-Clause
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -228,7 +228,6 @@ Exit statuses:
228228
// Diff two files (we do not have a custom ruleset defined for OAS
229229
// By default, checks are all 'diff-only'
230230
await oasDiffChangelog(baseApis, newApis, flags);
231-
// await oasDiffChangelog("~/Git/oas-spike/diff-oas-test/specs/petstore.yaml", "~/Git/oas-spike/diff-oas-test/specs/petstore1.yaml", flags);
232231
}
233232
} else {
234233
if (flags.dir) {

src/diff/oasDiff.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
17
import { flags } from "@oclif/command";
28
import { OutputFlags } from "@oclif/parser";
39
import fs from 'fs-extra'
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { Command, flags } from "@oclif/command";
9+
import { allCommonFlags } from "../common/flags";
10+
import { generateFromOas, DEFAULT_CONFIG_PACKAGE_PATH, DEFAULT_CONFIG_PATH } from "./generateFromOas";
11+
12+
export class GenerateCommand extends Command {
13+
14+
static description = "Generate from OAS";
15+
16+
static flags = {
17+
...allCommonFlags(),
18+
inputSpec: flags.string({
19+
char: "i",
20+
description: 'Input OAS specification file',
21+
required: true,
22+
}),
23+
outputDir: flags.string({
24+
char: "o",
25+
description: 'Output directory for generated code',
26+
required: true,
27+
}),
28+
templateDir: flags.string({
29+
char: "t",
30+
description: 'Template directory',
31+
required: true,
32+
}),
33+
configFile: flags.string({
34+
char: "c",
35+
description: `[default:${DEFAULT_CONFIG_PACKAGE_PATH}] Configuration file with additional generator properties`
36+
}),
37+
generator: flags.string({
38+
char: "g",
39+
description: '[default:typescript-fetch] Generator to use',
40+
}),
41+
skipValidateSpec: flags.boolean({
42+
description: 'Skip validation of the OAS specification',
43+
}),
44+
};
45+
46+
async run(): Promise<void> {
47+
console.log('Running generator')
48+
const { flags } = this.parse(GenerateCommand);
49+
console.log(flags)
50+
generateFromOas({
51+
inputSpec: flags.inputSpec,
52+
outputDir: flags.outputDir,
53+
templateDir: flags.templateDir,
54+
configFile: flags.configFile,
55+
generator: flags.generator,
56+
skipValidateSpec: flags.skipValidateSpec
57+
});
58+
}
59+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import path from "path";
9+
import { execSync } from "child_process";
10+
import { string, boolean } from "@oclif/parser/lib/flags";
11+
12+
// Path relative to project root
13+
export const DEFAULT_CONFIG_BASE_PATH =
14+
"resources/generate-from-oas/config/config.yaml";
15+
16+
export const DEFAULT_CONFIG_PATH = path.join(
17+
__dirname,
18+
"../../",
19+
DEFAULT_CONFIG_BASE_PATH
20+
);
21+
22+
// Path prefixed with package name, short form usable by require()
23+
export const DEFAULT_CONFIG_PACKAGE_PATH = path.join(
24+
"@commerce-apps/raml-toolkit",
25+
path.dirname(DEFAULT_CONFIG_BASE_PATH),
26+
path.basename(DEFAULT_CONFIG_BASE_PATH)
27+
);
28+
29+
30+
export const generateFromOas = (args: {
31+
inputSpec: string,
32+
outputDir: string,
33+
templateDir: string,
34+
configFile?: string,
35+
generator?: string,
36+
skipValidateSpec?: boolean
37+
}) => {
38+
const {inputSpec, outputDir, templateDir, configFile, generator, skipValidateSpec} = args;
39+
const skipValidateSpecFlag = skipValidateSpec ? "--skip-validate-spec" : "";
40+
const _configFile = configFile ? configFile : DEFAULT_CONFIG_PATH;
41+
const _generator = generator ? generator : "typescript-fetch";
42+
43+
execSync(`openapi-generator-cli generate -i ${inputSpec} -o ${outputDir} -t ${templateDir} -g ${_generator} -c ${_configFile} ${skipValidateSpecFlag}`);
44+
}
45+

src/generate-from-oas/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
export { GenerateCommand } from "./generateCommand";
8+
export { generateFromOas } from "./generateFromOas";

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export * as amfParser from "./common/amfParser";
99
export * as diff from "./diff";
1010
export * as download from "./download";
1111
export * as generate from "./generate";
12+
export * as generateFromOas from "./generate-from-oas";
1213
export * as lint from "./lint";
1314
export { ramlToolLogger } from "./common/logger";

0 commit comments

Comments
 (0)