Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into fix/cli/yarn-dep
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Oct 24, 2022
2 parents e842622 + b4c3c11 commit 0dfa021
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"@stoplight/json": "~3.20.1",
"@stoplight/path": "1.3.2",
"@stoplight/spectral-core": "^1.14.1",
"@stoplight/spectral-core": "^1.15.1",
"@stoplight/spectral-parsers": "^1.0.2",
"@stoplight/spectral-ref-resolver": "1.0.2",
"@stoplight/spectral-ruleset-bundler": "^1.4.0",
Expand Down
41 changes: 40 additions & 1 deletion packages/cli/src/services/__tests__/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ describe('Linter service', () => {
.persist()
.get('/ruleset.json')
.replyWithFile(200, join(__dirname, '__fixtures__/ruleset.json'), {
'Content-Type': 'application/yaml',
'Content-Type': 'application/json',
});

const output = await run(`lint ${validOas3SpecPath} -r http://foo.local/ruleset.json`);
Expand All @@ -326,6 +326,45 @@ describe('Linter service', () => {
]),
);
});

it('fallbacks to Content-Type', async () => {
nock('http://foo.local')
.persist()
.get('/ruleset')
.replyWithFile(200, join(__dirname, '__fixtures__/ruleset.json'), {
'Content-Type': 'application/json',
});

const output = await run(`lint ${validOas3SpecPath} -r http://foo.local/ruleset`);
expect(output).toEqual(expect.arrayContaining([expect.objectContaining({ code: 'info-matches-stoplight' })]));
expect(output).toEqual(
expect.not.arrayContaining([
expect.objectContaining({
message: 'Info object should contain `contact` object',
}),
]),
);
});

it('ignores query parameters', async () => {
nock('http://foo.local')
.persist()
.get('/ruleset.json')
.query({ token: 'bar' })
.replyWithFile(200, join(__dirname, '__fixtures__/ruleset.json'), {
'Content-Type': 'text/plain', // GitHub raw like
});

const output = await run(`lint ${validOas3SpecPath} -r http://foo.local/ruleset.json?token=bar`);
expect(output).toEqual(expect.arrayContaining([expect.objectContaining({ code: 'info-matches-stoplight' })]));
expect(output).toEqual(
expect.not.arrayContaining([
expect.objectContaining({
message: 'Info object should contain `contact` object',
}),
]),
);
});
});
});

Expand Down
8 changes: 2 additions & 6 deletions packages/cli/src/services/linter/utils/getRuleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from '@stoplight/path';
import * as process from 'process';
import { createRequire } from 'module';
import { fetch } from '@stoplight/spectral-runtime';
import { migrateRuleset } from '@stoplight/spectral-ruleset-migrator';
import { migrateRuleset, isBasicRuleset } from '@stoplight/spectral-ruleset-migrator';
import { bundleRuleset } from '@stoplight/spectral-ruleset-bundler';
import { node } from '@stoplight/spectral-ruleset-bundler/presets/node';
import { commonjs } from '@stoplight/spectral-ruleset-bundler/plugins/commonjs';
Expand All @@ -25,10 +25,6 @@ async function getDefaultRulesetFile(): Promise<Optional<string>> {
return;
}

function isBasicRuleset(filepath: string): boolean {
return /\.(json|ya?ml)$/.test(path.extname(filepath));
}

function isErrorWithCode(error: Error | (Error & { code: unknown })): error is Error & { code: string } {
return 'code' in error && typeof error.code === 'string';
}
Expand All @@ -49,7 +45,7 @@ export async function getRuleset(rulesetFile: Optional<string>): Promise<Ruleset
let ruleset: string;

try {
if (isBasicRuleset(rulesetFile)) {
if (await isBasicRuleset(rulesetFile)) {
const migratedRuleset = await migrateRuleset(rulesetFile, {
format: 'esm',
fs,
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2479,7 +2479,7 @@ __metadata:
dependencies:
"@stoplight/json": ~3.20.1
"@stoplight/path": 1.3.2
"@stoplight/spectral-core": ^1.14.1
"@stoplight/spectral-core": ^1.15.1
"@stoplight/spectral-parsers": ^1.0.2
"@stoplight/spectral-ref-resolver": 1.0.2
"@stoplight/spectral-ruleset-bundler": ^1.4.0
Expand Down Expand Up @@ -2513,7 +2513,7 @@ __metadata:
languageName: unknown
linkType: soft

"@stoplight/spectral-core@*, @stoplight/spectral-core@>=1, @stoplight/spectral-core@^1.14.1, @stoplight/spectral-core@^1.7.0, @stoplight/spectral-core@^1.8.0, @stoplight/spectral-core@^1.8.1, @stoplight/spectral-core@workspace:packages/core":
"@stoplight/spectral-core@*, @stoplight/spectral-core@>=1, @stoplight/spectral-core@^1.15.1, @stoplight/spectral-core@^1.7.0, @stoplight/spectral-core@^1.8.0, @stoplight/spectral-core@^1.8.1, @stoplight/spectral-core@workspace:packages/core":
version: 0.0.0-use.local
resolution: "@stoplight/spectral-core@workspace:packages/core"
dependencies:
Expand Down

0 comments on commit 0dfa021

Please sign in to comment.