Skip to content

Commit

Permalink
fix failed test
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsypkina committed Feb 19, 2024
1 parent 9315868 commit 5791339
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/zally-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dependencies {
kapt("com.google.auto.service:auto-service:1.0.1")

api(project(":zally-rule-api"))
api("io.swagger.parser.v3:swagger-parser:2.1.9")
api("io.swagger.parser.v3:swagger-parser:2.1.12")
api("io.github.config4k:config4k:0.5.0")
implementation("com.google.auto.service:auto-service:1.0.1")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ class DefaultContextFactory(

val parseResult = OpenAPIV3Parser().readContents(content, authorizationValue, parseOptions)
return if (parseResult.openAPI === null) {
if (parseResult.messages.isEmpty() || parseResult.messages.contains("attribute openapi is missing")) {
val openApiIsMissing = parseResult.messages.contains("attribute openapi is missing")
val errorConstructingInstance = parseResult.messages.any {
it.contains("Cannot construct instance", ignoreCase = true)
}

if (parseResult.messages.isEmpty() || openApiIsMissing || errorConstructingInstance) {
ContentParseResult.NotApplicable()
} else {
ContentParseResult.ParsedWithErrors(parseResult.messages.filterNotNull().map(::errorToViolation))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@ class RestApiViolationsTest : RestApiBaseTest() {

@Test
fun shouldRespondWithViolationWhenApiDefinitionFieldIsNotValidSwaggerDefinition() {
val rule101Link = "https://zalando.github.io/restful-api-guidelines/#101"
val response = sendApiDefinition(
ApiDefinitionRequest.fromJson("\"no swagger definition\"")
)

assertThat(response.violations).hasSize(5)
assertThat(response.violations[0].title).isEqualTo("provide API specification using OpenAPI")
// TODO: fails with exception after switch to swagger-parser:2.1.9
// assertThat(response.violations[0].description).isEqualTo("attribute openapi is not of type `object`")
// the input is just a string, it has no attributes
assertThat(response.violations[0].description).isEqualTo("attribute is not of type `object`")
assertThat(response.violations[0].ruleLink).isEqualTo(rule101Link)
assertThat(response.violations[1].title).isEqualTo("TestCheckIsOpenApi3")
assertThat(response.externalId).isNotNull()
}
Expand Down

0 comments on commit 5791339

Please sign in to comment.