diff --git a/scripts/generate-assets.ts b/scripts/generate-assets.ts index 5acc52d6c7..702f074094 100644 --- a/scripts/generate-assets.ts +++ b/scripts/generate-assets.ts @@ -1,5 +1,5 @@ /** - * This script generates a list of assets that are needed to load spectral:oas and spectral:aas rulesets. + * This script generates a list of assets that are needed to load spectral:oas and spectral:asyncapi rulesets. * It contains all custom functions and *resolved* rulesets. * The assets are stored in a single file named `assets.json` in the following format: * `: ` @@ -30,7 +30,7 @@ const assetsPath = path.join(baseDir, `assets.json`); const generatedAssets = {}; (async () => { - for (const kind of ['oas', 'aas']) { + for (const kind of ['oas', 'asyncapi']) { await processDirectory(generatedAssets, path.join(__dirname, `../rulesets/${kind}`)); await writeFileAsync(assetsPath, JSON.stringify(generatedAssets, null, 2)); } diff --git a/scripts/generate-karma-fixtures.js b/scripts/generate-karma-fixtures.js index 4f329f9870..29bca96883 100755 --- a/scripts/generate-karma-fixtures.js +++ b/scripts/generate-karma-fixtures.js @@ -8,7 +8,7 @@ if (!fs.existsSync(baseDir)) { fs.mkdirSync(baseDir); } -for (const rulesetName of ['oas', 'aas']) { +for (const rulesetName of ['oas', 'asyncapi']) { const target = path.join(baseDir, `${rulesetName}-functions.json`); const fnsPath = path.join(__dirname, `../rulesets/${rulesetName}/functions`); const bundledFns = {}; diff --git a/setupKarma.ts b/setupKarma.ts index 142b45cbb7..c2af945a74 100644 --- a/setupKarma.ts +++ b/setupKarma.ts @@ -3,7 +3,7 @@ import { FetchMockSandbox } from 'fetch-mock'; const oasRuleset = JSON.parse(JSON.stringify(require('./rulesets/oas/index.json'))); const oasFunctions = JSON.parse(JSON.stringify(require('./__karma__/__fixtures__/oas-functions.json'))); -const aasFunctions = JSON.parse(JSON.stringify(require('./__karma__/__fixtures__/aas-functions.json'))); +const asyncApiFunctions = JSON.parse(JSON.stringify(require('./__karma__/__fixtures__/asyncapi-functions.json'))); const oas2Schema = JSON.parse(JSON.stringify(require('./rulesets/oas/schemas/schema.oas2.json'))); const oas3Schema = JSON.parse(JSON.stringify(require('./rulesets/oas/schemas/schema.oas3.json'))); @@ -31,7 +31,7 @@ beforeEach(() => { [ ['oas', oasFunctions], - ['aas', aasFunctions], + ['asyncapi', asyncApiFunctions], ].forEach(([rulesetName, funcs]) => { for (const [name, fn] of Object.entries(funcs)) { fetchMock.get(`https://unpkg.com/@stoplight/spectral/rulesets/${rulesetName}/functions/${name}`, { diff --git a/src/__tests__/generate-assets.jest.test.ts b/src/__tests__/generate-assets.jest.test.ts index b5517df5b1..aafd644490 100644 --- a/src/__tests__/generate-assets.jest.test.ts +++ b/src/__tests__/generate-assets.jest.test.ts @@ -19,7 +19,7 @@ describe('generate-assets', () => { const testCases = [ ['oas', 'oas2-schema', 'title', 'A JSON Schema for Swagger 2.0 API.'], ['oas', 'oas3-schema', 'description', 'Validation schema for OpenAPI Specification 3.0.X.'], - ['aas', 'asyncapi-schema', 'title', 'AsyncAPI 2.0.0 schema.'], + ['asyncapi', 'asyncapi-schema', 'title', 'AsyncAPI 2.0.0 schema.'], ]; it.each(testCases)( diff --git a/src/__tests__/spectral.test.ts b/src/__tests__/spectral.test.ts index 8d2a0912fb..e5aa3c903c 100644 --- a/src/__tests__/spectral.test.ts +++ b/src/__tests__/spectral.test.ts @@ -12,15 +12,15 @@ import { RulesetExceptionCollection } from '../types/ruleset'; import { buildRulesetExceptionCollectionFrom } from '../../setupTests'; const oasRuleset = JSON.parse(JSON.stringify(require('../rulesets/oas/index.json'))); -const aasRuleset = JSON.parse(JSON.stringify(require('../rulesets/aas/index.json'))); +const asyncApiRuleset = JSON.parse(JSON.stringify(require('../rulesets/asyncapi/index.json'))); const oasRulesetRules: Dictionary = oasRuleset.rules; -const aasRulesetRules: Dictionary = aasRuleset.rules; +const asyncApiRulesetRules: Dictionary = asyncApiRuleset.rules; describe('spectral', () => { describe('loadRuleset', () => { test.each([ ['spectral:oas', oasRulesetRules], - ['spectral:aas', aasRulesetRules], + ['spectral:asyncapi', asyncApiRulesetRules], ])('should support loading "%s" built-in ruleset', async (rulesetName, rules) => { const s = new Spectral(); await s.loadRuleset(rulesetName); @@ -44,7 +44,7 @@ describe('spectral', () => { test.each([ ['spectral:oas', oasRulesetRules], - ['spectral:aas', aasRulesetRules], + ['spectral:asyncapi', asyncApiRulesetRules], ])('should support loading multiple times the built-in ruleset "%s"', async (rulesetName, expectedRules) => { const s = new Spectral(); await s.loadRuleset([rulesetName, rulesetName]); diff --git a/src/assets.ts b/src/assets.ts index 4ad5486e3d..f8841fd3f0 100644 --- a/src/assets.ts +++ b/src/assets.ts @@ -6,7 +6,7 @@ function resolveSpectralRuleset(ruleset: string) { export const RESOLVE_ALIASES: Dictionary = { 'spectral:oas': resolveSpectralRuleset('oas'), - 'spectral:aas': resolveSpectralRuleset('aas'), + 'spectral:asyncapi': resolveSpectralRuleset('asyncapi'), }; export const STATIC_ASSETS: Dictionary = {}; diff --git a/src/cli/services/linter/linter.ts b/src/cli/services/linter/linter.ts index 6586b22adb..2fe75be19f 100644 --- a/src/cli/services/linter/linter.ts +++ b/src/cli/services/linter/linter.ts @@ -22,7 +22,7 @@ import { getResolver } from './utils/getResolver'; const KNOWN_FORMATS: Array<[string, FormatLookup, string]> = [ ['oas2', isOpenApiv2, 'OpenAPI 2.0 (Swagger) detected'], ['oas3', isOpenApiv3, 'OpenAPI 3.x detected'], - ['aas2', isAsyncApiv2, 'AsyncAPI 2.x detected'], + ['asyncapi2', isAsyncApiv2, 'AsyncAPI 2.x detected'], ['json-schema', isJSONSchema, 'JSON Schema detected'], ['json-schema-loose', isJSONSchemaLoose, 'JSON Schema (loose) detected'], ['json-schema-draft4', isJSONSchemaDraft4, 'JSON Schema Draft 4 detected'], diff --git a/src/cli/services/linter/utils/getRuleset.ts b/src/cli/services/linter/utils/getRuleset.ts index cfd466111b..4b8a998d3e 100644 --- a/src/cli/services/linter/utils/getRuleset.ts +++ b/src/cli/services/linter/utils/getRuleset.ts @@ -21,5 +21,5 @@ export async function getRuleset(rulesetFile: Optional) { return await (rulesetFiles ? loadRulesets(process.cwd(), Array.isArray(rulesetFiles) ? rulesetFiles : [rulesetFiles]) - : readRuleset(['spectral:oas', 'spectral:aas'])); // TODO: Rule name clashes + : readRuleset(['spectral:oas', 'spectral:asyncapi'])); } diff --git a/src/rulesets/aas/__tests__/__fixtures__/streetlights.yaml b/src/rulesets/asyncapi/__tests__/__fixtures__/streetlights.yaml similarity index 100% rename from src/rulesets/aas/__tests__/__fixtures__/streetlights.yaml rename to src/rulesets/asyncapi/__tests__/__fixtures__/streetlights.yaml diff --git a/src/rulesets/aas/__tests__/streetlights.jest.test.ts b/src/rulesets/asyncapi/__tests__/streetlights.jest.test.ts similarity index 90% rename from src/rulesets/aas/__tests__/streetlights.jest.test.ts rename to src/rulesets/asyncapi/__tests__/streetlights.jest.test.ts index 3cf88991f5..6ffce8778b 100644 --- a/src/rulesets/aas/__tests__/streetlights.jest.test.ts +++ b/src/rulesets/asyncapi/__tests__/streetlights.jest.test.ts @@ -11,10 +11,10 @@ describe('streetlights', () => { const streetlights = path.join(__dirname, './__fixtures__/streetlights.yaml'); const s = new Spectral({ resolver: httpAndFileResolver }); - s.registerFormat('aas2', isAsyncApiv2); + s.registerFormat('asyncapi2', isAsyncApiv2); test('can be linted', async () => { - await s.loadRuleset('spectral:aas'); + await s.loadRuleset('spectral:asyncapi'); const document = new Document(await readParsable(streetlights, { encoding: 'utf8' }), Parsers.Yaml, streetlights); diff --git a/src/rulesets/aas/index.json b/src/rulesets/asyncapi/index.json similarity index 94% rename from src/rulesets/aas/index.json rename to src/rulesets/asyncapi/index.json index e8ace92c89..640647bd51 100644 --- a/src/rulesets/aas/index.json +++ b/src/rulesets/asyncapi/index.json @@ -4,7 +4,7 @@ "description": "Contact object should have `name`, `url` and `email`.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "severity": 2, "type": "style", @@ -28,7 +28,7 @@ "description": "Example should have either a `value` or `externalValue` field.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$..example", @@ -46,7 +46,7 @@ "description": "Info object should contain `contact` object.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$", @@ -59,7 +59,7 @@ "description": "AsyncAPI object info `description` must be present and non-empty string.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$", @@ -75,7 +75,7 @@ "description": "AsyncAPI object info `license` must be present and non-empty string.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$", @@ -91,7 +91,7 @@ "description": "License object should include `url`.", "recommended": false, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$", @@ -104,7 +104,7 @@ "description": "AsyncAPI object should have alphabetical `tags`.", "recommended": false, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$", @@ -120,7 +120,7 @@ "description": "Operation `description` must be present and non-empty string.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$.paths.*[?( @property === 'get' || @property === 'put' || @property === 'post' || @property === 'delete' || @property === 'options' || @property === 'head' || @property === 'patch' || @property === 'trace' )]", @@ -136,7 +136,7 @@ "description": "Operation should have an `operationId`.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$.paths.*[?( @property === 'get' || @property === 'put' || @property === 'post' || @property === 'delete' || @property === 'options' || @property === 'head' || @property === 'patch' || @property === 'trace' )]", @@ -152,7 +152,7 @@ "description": "Path parameter declarations cannot be empty, ex.`/companies/{}` is invalid.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$.paths", @@ -171,7 +171,7 @@ "description": "paths should not end with a slash.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$.paths", @@ -190,7 +190,7 @@ "description": "given keys should not include a query string.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$.paths", @@ -209,7 +209,7 @@ "description": "Tag object should have a `description`.", "recommended": false, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$.tags[*]", @@ -222,7 +222,7 @@ "description": "Define at least one server.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "given": "$", "then": { @@ -240,7 +240,7 @@ "description": "Parameter objects should have a `description`.", "recommended": false, "formats": [ - "aas2" + "asyncapi2" ], "given": "$..['parameters']", "then": { @@ -255,7 +255,7 @@ "description": "Server URL should not point at example.com.", "recommended": false, "formats": [ - "aas2" + "asyncapi2" ], "given": "$.servers[*].url", "then": { @@ -269,7 +269,7 @@ "description": "Server URL should not have a trailing slash.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "given": "$.servers[*].url", @@ -286,7 +286,7 @@ "severity": 0, "recommended": false, "formats": [ - "aas2" + "asyncapi2" ], "type": "validation", "given": "$.components.schemas..[?(@property !== 'properties' && @.example && (@.type || @.format || @.$ref))]", @@ -304,7 +304,7 @@ "severity": 0, "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "validation", "given": "$", @@ -312,7 +312,7 @@ "function": "schema", "functionOptions": { "schema": { - "$ref": "./schemas/schema.aas2.json" + "$ref": "./schemas/schema.asyncapi2.json" } } } @@ -321,7 +321,7 @@ "description": "Potentially unused components schema has been detected.", "recommended": true, "formats": [ - "aas2" + "asyncapi2" ], "type": "style", "resolved": false, diff --git a/src/rulesets/aas/schemas/schema.aas2.json b/src/rulesets/asyncapi/schemas/schema.asyncapi2.json similarity index 100% rename from src/rulesets/aas/schemas/schema.aas2.json rename to src/rulesets/asyncapi/schemas/schema.asyncapi2.json diff --git a/test-harness/scenarios/rules-matching-multiple-places.scenario b/test-harness/scenarios/rules-matching-multiple-places.scenario index 9d699125a1..e412e512da 100644 --- a/test-harness/scenarios/rules-matching-multiple-places.scenario +++ b/test-harness/scenarios/rules-matching-multiple-places.scenario @@ -33,7 +33,7 @@ rules: 1 ====stdout==== {document} - 1:1 warning unrecognized-format The provided document does not match any of the registered formats [oas2, oas3, aas2, json-schema, json-schema-loose, json-schema-draft4, json-schema-draft6, json-schema-draft7, json-schema-2019-09] + 1:1 warning unrecognized-format The provided document does not match any of the registered formats [oas2, oas3, asyncapi2, json-schema, json-schema-loose, json-schema-draft4, json-schema-draft6, json-schema-draft7, json-schema-2019-09] 6:15 error valid-user-properties must match the pattern '/^string$/' 10:15 error valid-user-properties must match the pattern '/^string$/' 11:11 error require-user-and-address `address` property is not truthy diff --git a/test-harness/scenarios/unrecognized-format.scenario b/test-harness/scenarios/unrecognized-format.scenario index 99b7a28b36..1ac19f4b4e 100644 --- a/test-harness/scenarios/unrecognized-format.scenario +++ b/test-harness/scenarios/unrecognized-format.scenario @@ -7,6 +7,6 @@ info: {} {bin} lint {document} ====stdout==== {document} - 1:1 warning unrecognized-format The provided document does not match any of the registered formats [oas2, oas3, aas2, json-schema, json-schema-loose, json-schema-draft4, json-schema-draft6, json-schema-draft7, json-schema-2019-09] + 1:1 warning unrecognized-format The provided document does not match any of the registered formats [oas2, oas3, asyncapi2, json-schema, json-schema-loose, json-schema-draft4, json-schema-draft6, json-schema-draft7, json-schema-2019-09] ✖ 1 problem (0 errors, 1 warning, 0 infos, 0 hints)