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

714-rules-to-aos--AvoidLinkHeadersRule #763

Merged
5 commits merged into from Jul 26, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jul 24, 2018

#714 Convert rule AvoidLinkHeadersRule to the next Context object (OpenAPI 3).

David Dufour-Boivin added 2 commits July 24, 2018 14:52
@ghost ghost requested review from maxim-tschumak and tkrop July 24, 2018 13:07
@ghost ghost requested a review from netme as a code owner July 24, 2018 13:07
@codecov-io
Copy link

codecov-io commented Jul 24, 2018

Codecov Report

Merging #763 into master will decrease coverage by 0.36%.
The diff coverage is 56.86%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #763      +/-   ##
============================================
- Coverage     86.08%   85.71%   -0.37%     
- Complexity     1020     1024       +4     
============================================
  Files           170      171       +1     
  Lines          2667     2703      +36     
  Branches        374      385      +11     
============================================
+ Hits           2296     2317      +21     
- Misses          186      194       +8     
- Partials        185      192       +7
Impacted Files Coverage Δ Complexity Δ
...ver/src/main/java/de/zalando/zally/rule/Context.kt 66.12% <33.33%> (-13.04%) 17 <0> (+1)
...src/main/java/de/zalando/zally/util/OpenApiUtil.kt 75% <75%> (ø) 0 <0> (?)
...zalando/zally/rule/zalando/AvoidLinkHeadersRule.kt 85.71% <85.71%> (-14.29%) 6 <6> (+2)
...n/java/de/zalando/zally/util/ast/JsonPointers.java 89.74% <0%> (+5.12%) 13% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update add1ab6...10f787b. Read the comment docs.

@@ -11,21 +13,30 @@ class AvoidLinkHeadersRuleTest {

@Test
fun positiveCaseSpp() {
val swagger = getFixture("api_spp.json")
assertThat(rule.validate(swagger)).isNull()
val context = getContextFromFixture("api_spp.json")
Copy link
Contributor

Choose a reason for hiding this comment

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

We want to use comprehensible minimal specification fixtures in tests instead of full-size API specifications.

Copy link
Author

Choose a reason for hiding this comment

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

For the negative cases, I do agree; but for the positive ones too?

Copy link
Author

Choose a reason for hiding this comment

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

Nevermind that. We said we wanted to get rid of all of most of them because of internal reasons.

@@ -120,7 +120,7 @@ class MediaTypesRuleTest {

@Test
fun `the SPP API generates violations`() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would replace tests based on a complete API specification with test cases describing the behavior of the check functions.

Copy link
Author

Choose a reason for hiding this comment

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

This has not changed since the PR for this rule. Only the !! have been removed because of a change in getContextFromFixture.

import io.swagger.v3.oas.models.responses.ApiResponse

// todo: When all rules deriving from `HttpHeadersRule` are converted to the `Context` object, replace `HttpHeadersRule` with this class (#714).
abstract class HttpHeadersRuleWithContext(rulesConfig: Config) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a comment: In general, I would avoid having a class hierarchy for rules. I would rather move these util functions to some Utility class or to the context's companion object.

Copy link
Author

Choose a reason for hiding this comment

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

I did not want to change what was in place more than necessary. This is simply a copy of the original base class.

I am also OK in changing that. This header-gathering function can be moved to either the context or simply some util object.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did not want to change what was in place more than necessary. This is simply a copy of the original base class.

I know - that's why it's only a comment :)

I am also OK in changing that. This header-gathering function can be moved to either the context or simply some util object.

We don't have to do this in this PR.

@ghost ghost force-pushed the 714-rules-to-aos--AvoidLinkHeadersRule branch from 1a144a9 to 70ad4ab Compare July 24, 2018 15:14
fun `a Swagger API with no header called Link produces no violation`() {
@Language("YAML")
val context = Context.createSwaggerContext("""
swagger: 2.0
Copy link
Contributor

Choose a reason for hiding this comment

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

You can have an even smaller example, like:

swagger: 2.0
paths:
  /foo:
    get:
      parameters:
        FlowId:
          name: X-Flow-Id
          in: header
          type: string

BTW, the parameters are wrongly intended in your example (should be under get:).

Copy link
Author

Choose a reason for hiding this comment

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

Those parameters are for all of the API, not just for that path/verb.

Copy link
Author

Choose a reason for hiding this comment

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

I wanted the example to include:

  • a header in a path/verb
  • a header in the global parameters
  • another parameter that is not a header

to make sure the test does not return false negatives.

I can remove one of the header parameter for shortening it.

I can also add one that is called Link but is not a header, again to shield against false negatives in the test.

@maxim-tschumak
Copy link
Contributor

👍

1 similar comment
@ghost
Copy link
Author

ghost commented Jul 26, 2018

👍

@ghost ghost merged commit 2702979 into master Jul 26, 2018
@ghost ghost deleted the 714-rules-to-aos--AvoidLinkHeadersRule branch July 26, 2018 09:14
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants