New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): support JSON ruleset validation #2062
Conversation
@@ -0,0 +1,65 @@ | |||
import { ErrorObject } from 'ajv'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not a new code, it was copied over from packages/core/src/ruleset/validation.ts
@@ -0,0 +1,33 @@ | |||
import { isPlainObject } from '@stoplight/json'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copied over from packages/core/src/ruleset/validation.ts
, the only change is the addition of format
in assertValidRuleset
@@ -0,0 +1,66 @@ | |||
import Ajv, { _, ValidateFunction } from 'ajv'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Largely copied from packages/core/src/ruleset/validation.ts
with a few subtle adjustments to account for 2 different rulesets formats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
If it's still relevant.
# [@stoplight/spectral-core-v1.12.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-v1.11.1...@stoplight/spectral-core-v1.12.0) (2022-04-18) ### Features * **core:** support JSON ruleset validation ([#2062](#2062)) ([aeb7d5b](aeb7d5b))
🎉 This PR is included in version @stoplight/spectral-core-v1.12.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
@tylerlong I'm sorry to hear that! Would you mind sharing your ruleset with us? |
Here you go:
|
Hm, I don't seem to be able to reproduce the issue using the latest. |
Do you know how to run a vscode extension: https://github.com/ringcentral/vscode-openapi-linter If you don't want to run it, you may read the code here: |
Let me find some time to create a simple demo project. |
Here is the simple project to reproduce it https://github.com/tylerlong/spectral-demo How to run the project?
After upgrading to "@stoplight/spectral-core": "^1.12.0", the first issue is:
I changed line 45 from Then there is this issue:
Root cause is TypeScript: microsoft/TypeScript#33079 I workaround it by deleting "exports" section from package.json of @stoplight/spectral-ruleset-bundler and Then the error is:
Which I believe is a new bug cause by this PR. Thanks for your time. |
Hey @tylerlong. Speaking of the first issue, you can run Furthermore, it's likely the error you're experiencing will be resolved altogether, since I'm able to run the code just fine
LMK if that did the trick. |
I think I have found the root cause. It can only be reproduced in some scenarios. spectral/packages/core/src/spectral.ts Line 101 in 3baba29
Especially when you need to compile the code to js first (or even more complicated, bundle the code using some kind of tools like webpack). Especially when you rule set is loaded by @stoplight/spectral-ruleset-bundler/dist/loader/node which has different class definition for the RuleSet. Yes |
A small subset of changes from #2026
The only change shere are:
The remaining changes such as the addition of
AggregateError
, changes around typings, some bug fixes, etc. aren't a part of this PR.Checklist
Does this PR introduce a breaking change?