Skip to content
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

fix: supported references for problem+json (#1274) #1277

Merged
merged 2 commits into from
Jul 7, 2021

Conversation

tkrop
Copy link
Member

@tkrop tkrop commented Jul 6, 2021

fixes #1274
fixes #891

Tricky! As it actually turned out, not the missing reference broke the check, but the change in the problem specification the check was not adapted to. However, the reference check does play a role as soon as the reference cannot be resolved for any reason. It is just not tested while validating the check.

@vadeg if you know how to switch of reference resolution for one test, I would like to add this as an additional test case.

Anyhow, I added a separate check method as well as full test coverage for checking and notifying the media-type violations.

@codecov-commenter
Copy link

codecov-commenter commented Jul 6, 2021

Codecov Report

Merging #1277 (0f24113) into master (18639d8) will decrease coverage by 0.06%.
The diff coverage is 54.16%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1277      +/-   ##
============================================
- Coverage     76.07%   76.01%   -0.07%     
- Complexity     1009     1017       +8     
============================================
  Files           187      187              
  Lines          2922     2935      +13     
  Branches        501      508       +7     
============================================
+ Hits           2223     2231       +8     
  Misses          435      435              
- Partials        264      269       +5     
Impacted Files Coverage Δ
...uleset/zalando/JsonProblemAsDefaultResponseRule.kt 55.26% <54.16%> (+3.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 18639d8...0f24113. Read the comment docs.

.filter { "default" in it.second.keys }
.flatMap { it.second.getValue("default").content.orEmpty().entries }
.filter { (contentType, _) -> contentType in validContentTypes }
.filterNot { it.value?.schema?.`$ref` in validRefs || isProblemJsonSchema(it.value?.schema) }
.map { context.violation("problem json has to be used as default response (${validRefs[0]})", it.value) }
.filterNot { it.value?.schema?.`$ref` in validRefs }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filter is actually only active, when the references are not resolved, which we currently have no happy path test case for.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swagger parser in Zally always fully resolves references (applies both resolve and resolveFully options). I think we can remove completely the ref check from this rule and check only that the default response is a Problem.json object regardless of the reference, because refs will be removed from the schema.

Copy link
Member Author

@tkrop tkrop Jul 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, keeping it is more robust. If we drop it, the server will fail, when the problem+json resource is unreachable - not sure how often this may happen. I would more like to add a test that enforces non-loading ...

Anyhow, unless you have an idea, I suggest to merge it now finding a fix for this later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-loading would never happen in reality unless we allow to do so :) If the resource is unreachable, then the response will be resolved to nullable response without properties in the schema. This is what the rule can check.

@tkrop tkrop force-pushed the 1274-supported-references-for-problem branch 2 times, most recently from 0246c86 to 4cab783 Compare July 6, 2021 15:32
@tkrop tkrop force-pushed the 1274-supported-references-for-problem branch from 4cab783 to 345d406 Compare July 6, 2021 16:51
@tkrop tkrop added the area: server Zally server issues label Jul 6, 2021
@tkrop
Copy link
Member Author

tkrop commented Jul 6, 2021

👍

1 similar comment
@vadeg
Copy link
Contributor

vadeg commented Jul 7, 2021

👍

@tkrop tkrop merged commit 367be54 into master Jul 7, 2021
@tkrop tkrop deleted the 1274-supported-references-for-problem branch July 7, 2021 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants