Skip to content

Commit 771fc7d

Browse files
authored
Merge pull request #1059 from binggao1230/add-trace-to-path-keys
Recognize `trace` operations in docstrings
2 parents 96e93e8 + 1cd742f commit 771fc7d

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎CHANGELOG.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ unreleased
66

77
Bug fixes:
88

9+
- Recognize ``trace`` operations defined in view docstrings, instead of
10+
silently dropping them (:pr:`1059`).
11+
Thanks :user:`binggao1230` for the PR.
912
- Fix intersect ``OneOf`` and ``Equal`` choices in ``field2choices`` (:issue:`198`).
1013
Thanks :user:`alexchen-sys` for the PR.
1114

‎src/apispec/yaml_utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def load_yaml_from_docstring(docstring: str) -> dict:
3636
return yaml.safe_load(yaml_string) or {}
3737

3838

39-
PATH_KEYS = {"get", "put", "post", "delete", "options", "head", "patch"}
39+
PATH_KEYS = {"get", "put", "post", "delete", "options", "head", "patch", "trace"}
4040

4141

4242
def load_operations_from_docstring(docstring: str) -> dict:

‎tests/test_yaml_utils.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ def test_load_operations_from_docstring_empty_docstring(docstring):
2929
assert yaml_utils.load_operations_from_docstring(docstring) == {}
3030

3131

32+
@pytest.mark.parametrize(
33+
"method", ("get", "put", "post", "delete", "options", "head", "patch", "trace")
34+
)
35+
def test_load_operations_from_docstring_path_methods(method):
36+
docstring = f"""Foo.
37+
---
38+
{method}:
39+
responses:
40+
200:
41+
description: ok
42+
"""
43+
44+
operations = yaml_utils.load_operations_from_docstring(docstring)
45+
assert operations == {method: {"responses": {200: {"description": "ok"}}}}
46+
47+
3248
def test_dict_to_yaml_unicode():
3349
assert yaml_utils.dict_to_yaml({"가": "나"}) == '"\\uAC00": "\\uB098"\n'
3450
assert yaml_utils.dict_to_yaml({"가": "나"}, {"allow_unicode": True}) == "가: 나\n"

0 commit comments

Comments
 (0)