Skip to content

Commit d8e537c

Browse files
committed
Lint
1 parent 8152fa7 commit d8e537c

File tree

7 files changed

+117
-113
lines changed

7 files changed

+117
-113
lines changed

src/commands/generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
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
66
*/
7-
export { GenerateCommand as default } from "../generate-from-oas";
7+
export { GenerateCommand as default } from "../generate-from-oas";

src/diff/diffCommand.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ApiCollectionChanges } from "./changes/apiCollectionChanges";
1313
import { diffRamlDirectories } from "./diffDirectories";
1414
import { allCommonFlags } from "../common/flags";
1515
import { execSync } from "child_process";
16-
import fs from 'fs-extra'
16+
import fs from "fs-extra";
1717

1818
import { oasDiffChangelog } from "./oasDiff";
1919

@@ -217,7 +217,9 @@ Exit statuses:
217217
try {
218218
execSync(`oasdiff --version`);
219219
} catch (err) {
220-
this.error("oasdiff is not installed. Install oasdiff according to https://github.com/oasdiff/oasdiff#installation");
220+
this.error(
221+
"oasdiff is not installed. Install oasdiff according to https://github.com/oasdiff/oasdiff#installation"
222+
);
221223
}
222224

223225
if (flags.dir) {
@@ -226,7 +228,7 @@ Exit statuses:
226228
await oasDiffChangelog(baseApisYamlGlob, newApisYamlGlob, flags);
227229
} else {
228230
// Diff two files (we do not have a custom ruleset defined for OAS
229-
// By default, checks are all 'diff-only'
231+
// By default, checks are all 'diff-only'
230232
await oasDiffChangelog(baseApis, newApis, flags);
231233
}
232234
} else {

src/diff/oasDiff.ts

Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,73 @@
66
*/
77
import { flags } from "@oclif/command";
88
import { OutputFlags } from "@oclif/parser";
9-
import fs from 'fs-extra'
9+
import fs from "fs-extra";
1010
import { execSync } from "child_process";
1111

12-
13-
/**
14-
* Find the differences between two directories containing API spec files.
15-
* Only finds differences, does not classify using a ruleset.
16-
*
17-
* @param baseApis - Path to base API directory
18-
* @param newApis - Path to new API directory
19-
* @param flags - Parsed CLI flags passed to the command
20-
*/
12+
/**
13+
* Find the differences between two directories containing API spec files.
14+
* Only finds differences, does not classify using a ruleset.
15+
*
16+
* @param baseApis - Path to base API directory
17+
* @param newApis - Path to new API directory
18+
* @param flags - Parsed CLI flags passed to the command
19+
*/
2120
async function oasDiffDirs(
22-
baseApis: string,
23-
newApis: string,
24-
flags
25-
): Promise<void> {
26-
try {
27-
28-
} catch (err) {
29-
console.error(err.message, { exit: 2 });
30-
}
31-
// if (apiCollectionChanges.hasChanges()) {
32-
// this.exit(1);
33-
// }
21+
baseApis: string,
22+
newApis: string,
23+
flags
24+
): Promise<void> {
25+
try {
26+
} catch (err) {
27+
console.error(err.message, { exit: 2 });
3428
}
29+
}
3530

36-
/**
37-
* If a file is given, saves the changes to the file, as JSON by default.
38-
* Otherwise, logs the changes to console, as text by default.
39-
*
40-
* @param changes - The changes to save or log
41-
* @param flags - Parsed CLI flags passed to the command
42-
*/
43-
async function _saveOrLogOas(
44-
changes: string,
45-
flags
46-
): Promise<void> {
47-
const file = flags["out-file"];
48-
if (file) {
49-
console.log('Saving results to file')
50-
if (flags.format === "json") {
51-
console.log('Using json format')
52-
await fs.writeJson(file, JSON.parse(changes));
53-
} else {
54-
console.log('Using console format')
55-
await fs.writeFile(file, changes);
56-
}
31+
/**
32+
* If a file is given, saves the changes to the file, as JSON by default.
33+
* Otherwise, logs the changes to console, as text by default.
34+
*
35+
* @param changes - The changes to save or log
36+
* @param flags - Parsed CLI flags passed to the command
37+
*/
38+
async function _saveOrLogOas(changes: string, flags): Promise<void> {
39+
const file = flags["out-file"];
40+
if (file) {
41+
console.log("Saving results to file");
42+
if (flags.format === "json") {
43+
console.log("Using json format");
44+
await fs.writeJson(file, JSON.parse(changes));
5745
} else {
58-
console.log(changes);
46+
console.log("Using console format");
47+
await fs.writeFile(file, changes);
5948
}
60-
}
49+
} else {
50+
console.log(changes);
51+
}
52+
}
6153

6254
export async function oasDiffChangelog(baseApi: string, newApi: string, flags) {
63-
try {
64-
console.log('Starting oasdiff')
65-
66-
const jsonMode = flags.format === "json" ? '-f json' : '';
67-
const directoryMode = flags.dir ? '--composed' : '';
55+
try {
56+
console.log("Starting oasdiff");
6857

69-
// TODO: Do we want to support the other output formats?
70-
// See https://github.com/oasdiff/oasdiff/blob/main/docs/BREAKING-CHANGES.md#output-formats
58+
const jsonMode = flags.format === "json" ? "-f json" : "";
59+
const directoryMode = flags.dir ? "--composed" : "";
7160

72-
// TODO: Do we want to support customizing severity levels?
73-
// This would be akin to the raml rulesets
74-
const oasdiffOutput = execSync(`oasdiff changelog ${jsonMode} ${directoryMode} ${baseApi} ${newApi}`).toString();
61+
// TODO: Do we want to support the other output formats?
62+
// See https://github.com/oasdiff/oasdiff/blob/main/docs/BREAKING-CHANGES.md#output-formats
7563

76-
if (oasdiffOutput.trim().length === 0) {
77-
console.log("No API changes reported by oasdiff");
78-
} else {
79-
await _saveOrLogOas(oasdiffOutput, flags);
80-
}
64+
// TODO: Do we want to support customizing severity levels?
65+
// This would be akin to the raml rulesets
66+
const oasdiffOutput = execSync(
67+
`oasdiff changelog ${jsonMode} ${directoryMode} ${baseApi} ${newApi}`
68+
).toString();
8169

82-
} catch (err) {
83-
console.error(err);
70+
if (oasdiffOutput.trim().length === 0) {
71+
console.log("No API changes reported by oasdiff");
72+
} else {
73+
await _saveOrLogOas(oasdiffOutput, flags);
8474
}
75+
} catch (err) {
76+
console.error(err);
77+
}
8578
}
86-

src/download/exchangeDownloader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function runFetch(
6262
export async function downloadRestApi(
6363
restApi: RestApi,
6464
destinationFolder: string = DEFAULT_DOWNLOAD_FOLDER,
65-
isOas: boolean = false
65+
isOas = false
6666
): Promise<void> {
6767
if (!restApi.id) {
6868
ramlToolLogger.warn(
@@ -108,7 +108,7 @@ export async function downloadRestApi(
108108
export async function downloadRestApis(
109109
restApi: RestApi[],
110110
destinationFolder: string = DEFAULT_DOWNLOAD_FOLDER,
111-
isOas: boolean = false
111+
isOas = false
112112
): Promise<string> {
113113
const downloads = restApi.map((api) =>
114114
downloadRestApi(api, destinationFolder, isOas)
@@ -131,7 +131,7 @@ function getFileByClassifier(files: FileInfo[], classifier: string): FileInfo {
131131
// Not all API files in anypoint exchange have an associated fat-as classifier. so
132132
// we return null here for those cases
133133
if (!found) {
134-
return null
134+
return null;
135135
}
136136
// There are extra properties we don't want (downloadURL, isGenerated), so we
137137
// create a new object that excludes them

src/download/exchangeTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type RestApi = {
1515
version?: string;
1616
categories?: Categories;
1717
fatRaml?: FileInfo;
18-
fatOas?: FileInfo
18+
fatOas?: FileInfo;
1919
};
2020

2121
export type FileInfo = {

src/generate-from-oas/generateCommand.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,56 @@
77

88
import { Command, flags } from "@oclif/command";
99
import { allCommonFlags } from "../common/flags";
10-
import { generateFromOas, DEFAULT_CONFIG_PACKAGE_PATH, DEFAULT_CONFIG_PATH } from "./generateFromOas";
10+
import {
11+
generateFromOas,
12+
DEFAULT_CONFIG_PACKAGE_PATH,
13+
DEFAULT_CONFIG_PATH,
14+
} from "./generateFromOas";
1115

1216
export class GenerateCommand extends Command {
13-
1417
static description = "Generate from OAS";
1518

1619
static flags = {
1720
...allCommonFlags(),
1821
inputSpec: flags.string({
1922
char: "i",
20-
description: 'Input OAS specification file',
23+
description: "Input OAS specification file",
2124
required: true,
2225
}),
2326
outputDir: flags.string({
2427
char: "o",
25-
description: 'Output directory for generated code',
26-
required: true,
28+
description: "Output directory for generated code",
29+
required: true,
2730
}),
2831
templateDir: flags.string({
2932
char: "t",
30-
description: 'Template directory',
33+
description: "Template directory",
3134
required: true,
3235
}),
3336
configFile: flags.string({
34-
char: "c",
35-
description: `[default:${DEFAULT_CONFIG_PACKAGE_PATH}] Configuration file with additional generator properties`
37+
char: "c",
38+
description: `[default:${DEFAULT_CONFIG_PACKAGE_PATH}] Configuration file with additional generator properties`,
3639
}),
3740
generator: flags.string({
3841
char: "g",
39-
description: '[default:typescript-fetch] Generator to use',
42+
description: "[default:typescript-fetch] Generator to use",
4043
}),
4144
skipValidateSpec: flags.boolean({
42-
description: 'Skip validation of the OAS specification',
45+
description: "Skip validation of the OAS specification",
4346
}),
4447
};
4548

4649
async run(): Promise<void> {
47-
console.log('Running generator')
50+
console.log("Running generator");
4851
const { flags } = this.parse(GenerateCommand);
49-
console.log(flags)
52+
console.log(flags);
5053
generateFromOas({
5154
inputSpec: flags.inputSpec,
5255
outputDir: flags.outputDir,
5356
templateDir: flags.templateDir,
5457
configFile: flags.configFile,
5558
generator: flags.generator,
56-
skipValidateSpec: flags.skipValidateSpec
59+
skipValidateSpec: flags.skipValidateSpec,
5760
});
5861
}
59-
}
62+
}

src/generate-from-oas/generateFromOas.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,44 @@ import path from "path";
99
import { execSync } from "child_process";
1010
import { string, boolean } from "@oclif/parser/lib/flags";
1111

12-
// Path relative to project root
13-
export const DEFAULT_CONFIG_BASE_PATH =
12+
// Path relative to project root
13+
export const DEFAULT_CONFIG_BASE_PATH =
1414
"resources/generate-from-oas/config/config.yaml";
1515

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-
);
16+
export const DEFAULT_CONFIG_PATH = path.join(
17+
__dirname,
18+
"../../",
19+
DEFAULT_CONFIG_BASE_PATH
20+
);
2821

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+
);
2928

3029
export const generateFromOas = (args: {
31-
inputSpec: string,
32-
outputDir: string,
33-
templateDir: string,
34-
configFile?: string,
35-
generator?: string,
36-
skipValidateSpec?: boolean
30+
inputSpec: string;
31+
outputDir: string;
32+
templateDir: string;
33+
configFile?: string;
34+
generator?: string;
35+
skipValidateSpec?: boolean;
3736
}) => {
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-
37+
const {
38+
inputSpec,
39+
outputDir,
40+
templateDir,
41+
configFile,
42+
generator,
43+
skipValidateSpec,
44+
} = args;
45+
const skipValidateSpecFlag = skipValidateSpec ? "--skip-validate-spec" : "";
46+
const _configFile = configFile ? configFile : DEFAULT_CONFIG_PATH;
47+
const _generator = generator ? generator : "typescript-fetch";
48+
49+
execSync(
50+
`openapi-generator-cli generate -i ${inputSpec} -o ${outputDir} -t ${templateDir} -g ${_generator} -c ${_configFile} ${skipValidateSpecFlag}`
51+
);
52+
};

0 commit comments

Comments
 (0)