From c076389d69350fc57ca5ddc77935fcf52ded30e6 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 24 Feb 2020 18:45:39 +0100 Subject: [PATCH] fixup! WIP --- src/cli/services/linter/utils/getRuleset.ts | 3 +-- .../aas/__tests__/streetlights.jest.test.ts | 21 ++++++++++++------- src/rulesets/reader.ts | 3 +++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/cli/services/linter/utils/getRuleset.ts b/src/cli/services/linter/utils/getRuleset.ts index ffde38e5de..a0ad0dade3 100644 --- a/src/cli/services/linter/utils/getRuleset.ts +++ b/src/cli/services/linter/utils/getRuleset.ts @@ -20,6 +20,5 @@ export async function getRuleset(rulesetFile: Optional) { 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 } diff --git a/src/rulesets/aas/__tests__/streetlights.jest.test.ts b/src/rulesets/aas/__tests__/streetlights.jest.test.ts index b3457bbb02..8d85cb6163 100644 --- a/src/rulesets/aas/__tests__/streetlights.jest.test.ts +++ b/src/rulesets/aas/__tests__/streetlights.jest.test.ts @@ -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'], + }), + ]); }); }); diff --git a/src/rulesets/reader.ts b/src/rulesets/reader.ts index d424da611b..9042176142 100644 --- a/src/rulesets/reader.ts +++ b/src/rulesets/reader.ts @@ -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(); const processRuleset = createRulesetProcessor(processedRulesets, new Cache(), opts);