Skip to content

Commit bcfa738

Browse files
fix: kebab case command options & mtls path & remove residensy (#1925)
1 parent cea202a commit bcfa738

File tree

16 files changed

+134
-159
lines changed

16 files changed

+134
-159
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
statements: 84,
2828
branches: 74,
2929
functions: 84,
30-
lines: 85,
30+
lines: 84,
3131
},
3232
},
3333
testMatch: ['**/__tests__/**/*.test.ts', '**/*.test.ts'],

packages/cli/src/index.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
notifyUpdateCliVersion,
2020
version,
2121
} from './utils/update-version-notifier';
22-
import { commandWrapper } from './wrapper';
22+
import { type CommandArgs, commandWrapper } from './wrapper';
2323
import { previewProject } from './commands/preview-project';
2424
import { handleTranslations } from './commands/translations';
2525
import { handleEject } from './commands/eject';
@@ -30,7 +30,7 @@ import type { Arguments } from 'yargs';
3030
import type { OutputFormat, RuleSeverity } from '@redocly/openapi-core';
3131
import type { BuildDocsArgv } from './commands/build-docs/types';
3232
import type { PushStatusOptions } from './reunite/commands/push-status';
33-
import type { PushArguments } from './types';
33+
import type { CommandOptions, PushArguments } from './types';
3434
import type { EjectOptions } from './commands/eject';
3535

3636
dotenv.config({ path: path.resolve(process.cwd(), './.env') });
@@ -914,11 +914,6 @@ yargs
914914
describe: 'JSON file output name',
915915
type: 'string',
916916
},
917-
residency: {
918-
describe: 'Residency of Reunite application. Defaults to US.',
919-
type: 'string',
920-
default: 'us',
921-
},
922917
'client-cert': {
923918
describe: 'Mutual TLS client certificate',
924919
type: 'string',
@@ -964,21 +959,15 @@ yargs
964959
'Generate config with populated values from description using success criteria',
965960
type: 'boolean',
966961
},
967-
residency: {
968-
describe: 'Residency of Reunite application. Defaults to US.',
969-
type: 'string',
970-
default: 'us',
971-
},
972962
});
963+
},
964+
async (argv) => {
965+
process.env.REDOCLY_CLI_COMMAND = 'generate-arazzo';
966+
const { handleGenerate } = await import('@redocly/respect-core');
967+
commandWrapper(
968+
handleGenerate as (wrapperArgs: CommandArgs<CommandOptions>) => Promise<unknown>
969+
)(argv);
973970
}
974-
// async (argv) => {
975-
// try {
976-
// await handleGenerate(argv as GenerateConfigFileArgv);
977-
// } catch {
978-
// logger.error(`❌ Auto config generation failed.`);
979-
// process.exit(1);
980-
// }
981-
// },
982971
)
983972
.completion('completion', 'Generate autocomplete script for `redocly` command.')
984973
.demandCommand(1)

packages/respect-core/src/handlers/generate.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,29 @@ import { writeFileSync } from 'fs';
33
import { stringifyYaml } from '../utils/yaml';
44
import { generateTestConfig } from '../modules/test-config-generator';
55
import { DefaultLogger } from '../utils/logger/logger';
6+
import { exitWithError } from '../utils/exit-with-error';
7+
import { type CommandArgs } from '../types';
68

7-
import type { GenerateConfigFileArgv } from '../types';
9+
export type GenerateArazzoFileOptions = {
10+
descriptionPath: string;
11+
'output-file'?: string;
12+
extended?: boolean;
13+
};
814

915
const logger = DefaultLogger.getInstance();
1016

11-
export async function handleGenerate(argv: GenerateConfigFileArgv) {
12-
logger.log(gray('\n Generating test configuration... \n'));
17+
export async function handleGenerate({ argv }: CommandArgs<GenerateArazzoFileOptions>) {
18+
try {
19+
logger.log(gray('\n Generating test configuration... \n'));
1320

14-
const generatedConfig = await generateTestConfig(argv as GenerateConfigFileArgv);
15-
const content = stringifyYaml(generatedConfig);
21+
const generatedConfig = await generateTestConfig(argv);
22+
const content = stringifyYaml(generatedConfig);
1623

17-
const fileName = argv?.outputFile || 'auto-generated.yaml';
18-
writeFileSync(fileName, content);
24+
const fileName = argv['output-file'] || 'auto-generated.arazzo.yaml';
25+
writeFileSync(fileName, content);
1926

20-
logger.log('\n' + blue(`Config ${yellow(fileName)} successfully generated.`) + '\n');
27+
logger.log('\n' + blue(`Config ${yellow(fileName)} successfully generated.`) + '\n');
28+
} catch (_err) {
29+
exitWithError('\n' + '❌ Auto config generation failed.');
30+
}
2131
}

packages/respect-core/src/handlers/run.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { bgRed, red } from 'colorette';
1+
import { red } from 'colorette';
2+
import { type CollectFn } from '@redocly/openapi-core/src/utils';
23
import { runTestFile } from '../modules/flow-runner';
34
import {
45
displayErrors,
@@ -7,17 +8,8 @@ import {
78
calculateTotals,
89
} from '../modules/cli-output';
910
import { DefaultLogger } from '../utils/logger/logger';
10-
11-
import type { Config } from '@redocly/openapi-core';
12-
import type { CollectFn } from '@redocly/openapi-core/src/utils';
13-
import type { RunArgv } from '../types';
14-
15-
export type CommandArgs<T> = {
16-
argv: T;
17-
config: Config;
18-
version: string;
19-
collectSpecData?: CollectFn;
20-
};
11+
import { type CommandArgs, type RunArgv } from '../types';
12+
import { exitWithError } from '../utils/exit-with-error';
2113

2214
export type RespectOptions = {
2315
files: string[];
@@ -28,7 +20,6 @@ export type RespectOptions = {
2820
verbose?: boolean;
2921
'har-output'?: string;
3022
'json-output'?: string;
31-
residency?: string;
3223
'client-cert'?: string;
3324
'client-key'?: string;
3425
'ca-cert'?: string;
@@ -113,9 +104,3 @@ async function runFile(
113104

114105
return { hasProblems, file: argv.file, workflows, argv };
115106
}
116-
117-
const exitWithError = (message: string) => {
118-
logger.error(bgRed(message));
119-
logger.printNewLine();
120-
throw new Error(message);
121-
};

packages/respect-core/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export { handleGenerate, handleRun } from './handlers/index';
2+
export type { GenerateArazzoFileOptions } from './handlers/generate';
3+
export type { RespectOptions } from './handlers/run';

packages/respect-core/src/modules/__tests__/flow-runner/context/create-test-context.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ describe('createTestContext', () => {
553553
const options: AppOptions = {
554554
workflowPath: 'test.test.yaml',
555555
workflow: undefined,
556-
harLogsFile: 'har-output',
556+
harOutput: 'har-output',
557557
metadata: {},
558558
verbose: false,
559559
};
@@ -597,7 +597,7 @@ describe('createTestContext', () => {
597597
input: JSON.stringify({ testInput: 'testValue' }),
598598
workflow: undefined,
599599
skip: undefined,
600-
harLogsFile: 'har-output',
600+
harOutput: 'har-output',
601601
metadata: {},
602602
verbose: false,
603603
};

packages/respect-core/src/modules/__tests__/test-config-generator/generate-test-config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('generateTestConfig', () => {
9090
expect(
9191
await generateTestConfig({
9292
descriptionPath: 'description.yaml',
93-
outputFile: './final-test-location/output.yaml',
93+
'output-file': './final-test-location/output.yaml',
9494
extended: false,
9595
})
9696
).toEqual({

packages/respect-core/src/modules/flow-runner/context/create-test-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export async function createTestContext(
8282
secretFields: new Set<string>(),
8383
mtlsCerts:
8484
options.mutualTls?.clientCert || options.mutualTls?.clientKey || options.mutualTls?.caCert
85-
? resolveMtlsCertificates(options.mutualTls)
85+
? resolveMtlsCertificates(options.mutualTls, options.workflowPath)
8686
: undefined,
8787
severity: resolveSeverityConfiguration(options.severity),
8888
apiClient,

packages/respect-core/src/modules/flow-runner/runner.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export async function runTestFile(
4747
input,
4848
skip,
4949
server,
50-
harOutput,
51-
jsonOutput,
50+
'har-output': harOutput,
51+
'json-output': jsonOutput,
5252
severity,
5353
} = argv;
5454

@@ -64,9 +64,9 @@ export async function runTestFile(
6464
server,
6565
severity,
6666
mutualTls: {
67-
clientCert: argv?.clientCert,
68-
clientKey: argv?.clientKey,
69-
caCert: argv?.caCert,
67+
clientCert: argv['client-cert'],
68+
clientKey: argv['client-key'],
69+
caCert: argv['ca-cert'],
7070
},
7171
};
7272

@@ -98,7 +98,7 @@ export async function runTestFile(
9898
}
9999

100100
async function runWorkflows(testDescription: TestDescription, options: AppOptions) {
101-
const harLogs = options.metadata?.harOutput && createHarLog();
101+
const harLogs = options?.harOutput && createHarLog();
102102
const apiClient = new ApiFetcher({
103103
harLogs,
104104
});
@@ -123,7 +123,7 @@ async function runWorkflows(testDescription: TestDescription, options: AppOption
123123
}
124124

125125
// json logs should be composed after all workflows are run
126-
const jsonLogs = options.jsonLogsFile ? composeJsonLogs(ctx) : undefined;
126+
const jsonLogs = options.jsonOutput ? composeJsonLogs(ctx) : undefined;
127127

128128
return { ...ctx, harLogs, jsonLogs };
129129
}

packages/respect-core/src/modules/test-config-generator/generate-test-config.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ import * as path from 'path';
22
import { sortMethods } from '../../utils/sort';
33
import { bundleOpenApi } from '../description-parser';
44

5-
import type {
6-
OperationMethod,
7-
TestDescription,
8-
GenerateConfigFileArgv,
9-
Workflow,
10-
Step,
11-
} from '../../types';
5+
import type { OperationMethod, TestDescription, Workflow, Step } from '../../types';
6+
import type { GenerateArazzoFileOptions } from '../../handlers/generate';
127

138
type WorkflowsFromDescriptionInput = {
149
descriptionPaths: any;
@@ -102,9 +97,9 @@ function resolveDescriptionNameFromPath(descriptionPath: string): string {
10297

10398
export async function generateTestConfig({
10499
descriptionPath,
105-
outputFile,
100+
'output-file': outputFile,
106101
extended,
107-
}: GenerateConfigFileArgv) {
102+
}: GenerateArazzoFileOptions) {
108103
const { paths: pathsObject, info } = (await bundleOpenApi(descriptionPath, '')) || {};
109104
const sourceDescriptionName = resolveDescriptionNameFromPath(descriptionPath);
110105
const resolvedDescriptionPath = outputFile

0 commit comments

Comments
 (0)