Skip to content

Recognize trace operations in docstrings#1059

Open
gaoflow wants to merge 2 commits into
marshmallow-code:devfrom
gaoflow:add-trace-to-path-keys
Open

Recognize trace operations in docstrings#1059
gaoflow wants to merge 2 commits into
marshmallow-code:devfrom
gaoflow:add-trace-to-path-keys

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 23, 2026

Copy link
Copy Markdown

Summary

load_operations_from_docstring filters the keys of a view docstring against PATH_KEYS, which omitted "trace":

PATH_KEYS = {"get", "put", "post", "delete", "options", "head", "patch"}

So a trace: operation defined in a docstring is silently dropped:

>>> from apispec.yaml_utils import load_operations_from_docstring
>>> doc = "Example.\n---\nget:\n    responses: {200: {description: ok}}\ntrace:\n    responses: {200: {description: ok}}\n"
>>> sorted(load_operations_from_docstring(doc))
['get']        # 'trace' is missing

This is inconsistent with the rest of apispec, which treats TRACE as a first-class OpenAPI v3 operation:

  • core.py: VALID_METHODS_OPENAPI_V3 = VALID_METHODS_OPENAPI_V2 + ["trace"]
  • core.py: resolve_refs_in_path iterates all eight methods, including trace

Only PATH_KEYS in yaml_utils.py was missed. The same docstring's get: operation is kept, confirming this is an oversight rather than intent.

Fix

Add "trace" to PATH_KEYS, mirroring VALID_METHODS_OPENAPI_V3.

Verification

  • Reproduced on dev (41784ce): trace is dropped from load_operations_from_docstring (and end-to-end, absent from spec.to_dict()["paths"]); with the fix it is preserved.
  • Added test_load_operations_from_docstring_trace; it fails before the fix and passes after.
  • Full suite: 619 passed, 6 skipped (baseline 618 + the new test), no regressions. ruff check and ruff format --check clean.

This pull request was prepared with the assistance of AI, under my direction and review.

gaoflow added 2 commits June 23, 2026 09:19
load_operations_from_docstring filters docstring keys against PATH_KEYS,
which omitted "trace". A trace: operation defined in a view docstring was
silently dropped, even though OpenAPI v3 (VALID_METHODS_OPENAPI_V3) and
the rest of apispec (e.g. resolve_refs_in_path) treat trace as a
first-class operation. Add "trace" to PATH_KEYS.
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.

1 participant