IBM/openapi-validator

feature request: Find a way to extend the spectral default ruleset without installing it local

Closed this issue · 1 comments

Blaimi commented

To extend the @ibm-cloud/openapi-ruleset in the spectral-file, it is necessary to install the ruleset into the project which is checked. (see also the customization documentation)

An extension of the default spectral ruleset spectral:oas can be done without any local installation.

It would be nice to be able to extend the default ibm ruleset without having to run npm install @ibm-cloud/openapi-ruleset especially if rules only needs to be disabled and the users want to run the checks in a container based environment.

Resolving of the upstream included rules is done in spectral's extends.ts.

I'm not experienced enough in typescript to find out how this can be done. This may even need a upstream patch first to be able to register custom rulesets to be able to extend them later.

Hey @Blaimi, thanks for the issue. I very much understand the desire for this feature so I spent some time on Friday investigating how we might approach it but unfortunately, I don't believe it can be done.

Spectral performs this lookup in their own code and there isn't a plugin point for us to be able to add ours. They can give special treatment to their own ruleset by bundling it, like you mentioned.

This may even need a upstream patch first to be able to register custom rulesets to be able to extend them later.

This would probably be the only realistic avenue - getting Spectral to add a feature to support this - but I doubt it would be trivial and I don't know what the priority would be on their end. They seem to have intentionally solved the custom ruleset loading by relying on NPM or local file systems.

So, right now, the only way around a separate dependency is to use the ruleset installed with the validator in your local file system like so:

extends: <path-to-validator>/node_modules/@ibm-cloud/openapi-ruleset/src/ibm-oas.js

I'm going to close, as we're not able to put additional work into this at the moment.