-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ruleset-migrator): transform functions under overrides (#2459)
- Loading branch information
Showing
5 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/ruleset-migrator/src/__tests__/__fixtures__/overrides-variant-2/output.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { truthy } = require('@stoplight/spectral-functions'); | ||
const { oas } = require('@stoplight/spectral-rulesets'); | ||
module.exports = { | ||
extends: [oas], | ||
aliases: { | ||
OperationObject: ['#PathItem[get,put,post,delete,options,head,patch,trace]'], | ||
PathItem: ['$.paths[*]'], | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['*'], | ||
rules: { | ||
'operation-description': { | ||
given: '#OperationObject', | ||
then: { | ||
field: 'summary', | ||
function: truthy, | ||
}, | ||
severity: 'warn', | ||
}, | ||
}, | ||
}, | ||
], | ||
}; |
24 changes: 24 additions & 0 deletions
24
packages/ruleset-migrator/src/__tests__/__fixtures__/overrides-variant-2/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { truthy } from '@stoplight/spectral-functions'; | ||
import { oas } from '@stoplight/spectral-rulesets'; | ||
export default { | ||
extends: [oas], | ||
aliases: { | ||
OperationObject: ['#PathItem[get,put,post,delete,options,head,patch,trace]'], | ||
PathItem: ['$.paths[*]'], | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['*'], | ||
rules: { | ||
'operation-description': { | ||
given: '#OperationObject', | ||
then: { | ||
field: 'summary', | ||
function: truthy, | ||
}, | ||
severity: 'warn', | ||
}, | ||
}, | ||
}, | ||
], | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/ruleset-migrator/src/__tests__/__fixtures__/overrides-variant-2/ruleset.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extends: | ||
- 'spectral:oas' | ||
aliases: | ||
OperationObject: | ||
- '#PathItem[get,put,post,delete,options,head,patch,trace]' | ||
PathItem: | ||
- $.paths[*] | ||
overrides: | ||
- files: ['*'] | ||
rules: | ||
operation-description: | ||
given: '#OperationObject' | ||
then: | ||
field: 'summary' | ||
function: 'truthy' | ||
severity: warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
test-harness/scenarios/overrides/new-rule-legacy-ruleset.scenario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
====test==== | ||
Respect overrides with rules-only | ||
====asset:spectral.yaml==== | ||
aliases: | ||
OperationObject: | ||
- "#PathItem[get,put,post,delete,options,head,patch,trace]" | ||
PathItem: | ||
- $.paths[*] | ||
rules: | ||
operation-description: | ||
given: '#OperationObject' | ||
then: | ||
field: 'description' | ||
function: 'truthy' | ||
severity: error | ||
overrides: | ||
- files: ["v2/**/*.json"] | ||
rules: | ||
summary-description: | ||
given: '#OperationObject' | ||
then: | ||
field: 'summary' | ||
function: 'truthy' | ||
severity: warn | ||
====asset:v2/document.json==== | ||
{ | ||
"openapi": "3.1.0", | ||
"info": { | ||
"description": "", | ||
"title": "" | ||
}, | ||
"paths": { | ||
"/": { | ||
"get": {} | ||
} | ||
} | ||
} | ||
====asset:legacy/document.json==== | ||
{ | ||
"openapi": "3.1.0", | ||
"info": { | ||
"description": "", | ||
"title": "" | ||
}, | ||
"paths": { | ||
"/": { | ||
"get": {} | ||
} | ||
} | ||
} | ||
====command==== | ||
{bin} lint **/*.json --ruleset {asset:spectral.yaml} --fail-on-unmatched-globs | ||
====stdout==== | ||
|
||
{asset:legacy/document.json} | ||
9:13 error operation-description "get.description" property must be truthy paths./.get | ||
|
||
{asset:v2/document.json} | ||
9:13 error operation-description "get.description" property must be truthy paths./.get | ||
9:13 warning summary-description "get.summary" property must be truthy paths./.get | ||
|
||
✖ 3 problems (2 errors, 1 warning, 0 infos, 0 hints) |