Closed jquick-axway closed 2 months ago
Yes, I can change the "extends" to a URL of the owasp/aws ruleset. (Although my goal is to let people upload a ruleset as-is.)
But I see this as a module resolution issue. Spectral changing something like...
@stoplight/spectral-owasp-ruleset
...to...
<MyRulesetBaseUrl>/@stoplight/spectral-owasp-ruleset
...isn't going to work unless you duplicate that ruleset on the server "without" the yaml file extension. And like you said, the remote custom JS functions support importing what's locally npm intsalled (which is a behavior I'm also depending on).
Closing as expected.
Checklist
Does this PR introduce a breaking change?
Summary: A remotely loaded ruleset will fail to load if it
extends
an npm/yarn installed ruleset such as:"@stoplight/spectral-owasp-ruleset"
"spectral-aws-apigateway-ruleset"
This is NOT an issue if the remote ruleset extends core rulesets "spectral:oas" and "spectral:asyncapi" because of the check here.
Cause: In the
resolveModule()
method, thepath.isURL(ctx.filepath)
check will return true for a remote ruleset and not bother to check if the module/identifier is an npm installed module via therequireResolve()
method. This causes the npm installed module to wrongly resolve to a relative URL path and 404.Notes: The
isPackageImport()
method will wrongly return true if my remote ruleset extends another ruleset in the same remote path. So, I'm testing the identifier if it is in fact installed viarequireResolve()
.We also can't assume all module names will be prefixed
@
, because it would fail to findspectral-aws-apigateway-ruleset
.Steps to reproduce:
npm install --save -D @stoplight/spectral-owasp-ruleset
spectral lint -r https://raw.githubusercontent.com/jquick-axway/spectral-test-rulesets/main/api-linting/owasp.yaml https://raw.githubusercontent.com/jquick-axway/spectral-test-rulesets/main/api-linting/tests/openapi-v3.json
@stoplight/spectral-owasp-ruleset
is resolving to a URL instead of the npm locally installed module.Could not load https://raw.githubusercontent.com/jquick-axway/spectral-test-rulesets/main/api-linting/@stoplight/spectral-owasp-ruleset (imported by https://raw.githubusercontent.com/jquick-axway/spectral-test-rulesets/main/api-linting/.spectral.js): Error fetching https://raw.githubusercontent.com/jquick-axway/spectral-test-rulesets/main/api-linting/@stoplight/spectral-owasp-ruleset: Not Found