diff --git a/connexion/operations/openapi.py b/connexion/operations/openapi.py index edcb9bf1f..7dce8dd5b 100644 --- a/connexion/operations/openapi.py +++ b/connexion/operations/openapi.py @@ -134,8 +134,8 @@ def consumes(self): def produces(self): return self._produces - def with_definitions(self, schema: dict): - if self.components: + def with_definitions(self, schema: dict, append_components=True): + if self.components and append_components: schema.setdefault("schema", {}) schema["schema"]["components"] = self.components return schema @@ -241,5 +241,5 @@ def body_definition(self, content_type: t.Optional[str] = None) -> dict: ) content_type_dict = MediaTypeDict(self.request_body.get("content", {})) res = content_type_dict.get(content_type, {}) - return self.with_definitions(res) + return self.with_definitions(res, append_components=False) return {} diff --git a/tests/api/test_parameters.py b/tests/api/test_parameters.py index 49806abae..31cc6156e 100644 --- a/tests/api/test_parameters.py +++ b/tests/api/test_parameters.py @@ -648,3 +648,18 @@ def test_cookie_param(simple_app): response = app_client.get("/v1.0/test-cookie-param") assert response.status_code == 200 assert response.json() == {"cookie_value": "hello"} + + +def test_openapi_schema_validate_with_request_body_change(simple_app): + app_client = simple_app.test_client() + + if simple_app._spec_file == "openapi.yaml": + response = app_client.post( + "/v1.0/test-default-object-body", + headers={"content-type": "application/json"}, + json={"image_version": "2015-08-26"}, + ) + assert response.status_code == 200 + + response = app_client.get("/v1.0/openapi.json") + assert response.status_code == 200