zalando / zally

A minimalistic, simple-to-use API linter
https://zalando.github.io/zally
MIT License
908 stars 145 forks source link

Address issue #1445 and fix failed test #1480

Closed ktsypkina closed 9 months ago

ktsypkina commented 9 months ago

Addresses https://github.com/zalando/zally/issues/1445 As Zally does not support validation for relative refs, no new test cases to cover this scenario

After upgrading to io.swagger.parser.v3:swagger-parser:2.1.9 (from 2.0.32) the test case was failing due to different error message.

This error occured because of changes in OpenAPIDeserializer: rootMap = new ObjectMapper().convertValue(rootNode, Map.class); the convert to rootMap was introduced before trying to parse the rootNode. That's why it is not setting the correct message in the result.

Before the upgrade the message was attribute openApi is not of type "object"

After upgrade the IllegalArgumentException is handled by the library itself, setting the message to

Cannot construct instance of `java.util.LinkedHashMap` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('no swagger definition') at [Source: UNKNOWN; byte offset: #UNKNOWN]

Aligned with @tkrop on the fix: handle this exception as violation of rule #101 Since there is 0 attributes in test example "no swagger definition" it is handled as ParseResult.NotApplicable with following details:

{
    externalId: "<some id>",
    title: "provide API specification using OpenAPI",
    description: "attribute  is not of type `object`",
    ruleLink: "https://zalando.github.io/restful-api-guidelines/#101",
   ....
}
codecov-commenter commented 9 months ago

Codecov Report

Attention: Patch coverage is 75.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 77.25%. Comparing base (9315868) to head (ae1d160). Report is 2 commits behind head on main.

Files Patch % Lines
...in/org/zalando/zally/core/DefaultContextFactory.kt 75.00% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1480 +/- ## ============================================ + Coverage 77.11% 77.25% +0.13% - Complexity 669 672 +3 ============================================ Files 171 171 Lines 2819 2822 +3 Branches 442 442 ============================================ + Hits 2174 2180 +6 + Misses 417 414 -3 Partials 228 228 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tkrop commented 9 months ago

:+1:

tkrop commented 9 months ago

Oh, by the way, there is a drop in coverage. Can you think of a new test case covering it?

ktsypkina commented 9 months ago

Oh, by the way, there is a drop in coverage. Can you think of a new test case covering it?

I've added a new test case before but it's not recognising the new test case as one covering string input scenario

tkrop commented 9 months ago

:+1:

ktsypkina commented 9 months ago

👍