From 8cbbbeb1630ff4d5732f2287b4985df84681af47 Mon Sep 17 00:00:00 2001 From: Tayler Sokalski Date: Mon, 17 Jul 2023 11:54:06 -0400 Subject: [PATCH] Fix conversion of Marshmallow field to OAS parameter to specify the deprecated flag on the parameter, not its schema. --- AUTHORS.rst | 1 + src/apispec/ext/marshmallow/openapi.py | 2 ++ tests/test_ext_marshmallow_openapi.py | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 02662ceb..17bea2b9 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -77,3 +77,4 @@ Contributors (chronological) - Edwin Erdmanis `@vorticity `_ - Mounier Florian `@paradoxxxzero `_ - Renato Damas `@codectl `_ +- Tayler Sokalski `@tsokalski `_ diff --git a/src/apispec/ext/marshmallow/openapi.py b/src/apispec/ext/marshmallow/openapi.py index a27bc4f7..22ff6ef0 100644 --- a/src/apispec/ext/marshmallow/openapi.py +++ b/src/apispec/ext/marshmallow/openapi.py @@ -197,6 +197,8 @@ def _field2parameter( else: if "description" in prop: ret["description"] = prop.pop("description") + if "deprecated" in prop: + ret["deprecated"] = prop.pop("deprecated") ret["schema"] = prop for param_attr_func in self.parameter_attribute_functions: diff --git a/tests/test_ext_marshmallow_openapi.py b/tests/test_ext_marshmallow_openapi.py index 2617329b..ed7fb0ef 100644 --- a/tests/test_ext_marshmallow_openapi.py +++ b/tests/test_ext_marshmallow_openapi.py @@ -245,6 +245,11 @@ def test_field_required(self, openapi): res = openapi._field2parameter(field, name="field", location="query") assert res["required"] is True + def test_field_deprecated(self, openapi): + field = fields.Str(metadata={"deprecated": True}) + res = openapi._field2parameter(field, name="field", location="query") + assert res["deprecated"] is True + def test_schema_partial(self, openapi): class UserSchema(Schema): field = fields.Str(required=True)