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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@@ -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") |
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.
We want to use comprehensible minimal specification fixtures in tests instead of full-size API specifications.
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.
For the negative cases, I do agree; but for the positive ones too?
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.
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`() { |
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 would replace tests based on a complete API specification with test cases describing the behavior of the check functions.
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 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) { |
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 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.
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 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.
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 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.
1a144a9
to
70ad4ab
Compare
fun `a Swagger API with no header called Link produces no violation`() { | ||
@Language("YAML") | ||
val context = Context.createSwaggerContext(""" | ||
swagger: 2.0 |
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.
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:
).
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.
Those parameters are for all of the API, not just for that path/verb.
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 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.
👍 |
1 similar comment
👍 |
#714 Convert rule AvoidLinkHeadersRule to the next Context object (OpenAPI 3).