-
-
Notifications
You must be signed in to change notification settings - Fork 218
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 scoped aliases #1840
Conversation
c2f3330
to
bc92140
Compare
bc92140
to
d5353da
Compare
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.
Is there a separate issue to update the docs?
Not strictly related to this PR, but do we have sense of perf impact of using aliases versus not using aliases?
{ targets }: RulesetScopedAliasDefinition, | ||
formats: Set<Format> | null, | ||
): string { | ||
const errorMessage = `Alias "${name}" is applicable to certain formats, but the format of the linted document is not matched`; |
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.
How does this manifest itself to end user, and what behavior does it cause? If there's a test around this behavior lmk and that might tell me, just couldn't find it :).
If there is a rule that uses an alias that isn't applicable to the document being linted, will this cause the lint to not go through and/or error?
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.
swagger: 2.0
definitions:
User:
type: woops
and the following ruleset
formats:
- oas2
- oas3
aliases:
SchemaObject:
targets:
- formats:
- oas3
given: $.components.schemas[*]
rules:
valid-type-schema:
given: "#SchemaObject"
then:
field: type
function: enumeration
functionOptions:
values:
- string
- boolean
- number
- null
- object
- array
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.
I can't quite tell from the screenshot - did that result in the lint failing, or is it just a log to stdout?
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.
@marbemac it fails, I updated the screenshot.
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.
Hmm - do we want that? makes it impossible to write some rules that target oas2 and some that target oas3 etc
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.
But we don't inform the user about a potentially broken json path
We don't, but it's more apparent than it is with aliases.
I agree with the "pointer to a json path" bit.
I mean, I'm certainly not against making it more lenient - just need to evaluate how this would feel.
Let's make Nauman decide.
Getting rid of that throw would be very easy, so let's not take the implementation factor into the account when making the choice.
Both options are easy to implement.
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.
After some thinking, I actually believe that the case we deal with here might closer to to an empty given:
given: []
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.
I think letting the file lint is the right thing to do. We should have some sort of warning though that a particular rule wasn't run as folks could assume that the file was linted against that rule. Maybe that as a message/info is the right way to go about it?
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.
That could be a separate thing though. Doesn't need to happen in this PR
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.
Fair enough.
I'd still argue we should throw, but let it be. It doesn't change much from the perspective of code.
Yeah, there's some in platform-internal https://github.com/stoplightio/platform-internal/issues/8141
That's actually a difficult question. I'd say it depends. That's why I'm thinking about exposing some internal logic I use in that library so we can potentially use it in Spectral/Studio, and warn about inefficient/bad JSONPath expressions. |
# [@stoplight/spectral-core-v1.6.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-v1.5.1...@stoplight/spectral-core-v1.6.0) (2021-10-12) ### Features * **core:** support scoped aliases ([#1840](#1840)) ([b278497](b278497))
🎉 This PR is included in version @stoplight/spectral-core-v1.6.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
Closes #1837
Needs #1838 #1839
Checklist
Does this PR introduce a breaking change?