-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
fix: example-value-or-externalValue too broad JsonPath expressions #899
Conversation
@m-mohr Could you please add a test that would only pass with that change ("examples that contain a property examples") for instance? |
@nulltoken I could post an example here, but I doubt I can add a good test. I'm not really into your test suite and don't really know what to do there. Could someone make a test out of a json example I post? Or would a new scenario file be enough? 🤔 |
@m-mohr That would be perfect! |
@m-mohr The tests are currently failing because the test documents (incorrectly) expose the Could you please update them so that they pass? This would require simple changes in the test documents and expectations.
An example below: diff --git a/src/rulesets/oas/__tests__/example-value-or-externalValue.ts b/src/rulesets/oas/__tests__/example-value-or-externalValue.ts
index 796ccc0..820f547 100644
--- a/src/rulesets/oas/__tests__/example-value-or-externalValue.ts
+++ b/src/rulesets/oas/__tests__/example-value-or-externalValue.ts
@@ -56,21 +56,21 @@ describe('example-value-or-externalValue', () => {
test('multiple examples - return warnings if missing externalValue and value in one', async () => {
const results = await s.run({
- examples: { first: { value: 'value1' }, second: { externalValue: 'external-value2' }, third: {} },
+ components: { examples: { first: { value: 'value1' }, second: { externalValue: 'external-value2' }, third: {} } },
});
expect(results).toEqual([
{
code: 'example-value-or-externalValue',
message: 'Example should have either a `value` or `externalValue` field.',
- path: ['examples', 'third'],
+ path: ['components', 'examples', 'third'],
range: {
end: {
- character: 15,
- line: 8,
+ character: 17,
+ line: 9,
},
start: {
- character: 12,
- line: 8,
+ character: 14,
+ line: 9,
},
},
severity: DiagnosticSeverity.Warning, Note: in order to repro those failure locally, running |
@nulltoken Thanks for the help regarding the tests. I updated the tests as requested and also managed to add new tests, also checking the
So I think I made all your requested changes. |
Great! |
Most likely some permissions issue, as you don't belong to Stoplight organization. |
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.
Just one comment.
Looking great.
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.
Thank you!
Checking this out @P0lip |
@P0lip For some reason the build was not triggered — some web hook failed. I've run this manually and it passed the tests, we can just merge it. |
Ah ok — I think the reason is that this is a PR originated from a fork, not from the repo. |
Related to #883 (partially, see comments).
Checklist
Does this PR introduce a breaking change?
Additional context
$..examples is too broad and incorrectly complains about examples that contain a property examples, see #883 (comment)
Please some one double-check whether I found all paths for the examples in the OAS3 spec. Not sure about Swagger2?!
Edit: I'm not sure why the CI fails. Is it because some JSON path expressions return an empty array? If yes, the old JSON path would also fail on OpenAPI specs with no examples, right?