Skip to content

Commit 9a71a1d

Browse files
authored
feat: Support content-type with attributes (#655, #809, #858). Thanks @sherbang!
1 parent c93dfb0 commit 9a71a1d

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

end_to_end_tests/openapi.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@
12721272
"200": {
12731273
"description": "Successful Response",
12741274
"content": {
1275-
"application/json": {
1275+
"application/json; version=1.2.3": {
12761276
"schema": {}
12771277
}
12781278
}

openapi_python_client/parser/responses.py

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from attrs import define
77

8+
from openapi_python_client import utils
9+
810
from .. import Config
911
from .. import schema as oai
1012
from ..utils import PythonIdentifier
@@ -22,6 +24,8 @@ class Response:
2224

2325

2426
def _source_by_content_type(content_type: str) -> Optional[str]:
27+
content_type = utils.get_content_type(content_type)
28+
2529
known_content_types = {
2630
"application/json": "response.json()",
2731
"application/octet-stream": "response.content",

tests/test_parser/test_responses.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def test_response_from_data_unsupported_content_type():
6868
def test_response_from_data_no_content_schema(any_property_factory):
6969
from openapi_python_client.parser.responses import Response, response_from_data
7070

71-
data = oai.Response.model_construct(description="", content={"application/json": oai.MediaType.model_construct()})
71+
data = oai.Response.model_construct(
72+
description="", content={"application/vnd.api+json; version=2.2": oai.MediaType.model_construct()}
73+
)
7274
response, schemas = response_from_data(
7375
status_code=200, data=data, schemas=Schemas(), parent_name="parent", config=MagicMock()
7476
)

0 commit comments

Comments
 (0)