Skip to content

Fix response-header documentation on marshalling decorators - #655

Open
2836048681 wants to merge 1 commit into
python-restx:masterfrom
2836048681:fix/601-marshal-response-headers
Open

2836048681 wants to merge 1 commit into
python-restx:masterfrom
2836048681:fix/601-marshal-response-headers

Conversation

@2836048681

Copy link
Copy Markdown

Fixes #601.

Passing headers to @api.marshal_with() currently raises TypeError while
defining the resource. The namespace decorator already stores these descriptions
in response metadata, and Swagger already knows how to render them, but the same
keyword arguments are forwarded to the runtime marshaller, which does not accept
headers.

Copy the runtime marshalling options and remove headers from that copy, keeping
the original response metadata intact. This also fixes @api.marshal_list_with()
and preserves header documentation when the same decorator is reused.

The regression cases cover both decorators, reusable decorators, string and typed
header descriptions, response-code scoping, envelopes, filtered response bodies,
and preservation of runtime response headers and status codes. Document the
parameter and add a changelog entry.

Validation

Environment: CPython 3.12.3, Flask 3.1.3, Werkzeug 3.1.9, pytest 8.4.2.

  • Before the production fix: both new regression cases fail with the reported
    unexpected-headers TypeError (screening/regression-before.log).
  • Focused Swagger, namespace and marshalling tests: 178 passed
    (screening/targeted-after.log).
  • Unfiltered suite: 1,231 passed, 6 skipped, 2 failed
    (screening/full-after.log). The failures are existing DNS-dependent tests:
    tests/test_inputs.py::URLTest::test_check and
    tests/test_inputs.py::EmailTest::test_invalid_values_check[coucou@not-found.test].
    Both fail identically against an untouched export of base commit 30abd919e7c6bb2533eef57ec9c2339d7de69b39
    (screening/baseline-dns.log). The baseline import was verified to come from
    screening/baseline/flask_restx/, not the edited checkout. This runner resolves
    both supposedly nonexistent hosts to 198.18.x.x addresses; see
    screening/dns-environment.json.
  • Suite with exactly those two proven pre-existing cases explicitly deselected:
    1,231 passed, 6 skipped, 2 deselected (screening/full-isolated.log).
  • Black check on both changed Python files: passed (screening/black.log).
  • Repository inv qa packaging/rendering check: passed (screening/qa.log).
  • pip check and git diff --check: passed.

Commands, from the checkout:

export PATH="$PWD/../.venv/bin:$PATH"
python -m pytest tests/test_swagger.py tests/test_namespace.py tests/test_marshalling.py -q --benchmark-skip
python -m pytest --benchmark-skip -q
python -m pytest --benchmark-skip -q \
  --deselect tests/test_inputs.py::URLTest::test_check \
  --deselect 'tests/test_inputs.py::EmailTest::test_invalid_values_check[coucou@not-found.test]'
python -m black --check flask_restx/namespace.py tests/test_swagger.py
inv qa
python -m pip check

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.

@api.marshal_with is meant to support headers but gets unexpected keyword argument

1 participant