From 724f8fd501c0740923d7172172296fc616ba6935 Mon Sep 17 00:00:00 2001 From: Nicholas Lim <18374483+niclim@users.noreply.github.com> Date: Fri, 29 Sep 2023 07:42:25 -0400 Subject: [PATCH] fix spectral ruleset addedOrChanged and changed (#2353) --- package.json | 2 +- projects/fastify-capture/package.json | 2 +- projects/json-pointer-helpers/package.json | 2 +- projects/openapi-io/package.json | 2 +- projects/openapi-utilities/package.json | 2 +- projects/optic/package.json | 2 +- projects/rulesets-base/package.json | 2 +- projects/standard-rulesets/package.json | 2 +- .../standard-rulesets/src/spectral/index.ts | 35 ++++++++++++++++++- 9 files changed, 42 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 79fd6175d6..ac6a25710a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "openapi-workspaces", "license": "MIT", "private": true, - "version": "0.50.4", + "version": "0.50.5", "workspaces": [ "projects/json-pointer-helpers", "projects/openapi-io", diff --git a/projects/fastify-capture/package.json b/projects/fastify-capture/package.json index c2da13cba0..7a71416bf7 100644 --- a/projects/fastify-capture/package.json +++ b/projects/fastify-capture/package.json @@ -2,7 +2,7 @@ "name": "@useoptic/fastify-capture", "license": "MIT", "packageManager": "yarn@3.6.3", - "version": "0.50.4", + "version": "0.50.5", "main": "build/index.js", "types": "build/index.d.ts", "files": [ diff --git a/projects/json-pointer-helpers/package.json b/projects/json-pointer-helpers/package.json index 135dcaf905..6975fcabc4 100644 --- a/projects/json-pointer-helpers/package.json +++ b/projects/json-pointer-helpers/package.json @@ -2,7 +2,7 @@ "name": "@useoptic/json-pointer-helpers", "license": "MIT", "packageManager": "yarn@3.6.3", - "version": "0.50.4", + "version": "0.50.5", "main": "build/index.js", "types": "build/index.d.ts", "files": [ diff --git a/projects/openapi-io/package.json b/projects/openapi-io/package.json index 8dce20bf82..5286028bc0 100644 --- a/projects/openapi-io/package.json +++ b/projects/openapi-io/package.json @@ -2,7 +2,7 @@ "name": "@useoptic/openapi-io", "license": "MIT", "packageManager": "yarn@3.6.3", - "version": "0.50.4", + "version": "0.50.5", "main": "build/index.js", "types": "build/index.d.ts", "files": [ diff --git a/projects/openapi-utilities/package.json b/projects/openapi-utilities/package.json index 852f797534..bff11cde8c 100644 --- a/projects/openapi-utilities/package.json +++ b/projects/openapi-utilities/package.json @@ -2,7 +2,7 @@ "name": "@useoptic/openapi-utilities", "license": "MIT", "packageManager": "yarn@3.6.3", - "version": "0.50.4", + "version": "0.50.5", "main": "build/index.js", "types": "build/index.d.ts", "files": [ diff --git a/projects/optic/package.json b/projects/optic/package.json index f631f3a3bc..1b541fdb81 100644 --- a/projects/optic/package.json +++ b/projects/optic/package.json @@ -2,7 +2,7 @@ "name": "@useoptic/optic", "license": "MIT", "packageManager": "yarn@3.6.3", - "version": "0.50.4", + "version": "0.50.5", "main": "build/index.js", "types": "build/index.d.ts", "files": [ diff --git a/projects/rulesets-base/package.json b/projects/rulesets-base/package.json index fe8c25b23a..3435f16439 100644 --- a/projects/rulesets-base/package.json +++ b/projects/rulesets-base/package.json @@ -2,7 +2,7 @@ "name": "@useoptic/rulesets-base", "license": "MIT", "packageManager": "yarn@3.6.3", - "version": "0.50.4", + "version": "0.50.5", "main": "build/index.js", "types": "build/index.d.ts", "files": [ diff --git a/projects/standard-rulesets/package.json b/projects/standard-rulesets/package.json index 8532e8bcfc..3b4977e1b3 100644 --- a/projects/standard-rulesets/package.json +++ b/projects/standard-rulesets/package.json @@ -2,7 +2,7 @@ "name": "@useoptic/standard-rulesets", "license": "MIT", "packageManager": "yarn@3.6.3", - "version": "0.50.4", + "version": "0.50.5", "main": "build/index.js", "types": "build/index.d.ts", "files": [ diff --git a/projects/standard-rulesets/src/spectral/index.ts b/projects/standard-rulesets/src/spectral/index.ts index f069a4e1d9..f26dc62d4d 100644 --- a/projects/standard-rulesets/src/spectral/index.ts +++ b/projects/standard-rulesets/src/spectral/index.ts @@ -196,8 +196,41 @@ export class SpectralRulesets extends ExternalRuleBase { matches: this.options.matches, }); }); + const changed = this.options.changed.map((ruleInput) => { + return new SpectralRule({ + name: + 'Spectral Rules applied to changes to the specification: ' + + ruleInput, + flatSpecFile: absolutePathTmpSpec, + applies: 'changed', + rulesetPointer: ruleInput, + matches: this.options.matches, + }); + }); + const addedOrChanged = this.options.addedOrChanged.flatMap((ruleInput) => { + return [ + new SpectralRule({ + name: + 'Spectral Rules applied to additions to the specification: ' + + ruleInput, + flatSpecFile: absolutePathTmpSpec, + applies: 'added', + rulesetPointer: ruleInput, + matches: this.options.matches, + }), + new SpectralRule({ + name: + 'Spectral Rules applied to changes to the specification: ' + + ruleInput, + flatSpecFile: absolutePathTmpSpec, + applies: 'changed', + rulesetPointer: ruleInput, + matches: this.options.matches, + }), + ]; + }); - const allRulesets = [...always, ...added]; + const allRulesets = [...always, ...added, ...changed, ...addedOrChanged]; const allResults = await Promise.all( allRulesets.map((ruleset) => ruleset.runRulesV2(inputs))