Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert rule AvoidLinkHeaderRule to the Context object (#714)
- Loading branch information
David Dufour-Boivin
committed
Jul 24, 2018
1 parent
bfb483c
commit 0c9fcc7
Showing
5 changed files
with
70 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions
24
server/src/main/java/de/zalando/zally/rule/zalando/AvoidLinkHeadersRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
package de.zalando.zally.rule.zalando | ||
|
||
import com.typesafe.config.Config | ||
import de.zalando.zally.rule.Context | ||
import de.zalando.zally.rule.HttpHeadersRule | ||
import de.zalando.zally.rule.api.Check | ||
import de.zalando.zally.rule.api.Rule | ||
import de.zalando.zally.rule.api.Severity | ||
import de.zalando.zally.rule.api.Violation | ||
import de.zalando.zally.rule.api.Rule | ||
import io.swagger.models.Swagger | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
@Rule( | ||
ruleSet = ZalandoRuleSet::class, | ||
id = "166", | ||
severity = Severity.MUST, | ||
title = "Avoid Link in Header Rule" | ||
ruleSet = ZalandoRuleSet::class, | ||
id = "166", | ||
severity = Severity.MUST, | ||
title = "Avoid Link in Header Rule" | ||
) | ||
class AvoidLinkHeadersRule(@Autowired rulesConfig: Config) : HttpHeadersRule(rulesConfig) { | ||
private val description = "Do Not Use Link Headers with JSON entities" | ||
|
||
@Check(severity = Severity.MUST) | ||
override fun validate(swagger: Swagger): Violation? { | ||
return super.validate(swagger) | ||
override fun validate(context: Context): List<Violation> { | ||
return super.validate(context) | ||
} | ||
|
||
override fun isViolation(header: String) = header == "Link" | ||
override fun isViolation(header: HeaderElement) = header.name == "Link" | ||
|
||
override fun createViolation(context: Context, header: HeaderElement): Violation = | ||
context.violation(description, header.element) | ||
|
||
override fun createViolation(paths: List<String>): Violation { | ||
return Violation(description, paths) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters