Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changeset/tiny-plums-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/cli": patch
---

Fixed a hard crash when no API is provided either via the command argument or in the config.
Comment thread
JLekawa marked this conversation as resolved.
Outdated
6 changes: 0 additions & 6 deletions packages/cli/src/__tests__/commands/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ describe('handleLint', () => {
await commandWrapper(handleLint)(argvMock);
expect(checkIfRulesetExist).toHaveBeenCalledTimes(1);
});

it('should fail if apis not provided', async () => {
await commandWrapper(handleLint)({ ...argvMock, apis: [] });
expect(getFallbackApisOrExit).toHaveBeenCalledTimes(1);
expect(exitWithError).toHaveBeenCalledWith('No APIs were provided.');
});
});

describe('loop through entrypoints and lint stage', () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/cli/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ describe('getFallbackApisOrExit', async () => {
}
});

it('should exit with error when no APIs are provided and config has no apis', async () => {
const apisConfig = await openapiCore.createConfig({ apis: {} });
expect.assertions(1);
try {
await getFallbackApisOrExit([], apisConfig);
} catch (e) {
expect(e.message).toEqual(
'No APIs were provided. Specify an API via the command argument or define one in your config.'
);
}
});

it('should error if file from config do not exist', async () => {
vi.spyOn(errorHandling, 'exitWithError');
vi.mocked(fs.existsSync).mockImplementationOnce(() => false);
Expand Down
6 changes: 1 addition & 5 deletions packages/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { performance } from 'perf_hooks';
import type { Arguments } from 'yargs';

import type { CommandArgv, Totals, VerifyConfigOptions } from '../types.js';
import { AbortFlowError, exitWithError } from '../utils/error.js';
import { AbortFlowError } from '../utils/error.js';
import { getCommandNameFromArgs } from '../utils/get-command-name-from-args.js';
import {
checkIfRulesetExist,
Expand Down Expand Up @@ -47,10 +47,6 @@ export async function handleLint({
}: CommandArgs<LintArgv>) {
const apis = await getFallbackApisOrExit(argv.apis, config);

if (!apis.length) {
exitWithError('No APIs were provided.');
}

const totals: Totals = { errors: 0, warnings: 0, ignored: 0 };
let totalIgnored = 0;

Expand Down
3 changes: 0 additions & 3 deletions packages/cli/src/commands/scorecard-classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ export async function handleScorecardClassic({
}: CommandArgs<ScorecardClassicArgv>) {
const startedAt = performance.now();
const apis = await getFallbackApisOrExit(argv.api ? [argv.api] : [], config);
if (!apis.length) {
exitWithError('No APIs were provided.');
}

const projectUrl =
argv['project-url'] ||
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/utils/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export async function getFallbackApisOrExit(
}
exitWithError('Please provide a valid path.');
}
if (!res.length) {
Comment thread
AlbinaBlazhko17 marked this conversation as resolved.
Outdated
exitWithError(
'No APIs were provided. Specify an API via the command argument or define one in your config.'
);
}
return res;
}

Expand Down
Loading