-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Litteral YAML in tests + Less class inheritance for rules
- Loading branch information
David Dufour-Boivin
committed
Jul 24, 2018
1 parent
5018e15
commit 1a144a9
Showing
5 changed files
with
188 additions
and
83 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
51 changes: 0 additions & 51 deletions
51
server/src/main/java/de/zalando/zally/rule/HttpHeadersRuleWithContext.kt
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package de.zalando.zally.util | ||
|
||
import io.swagger.v3.oas.models.OpenAPI | ||
import io.swagger.v3.oas.models.parameters.Parameter | ||
import io.swagger.v3.oas.models.responses.ApiResponse | ||
|
||
data class HeaderElement( | ||
val name: String, | ||
val element: Any | ||
) | ||
|
||
fun OpenAPI.getAllHeaders(): Set<HeaderElement> { | ||
|
||
fun Collection<Parameter>?.extractHeaders() = orEmpty() | ||
.filter { it.`in` == "header" } | ||
.map { HeaderElement(it.name, it) } | ||
.toSet() | ||
|
||
fun Collection<ApiResponse>?.extractHeaders() = orEmpty() | ||
.flatMap { it.headers.orEmpty().entries } | ||
.map { HeaderElement(it.key, it.value) } | ||
.toSet() | ||
|
||
val fromParams = components.parameters.orEmpty().values.extractHeaders() | ||
|
||
val fromPaths = paths.orEmpty().flatMap { (_, path) -> | ||
val fromPathParameters = path.parameters.extractHeaders() | ||
val fromOperations = path.readOperations().flatMap { operation -> | ||
val fromOpParams = operation.parameters.extractHeaders() | ||
val fromOpResponses = operation.responses.orEmpty().values.extractHeaders() | ||
fromOpParams + fromOpResponses | ||
} | ||
fromPathParameters + fromOperations | ||
} | ||
|
||
return fromParams + fromPaths | ||
} |
119 changes: 110 additions & 9 deletions
119
server/src/test/java/de/zalando/zally/rule/zalando/AvoidLinkHeadersRuleTest.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