Repository: marshmallow-code/apispec
Pull request #831 (2023-03-08 19:43:03)

fix/#830 resolve content type parameters


Patch:
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 02662ce..afe779f 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -76,4 +76,3 @@ Contributors (chronological)
 - `<https://github.com/kasium>`_
 - Edwin Erdmanis `@vorticity <https://github.com/vorticity>`_
 - Mounier Florian `@paradoxxxzero <https://github.com/paradoxxxzero>`_
-- Renato Damas `@codectl <https://github.com/codectl>`_
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 1262bd1..f792c07 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,14 +1,6 @@
 Changelog
 ---------
 
-6.2.0 (2023-03-06)
-******************
-
-Features:
-
-- Resolve references in callbacks (:issue:`827`).
-  Thanks :user:`codectl` for the PR.
-
 6.1.0 (2023-03-03)
 ******************
 
diff --git a/src/apispec/__init__.py b/src/apispec/__init__.py
index df3e9f2..6c020f6 100644
--- a/src/apispec/__init__.py
+++ b/src/apispec/__init__.py
@@ -3,5 +3,5 @@
 from .core import APISpec
 from .plugin import BasePlugin
 
-__version__ = "6.2.0"
+__version__ = "6.1.0"
 __all__ = ["APISpec", "BasePlugin"]
diff --git a/src/apispec/core.py b/src/apispec/core.py
index 0dfe373..c92843e 100644
--- a/src/apispec/core.py
+++ b/src/apispec/core.py
@@ -343,6 +343,9 @@ class Components:
     def _resolve_refs_in_parameter_or_header(self, parameter_or_header) -> None:
         self._resolve_schema(parameter_or_header)
         self._resolve_examples(parameter_or_header)
+        # parameter content is OpenAPI v3+
+        for media_type in parameter_or_header.get("content", {}).values():
+            self._resolve_schema(media_type)
 
     def _resolve_refs_in_request_body(self, request_body) -> None:
         # requestBody is OpenAPI v3+


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
index 61674eb..6342dff 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -481,6 +481,14 @@ class TestComponents(RefsSchemaTestMixin):
         param = get_parameters(spec)["param"]
         assert param["schema"] == build_ref(spec, "schema", "PetSchema")
 
+    @pytest.mark.parametrize("spec", ("3.0.0",), indirect=True)
+    def test_components_resolve_parameter_schemas_v3(self, spec):
+        parameter = {"content": {"application/json": {"schema": "PetSchema"}}}
+        spec.components.parameter("param", "path", parameter)
+        param = get_parameters(spec)["param"]
+        schema = param["content"]["application/json"]["schema"]
+        assert schema == build_ref(spec, "schema", "PetSchema")
+
     def test_components_resolve_refs_in_parameter_schema(self, spec):
         parameter = {"schema": copy.deepcopy(self.REFS_SCHEMA)}
         spec.components.parameter("param", "path", parameter)
@@ -901,48 +909,30 @@ class TestPath(RefsSchemaTestMixin):
     # callbacks only exists in OAS 3
     @pytest.mark.parametrize("spec", ("3.0.0",), indirect=True)
     def test_path_resolve_callbacks(self, spec):
-        parameter = {"name": "petId", "in": "query", "schema": "PetSchema"}
         spec.path(
             "/pet/{petId}",
             operations={
                 "get": {
                     "callbacks": {
-                        "onEvent": {
-                            "/callback/{petId}": {
+                        "event": {
+                            "/callback": {
                                 "post": {
-                                    "parameters": [parameter],
                                     "requestBody": {
                                         "content": {
                                             "application/json": {"schema": "PetSchema"}
                                         }
-                                    },
-                                    "responses": {
-                                        "200": {
-                                            "content": {
-                                                "application/json": {
-                                                    "schema": "PetSchema"
-                                                }
-                                            }
-                                        }
-                                    },
+                                    }
                                 }
                             }
                         }
-                    },
+                    }
                 }
             },
         )
-        path = get_paths(spec)["/pet/{petId}"]
-        schema_ref = build_ref(spec, "schema", "PetSchema")
-        callback_op = path["get"]["callbacks"]["onEvent"]["/callback/{petId}"]["post"]
-        assert callback_op["parameters"][0]["schema"] == schema_ref
-        assert (
-            callback_op["requestBody"]["content"]["application/json"]["schema"]
-            == schema_ref
-        )
-        assert (
-            callback_op["responses"]["200"]["content"]["application/json"]["schema"]
-            == schema_ref
+        assert get_paths(spec)["/pet/{petId}"]["get"]["callbacks"]["event"][
+            "/callback"
+        ]["post"]["requestBody"]["content"]["application/json"]["schema"] == build_ref(
+            spec, "schema", "PetSchema"
         )
 
     # requestBody only exists in OAS 3