Skip to content
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

Merged
merged 10 commits into from
Jan 14, 2020
Merged

fix: example-value-or-externalValue too broad JsonPath expressions #899

merged 10 commits into from
Jan 14, 2020

Conversation

m-mohr
Copy link
Contributor

@m-mohr m-mohr commented Jan 9, 2020

Related to #883 (partially, see comments).

Checklist

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
  • No

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?

@nulltoken
Copy link
Contributor

@m-mohr Could you please add a test that would only pass with that change ("examples that contain a property examples") for instance?

@nulltoken nulltoken requested a review from P0lip January 9, 2020 21:14
@m-mohr
Copy link
Contributor Author

m-mohr commented Jan 9, 2020

@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? 🤔

@nulltoken
Copy link
Contributor

Or would a new scenario file be enough?

@m-mohr That would be perfect!

@nulltoken
Copy link
Contributor

@m-mohr The tests are currently failing because the test documents (incorrectly) expose the examples at the root of the document. They were previously passing because of the (too) broad JsonPath expression.

Could you please update them so that they pass? This would require simple changes in the test documents and expectations.

I'm not really into your test suite and don't really know what to do there.

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 yarn test "example-value" should work.

@m-mohr
Copy link
Contributor Author

m-mohr commented Jan 10, 2020

@nulltoken Thanks for the help regarding the tests. I updated the tests as requested and also managed to add new tests, also checking the

  • other paths (parameters, headers, content)
  • examples on top level
  • examples properties in examples

So I think I made all your requested changes.

@m-mohr m-mohr requested a review from nulltoken January 10, 2020 10:22
@nulltoken nulltoken changed the title example-value-or-externalValue: $..examples is too broad fix: example-value-or-externalValue too broad JsonPath expressions Jan 12, 2020
@nulltoken
Copy link
Contributor

@m-mohr Looks very good to me.

@P0lip How do you feel about this?

@m-mohr
Copy link
Contributor Author

m-mohr commented Jan 12, 2020

Great!
Why's the stoplightio.spectral check hanging?

@P0lip
Copy link
Contributor

P0lip commented Jan 13, 2020

Why's the stoplightio.spectral check hanging?

Most likely some permissions issue, as you don't belong to Stoplight organization.
@XVincentX any clue? It's Azure Pipelines.

Copy link
Contributor

@P0lip P0lip left a 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.

src/rulesets/oas/index.json Outdated Show resolved Hide resolved
@P0lip P0lip added the t/bug Something isn't working label Jan 13, 2020
Copy link
Contributor

@P0lip P0lip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@XVincentX
Copy link
Contributor

Checking this out @P0lip

@XVincentX
Copy link
Contributor

@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.

@P0lip P0lip merged commit d391292 into stoplightio:develop Jan 14, 2020
@XVincentX
Copy link
Contributor

XVincentX commented Jan 14, 2020

Ah ok — I think the reason is that this is a PR originated from a fork, not from the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants