Error disabling an extended ruleset in an extended ruleset
See original GitHub issueDescribe the bug When I structure my rules like so:
index.json
{
"extends": [
"rules-one.json",
"rules-two.json",
]
}
rules-one.json
{
"extends": ["spectral:oas", "off"],
"rules": {
"path-params": true
}
}
…and then load them like so:
const spectral = new Spectral();
spectral.registerFormat("oas3", isOpenApiv3);
await spectral.loadRuleset(path.resolve("***/index.json"));
I get the following error:
Error: Provided ruleset is not an object
at Object.assertValidRuleset (/***/node_modules/@stoplight/spectral/dist/rulesets/validation.js:23:15)
at processRuleset (/***/node_modules/@stoplight/spectral/dist/rulesets/reader.js:62:38)
at process._tickCallback (internal/process/next_tick.js:68:7)
This does not occur if:
- I don’t disable the
spectral:oas
rules - I extend and disable them in
index.json
instead ofrules-one.json
I also tried to extend/disable the spectral rules in index.json
and then enable specific ones in rules-one.json
but that didn’t work (they don’t get enabled).
I printed the ruleset that fails to validate and it’s an IIFE that starts with:
(function (root, factory) { if (typeof define === \"function\" && define.amd) {
To Reproduce
- Set up and load rules as described above
- Observe error
Expected behavior The rules load successfully and allow me to disable an extended ruleset, in an extended ruleset, and then selectively enable them.
Environment (remove any that are not applicable):
- Library version: 5.5.0
- OS: macOS 10.15.6
Additional context
I organised my rules to be aligned with the OAS schema objects (e.g. operation-object.json
) to keep things manageable. I want to enable specific spectral:oas
rules alongside related, custom ones.
Workaround is to extend/disable in index.json
and then enable specific rules there too.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
@P0lip, yep, that’s the issue I’m referring to.
Well … curiously … things work a bit differently if you don’t disable all the rules with
extends: [[spectral:oas, off]]
and instead disable each one individually. With that approach, you can extend the ruleset without disabled (but “recommended”) rules becoming enabled again.So it does seem like there is an inconsistency here. If
extends: [[spectral:oas, off]]
could be made to work like disabling all the rules individually, I think that would resolve the inconsistency in a way that would match most people’s expectations.