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 OpenAPI docs generation to include missing response headers when pagination is used #579

Merged

Conversation

drcpu-github
Copy link
Contributor

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.

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (afaf1aa) 99.88% compared to head (05e34a2) 99.88%.
Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

Copy link
Member

@lafrech lafrech left a 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.

}
if "headers" not in resp_doc:
resp_doc["headers"] = {}
resp_doc["headers"].update(
Copy link
Member

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(...)

@@ -178,6 +178,29 @@ def test_get(val):
"schema": {"$ref": "#/components/schemas/PaginationMetadata"},
}

def test_all_headers_are_documented(self, app):
Copy link
Member

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.

Copy link
Contributor Author

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.

@@ -178,6 +178,29 @@ def test_get(val):
"schema": {"$ref": "#/components/schemas/PaginationMetadata"},
}

def test_all_headers_are_documented(self, app):
Copy link
Member

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.

Copy link
Contributor Author

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.

@drcpu-github
Copy link
Contributor Author

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.

@drcpu-github drcpu-github requested a review from lafrech November 22, 2023 07:42
Copy link
Member

@lafrech lafrech left a 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!

@@ -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):
Copy link
Member

Choose a reason for hiding this comment

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

s/preservers/preserves/

@drcpu-github drcpu-github force-pushed the openapi-doc-list-headers branch from ebe9bcc to 05e34a2 Compare December 4, 2023 11:17
@drcpu-github
Copy link
Contributor Author

Just a typo to fix and you can squash.

Thanks!

Done!

@drcpu-github drcpu-github requested a review from lafrech December 4, 2023 11:17
@lafrech lafrech merged commit 266de0f into marshmallow-code:master Dec 5, 2023
6 checks passed
@lafrech
Copy link
Member

lafrech commented Dec 5, 2023

Released in 0.42.3. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants