From b74da3613b751a8d23e368e12e6eafb1224da358 Mon Sep 17 00:00:00 2001 From: frankzye1 Date: Mon, 21 Jul 2025 21:41:28 +0800 Subject: [PATCH 1/3] equest body in openapi no need to append the components Fixes #spec-first#2029 --- connexion/operations/openapi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 {} From 7286ba8bba601c9e22e236c895817c9fd130b08e Mon Sep 17 00:00:00 2001 From: frankzye1 Date: Tue, 22 Jul 2025 09:27:26 +0800 Subject: [PATCH 2/3] add unit test test_openapi_schema_validate_with_request_body_change Signed-off-by: frankzye1 --- tests/api/test_parameters.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/api/test_parameters.py b/tests/api/test_parameters.py index 49806abae..eab26569a 100644 --- a/tests/api/test_parameters.py +++ b/tests/api/test_parameters.py @@ -648,3 +648,14 @@ 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 From 408df8b1862e83a966dcc9ed2f494633480e1f83 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 22 Jul 2025 01:27:49 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/api/test_parameters.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/api/test_parameters.py b/tests/api/test_parameters.py index eab26569a..31cc6156e 100644 --- a/tests/api/test_parameters.py +++ b/tests/api/test_parameters.py @@ -654,8 +654,12 @@ 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"}) + 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