Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions __tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ type CLICommands =
| 'push'
| 'split'
| 'stats'
| 'build-docs'
| 'respect';
| 'build-docs';

export function getParams(
indexEntryPoint: string,
Expand Down
1 change: 1 addition & 0 deletions docs/usage-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ When a command is run, the following data is collected:
- Node.js and NPM versions
- whether the `redocly.yaml` configuration file exists
- API specification version
- Platform (Linux, macOS, Windows)

Values such as file names, organization IDs, and URLs are removed, replaced by just "URL" or "file", etc.

Expand Down
45 changes: 22 additions & 23 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
notifyUpdateCliVersion,
version,
} from './utils/update-version-notifier';
import { type CommandArgs, commandWrapper } from './wrapper';
import { commandWrapper } from './wrapper';
import { previewProject } from './commands/preview-project';
import { handleTranslations } from './commands/translations';
import { handleEject } from './commands/eject';
Expand All @@ -28,9 +28,10 @@ import { commonPushHandler } from './commands/push';

import type { Arguments } from 'yargs';
import type { OutputFormat, RuleSeverity } from '@redocly/openapi-core';
import type { GenerateArazzoFileOptions, RespectOptions } from '@redocly/respect-core';
import type { BuildDocsArgv } from './commands/build-docs/types';
import type { PushStatusOptions } from './reunite/commands/push-status';
import type { CommandOptions, PushArguments } from './types';
import type { PushArguments } from './types';
import type { EjectOptions } from './commands/eject';

dotenv.config({ path: path.resolve(process.cwd(), './.env') });
Expand Down Expand Up @@ -867,12 +868,12 @@ yargs
}
)
.command(
'respect [files..]',
'Run workflow tests',
'respect [files...]',
'Run Arazzo tests.',
(yargs) => {
return yargs
.positional('files', {
describe: 'Test files or glob pattern',
describe: 'Test files or glob pattern.',
type: 'string',
array: true,
default: [],
Expand All @@ -881,87 +882,85 @@ yargs
.options({
input: {
alias: 'i',
describe: 'Input parameters',
describe: 'Input parameters.',
type: 'string',
},
server: {
alias: 'S',
describe: 'Server parameters',
describe: 'Server parameters.',
type: 'string',
},
workflow: {
alias: 'w',
describe: 'Workflow name',
describe: 'Workflow name.',
type: 'string',
array: true,
},
skip: {
alias: 's',
describe: 'Workflow to skip',
describe: 'Workflow to skip.',
type: 'string',
array: true,
},
verbose: {
alias: 'v',
describe: 'Apply verbose mode',
describe: 'Apply verbose mode.',
type: 'boolean',
},
'har-output': {
describe: 'Har file output name',
describe: 'Har file output name.',
type: 'string',
},
'json-output': {
describe: 'JSON file output name',
describe: 'JSON file output name.',
type: 'string',
},
'client-cert': {
describe: 'Mutual TLS client certificate',
describe: 'Mutual TLS client certificate.',
type: 'string',
},
'client-key': {
describe: 'Mutual TLS client key',
describe: 'Mutual TLS client key.',
type: 'string',
},
'ca-cert': {
describe: 'Mutual TLS CA certificate',
describe: 'Mutual TLS CA certificate.',
type: 'string',
},
severity: {
describe: 'Severity of the check',
describe: 'Severity of the check.',
type: 'string',
},
});
},
async (argv) => {
process.env.REDOCLY_CLI_COMMAND = 'respect';
const { handleRun } = await import('@redocly/respect-core');
commandWrapper(handleRun)(argv);
commandWrapper(handleRun)(argv as Arguments<RespectOptions>);
}
)
.command(
'generate-arazzo <descriptionPath>',
'Auto-generate test config file from description',
'Auto-generate arazzo description file from an API description.',
(yargs) => {
return yargs
.positional('descriptionPath', {
describe: 'Description file path',
describe: 'Description file path.',
type: 'string',
})
.env('REDOCLY_CLI_RESPECT')
.options({
'output-file': {
alias: 'o',
describe: 'Output File name',
describe: 'Output File name.',
type: 'string',
},
});
},
async (argv) => {
process.env.REDOCLY_CLI_COMMAND = 'generate-arazzo';
const { handleGenerate } = await import('@redocly/respect-core');
commandWrapper(
handleGenerate as (wrapperArgs: CommandArgs<CommandOptions>) => Promise<unknown>
)(argv);
commandWrapper(handleGenerate)(argv as Arguments<GenerateArazzoFileOptions>);
}
)
.completion('completion', 'Generate autocomplete script for `redocly` command.')
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BundleOutputFormat, Region, Config, RuleSeverity } from '@redocly/openapi-core';
import type { RespectOptions, GenerateArazzoFileOptions } from '@redocly/respect-core';
import type { ArgumentsCamelCase } from 'yargs';
import type { LintOptions } from './commands/lint';
import type { BundleOptions } from './commands/bundle';
Expand Down Expand Up @@ -43,7 +44,9 @@ export type CommandOptions =
| PushStatusOptions
| PreviewProjectOptions
| TranslationsOptions
| EjectOptions;
| EjectOptions
| RespectOptions
| GenerateArazzoFileOptions;

export type VerifyConfigOptions = {
config?: string;
Expand Down
13 changes: 8 additions & 5 deletions packages/respect-core/src/handlers/generate.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
import { blue, yellow, gray } from 'colorette';
import { writeFileSync } from 'fs';
import { stringifyYaml } from '../utils/yaml';
import { generateTestConfig } from '../modules/test-config-generator';
import { generateArazzoDescription } from '../modules/arazzo-description-generator';
import { DefaultLogger } from '../utils/logger/logger';
import { exitWithError } from '../utils/exit-with-error';
import { type CommandArgs } from '../types';

export type GenerateArazzoFileOptions = {
descriptionPath: string;
'output-file'?: string;
config?: never;
};

const logger = DefaultLogger.getInstance();

export async function handleGenerate({ argv }: CommandArgs<GenerateArazzoFileOptions>) {
try {
logger.log(gray('\n Generating test configuration... \n'));
logger.log(gray('\n Generating Arazzo description... \n'));

const generatedConfig = await generateTestConfig(argv);
const generatedConfig = await generateArazzoDescription(argv);
const content = stringifyYaml(generatedConfig);

const fileName = argv['output-file'] || 'auto-generated.arazzo.yaml';
writeFileSync(fileName, content);

logger.log('\n' + blue(`Config ${yellow(fileName)} successfully generated.`) + '\n');
logger.log(
'\n' + blue(`Arazzo description ${yellow(fileName)} successfully generated.`) + '\n'
);
} catch (_err) {
exitWithError('\n' + '❌ Auto config generation failed.');
exitWithError('\n' + '❌ Arazzo description generation failed.');
}
}
1 change: 1 addition & 0 deletions packages/respect-core/src/handlers/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type RespectOptions = {
'client-key'?: string;
'ca-cert'?: string;
severity?: string;
config?: never;
};

const logger = DefaultLogger.getInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TestDescription } from '../../../types';

import { cleanupTestDescription } from '../../test-config-generator';
import { cleanupTestDescription } from '../../arazzo-description-generator';

describe('cleanupTestDescription', () => {
it('should cleanup sensitive information from a test config', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateTestConfig } from '../../test-config-generator';
import { generateArazzoDescription } from '../../arazzo-description-generator';
import {
bundleOpenApi,
getOperationFromDescription,
Expand Down Expand Up @@ -41,11 +41,11 @@ const BUNDLED_DESCRIPTION_MOCK = {
},
};

describe('generateTestConfig', () => {
describe('generateArazzoDescription', () => {
it('should generate test config when output file is provided', async () => {
(bundleOpenApi as jest.Mock).mockReturnValue(BUNDLED_DESCRIPTION_MOCK);
expect(
await generateTestConfig({
await generateArazzoDescription({
descriptionPath: 'description.yaml',
'output-file': './final-test-location/output.yaml',
})
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('generateTestConfig', () => {
});

expect(
await generateTestConfig({
await generateArazzoDescription({
descriptionPath: 'description.yaml',
})
).toEqual({
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('generateTestConfig', () => {
it('should generate test config with not existing description', async () => {
(bundleOpenApi as jest.Mock).mockReturnValue(undefined);
expect(
await generateTestConfig({
await generateArazzoDescription({
descriptionPath: 'description.yaml',
})
).toEqual({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Parameter } from '../../../types';

import { generateExampleValue } from '../../test-config-generator';
import { generateExampleValue } from '../../arazzo-description-generator';

describe('generateExampleValue', () => {
it('should generate example value from parameter example', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Sampler from 'openapi-sampler';

import { DefaultLogger } from '../../../utils/logger/logger';
import { generateTestDataFromJsonSchema } from '../../test-config-generator';
import { generateTestDataFromJsonSchema } from '../../arazzo-description-generator';

const logger = DefaultLogger.getInstance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function resolveDescriptionNameFromPath(descriptionPath: string): string {
return path.parse(descriptionPath).name;
}

export async function generateTestConfig({
export async function generateArazzoDescription({
descriptionPath,
'output-file': outputFile,
}: GenerateArazzoFileOptions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './generate-test-config';
export * from './generate-arazzo-description';
export * from './cleanup-test-description';
export * from './generate-test-data-from-json-schema';
export * from './generate-example-value';
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { isPlainObject } from '@redocly/openapi-core/lib/utils';
import { generateTestDataFromJsonSchema, generateExampleValue } from '../test-config-generator';
import {
generateTestDataFromJsonSchema,
generateExampleValue,
} from '../arazzo-description-generator';
import { extractFirstExample } from './extract-first-example';
import { isParameterWithIn } from '../config-parser';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { type ApiFetcher } from '../../../utils/api-fetcher';
import { bundleOpenApi } from '../../description-parser';
import { createFaker } from '../../faker';
import { infoSubstitute } from '../../test-config-generator';
import { infoSubstitute } from '../../arazzo-description-generator';
import { formatCliInputs } from '../inputs';
import { bundleArazzo } from '../get-test-description-from-file';
import { readEnvVariables } from '../read-env-variables';
Expand Down
Loading