Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken committed Feb 25, 2020
1 parent 65c57ab commit c076389
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/cli/services/linter/utils/getRuleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ export async function getRuleset(rulesetFile: Optional<string[]>) {

return await (rulesetFiles
? loadRulesets(process.cwd(), Array.isArray(rulesetFiles) ? rulesetFiles : [rulesetFiles])
: readRuleset('spectral:oas'));
// TODO: Should there be a default, now?
: readRuleset(['spectral:oas', 'spectral:aas'])); // TODO: Rule name clashes
}
21 changes: 13 additions & 8 deletions src/rulesets/aas/__tests__/streetlights.jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ import { Spectral } from '../../../index';
import * as Parsers from '../../../parsers';
import { httpAndFileResolver } from '../../../resolvers/http-and-file';

describe('unusedComponentsSchema - Http and fs remote references', () => {
describe('streetlights', () => {
const streetlights = path.join(__dirname, './__fixtures__/streetlights.yaml');

const s = new Spectral({ resolver: httpAndFileResolver });
s.registerFormat('aas2', isAsyncApiv2);
describe('reports unreferenced components schemas', () => {
test('when analyzing an in-memory document', async () => {
await s.loadRuleset('spectral:aas');

const document = new Document(await readParsable(streetlights, { encoding: 'utf8' }), Parsers.Yaml, streetlights);
test('can be linted', async () => {
await s.loadRuleset('spectral:aas');

const document = new Document(await readParsable(streetlights, { encoding: 'utf8' }), Parsers.Yaml, streetlights);

const results = await s.run(document);
const results = await s.run(document);

expect(results).toEqual([]);
});
expect(results).toEqual([
expect.objectContaining({
code: 'info-contact',
path: ['info'],
}),
]);
});
});
3 changes: 3 additions & 0 deletions src/rulesets/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export async function readRuleset(uris: string | string[], opts?: IRulesetReadOp
functions: {},
};

// TODO: How to deal with identical rules? (eg. path-declarations-must-exist)
// Duplicate? or create a fake core ruleset and extend?

const processedRulesets = new Set<string>();
const processRuleset = createRulesetProcessor(processedRulesets, new Cache(), opts);

Expand Down

0 comments on commit c076389

Please sign in to comment.