Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions connexion/operations/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that only the init method has pydoc for parameters, the rest of the methods have basically none. With that said, since you are introducing a new parameter with a default value, I think it would be really helpful to add a little pydoc section with a sentence about the new parameter. Please consider it. I'd like to suggest that text, but I am still trying to understand exactly what is being appended here (or not).

schema.setdefault("schema", {})
schema["schema"]["components"] = self.components
return schema
Expand Down Expand Up @@ -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 {}
15 changes: 15 additions & 0 deletions tests/api/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please help me understand the need for this if clause? Are there multiple instances of simple_app and some have a different spec file? I suppose you are trying to increase the chance that the app is listening at endpoint /v1.0/test-default-object-body. Seems like all the other tests in this file have this kind of assumption, so I'm not sure it's necessary to check in this one. Or maybe I'm missing something huge :)

Copy link
Contributor

@chrisinmtown chrisinmtown Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more comment, if you can please have patience with me. I see there is a test file test_responses.py. Because this new test case doesn't actually exercise any parameters, maybe you might consider moving this new case to that file?

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