-
Notifications
You must be signed in to change notification settings - Fork 73
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 OpenAPI docs generation to include missing response headers when pagination is used #579
Fix OpenAPI docs generation to include missing response headers when pagination is used #579
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #579 +/- ##
=======================================
Coverage 99.88% 99.88%
=======================================
Files 14 14
Lines 885 885
Branches 192 192
=======================================
Hits 884 884
Partials 1 1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. That's what I was expecting.
Once minor comments are addressed, this is good to go.
flask_smorest/pagination.py
Outdated
} | ||
if "headers" not in resp_doc: | ||
resp_doc["headers"] = {} | ||
resp_doc["headers"].update( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the setdefault form. That's the form I use everywhere in the code.
resp_doc.setdefault("headers", {}).update(...)
tests/test_spec.py
Outdated
@@ -178,6 +178,29 @@ def test_get(val): | |||
"schema": {"$ref": "#/components/schemas/PaginationMetadata"}, | |||
} | |||
|
|||
def test_all_headers_are_documented(self, app): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm tempted to add a comment such as
# Non-regression test for https://github.com/marshmallow-code/flask-smorest/issues/578
to make the test intent more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did add a #noqa: E501
to stop flake8 complaining about the length of that line.
tests/test_spec.py
Outdated
@@ -178,6 +178,29 @@ def test_get(val): | |||
"schema": {"$ref": "#/components/schemas/PaginationMetadata"}, | |||
} | |||
|
|||
def test_all_headers_are_documented(self, app): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could put this in pagination tests and make the name reflect the fact that we're checking other headers are not dropped as a non-reg test for this specific issue.
I'd be happy to enlarge the scope to check all sorts of combination and leave the test here. But this is not what we do here and I'm not sure it's worth trying.
For now, I'd move this to test_pagination.py
and call it something like test_pagination_doc_preservers_other_headers_doc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funilly enough, I first had that test in test_pagination.py
, but then moved it because I felt it better fit in test_spec.py
since it was about documentation. In any case, I moved and renamed it.
I have applied all suggestions, but did not yet squash the branch so you can check it more easily. I'll do that once you are happy with the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a typo to fix and you can squash.
Thanks!
tests/test_pagination.py
Outdated
@@ -479,6 +479,39 @@ def func(): | |||
assert parameters[3]["schema"]["minimum"] == 1 | |||
assert parameters[3]["schema"]["maximum"] == 100 | |||
|
|||
# Non-regression test for https://github.com/marshmallow-code/flask-smorest/issues/578 # noqa: E501 | |||
@pytest.mark.parametrize("openapi_version", ("2.0", "3.0.2")) | |||
def test_pagination_doc_preservers_other_headers_doc(self, app, openapi_version): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/preservers/preserves/
…pagination is used
ebe9bcc
to
05e34a2
Compare
Done! |
Released in 0.42.3. Thanks! |
PR for issue #578.
Added the code I showed in the issue and a simple test to show that it works. Not sure if you expect more from a test than this, but let me know.