Skip to content

feat: Support content-type with attributes (#655 #809). #858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
2 changes: 1 addition & 1 deletion end_to_end_tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"application/json; version=1.2.3": {
"schema": {}
}
}
Expand Down
4 changes: 4 additions & 0 deletions openapi_python_client/parser/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from attrs import define

from openapi_python_client import utils

from .. import Config
from .. import schema as oai
from ..utils import PythonIdentifier
Expand All @@ -22,6 +24,8 @@ class Response:


def _source_by_content_type(content_type: str) -> Optional[str]:
content_type = utils.get_content_type(content_type)

known_content_types = {
"application/json": "response.json()",
"application/octet-stream": "response.content",
Expand Down
4 changes: 3 additions & 1 deletion tests/test_parser/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def test_response_from_data_unsupported_content_type():
def test_response_from_data_no_content_schema(any_property_factory):
from openapi_python_client.parser.responses import Response, response_from_data

data = oai.Response.model_construct(description="", content={"application/json": oai.MediaType.model_construct()})
data = oai.Response.model_construct(
description="", content={"application/vnd.api+json; version=2.2": oai.MediaType.model_construct()}
)
response, schemas = response_from_data(
status_code=200, data=data, schemas=Schemas(), parent_name="parent", config=MagicMock()
)
Expand Down