marshmallow-code / flask-smorest

DB agnostic framework to build auto-documented REST APIs with Flask and marshmallow
https://flask-smorest.readthedocs.io
MIT License
639 stars 72 forks source link

Missing response header in OpenAPI documentation #578

Closed drcpu-github closed 5 months ago

drcpu-github commented 8 months ago

When generating OpenAPI documentation, additional headers in the response decorator are overwritten whenever the paginate decorator is used. This appears to be caused by the _document_pagination_metadata in pagination.py which overwrites the resp_doc["headers"] structure.

A simple fix could be something like this:

def _document_pagination_metadata(self, spec, resp_doc):
    """Document pagination metadata header

    Override this to document custom pagination metadata
    """
    if "headers" not in resp_doc:
        resp_doc["headers"] = {}
    resp_doc["headers"].update({
        self.PAGINATION_HEADER_NAME: "PAGINATION"
        if spec.openapi_version.major >= 3
        else PAGINATION_HEADER
    })
lafrech commented 8 months ago

Yes, I guess you're right.

Would you like to submit a PR with this fix and a test?

drcpu-github commented 8 months ago

Sure thing, I created one.

lafrech commented 5 months ago

Fixed in #579.