FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: Handle octet-stream content media type as binary format by gudjonragnar · Pull Request #1418 · openapi-generators/openapi-python-client · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
      • __init__.py
      • schema.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _string_based_property(
description=data.description,
example=data.example,
)
if string_format == "binary":
if string_format == "binary" or data.content_media_type == "application/octet-stream":
return FileProperty.build(
name=name,
required=required,
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Schema(BaseModel):
additionalProperties: bool | ReferenceOr["Schema"] | None = None
description: str | None = None
schema_format: str | None = Field(default=None, alias="format")
content_media_type: str | None = Field(default=None, alias="contentMediaType")
default: Any | None = None
nullable: bool = Field(default=False)
discriminator: Discriminator | None = None
Expand Down
30 changes: 30 additions & 0 deletions tests/test_parser/test_properties/test_init.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
build_schemas,
property_from_data,
)
from openapi_python_client.parser.properties.string import StringProperty
from openapi_python_client.schema import Parameter, Reference, Schema
from openapi_python_client.utils import ClassName, PythonIdentifier

Expand Down Expand Up @@ -223,6 +224,35 @@ def test__string_based_property_binary_format(self, file_property_factory, confi
)
assert p == file_property_factory(name=name, required=required)

@pytest.mark.parametrize(
"content_media_type,schema_format",
[
pytest.param("application/octet-stream", None, id="content-media-type-only"),
pytest.param("application/octet-stream", "binary", id="both-content-media-type-and-binary-format"),
],
)
def test__string_based_property_content_media_type(
self, file_property_factory, config, content_media_type, schema_format
):
name = "file_prop"
required = True
data = oai.Schema(type="string", contentMediaType=content_media_type, format=schema_format)

p, _ = property_from_data(
name=name, required=required, data=data, schemas=Schemas(), config=config, parent_name=""
)
assert p == file_property_factory(name=name, required=required)

def test__string_based_property_non_binary_content_media_type_ignored(self, config):
name = "text_prop"
required = True
data = oai.Schema(type="string", contentMediaType="text/plain")

p, _ = property_from_data(
name=name, required=required, data=data, schemas=Schemas(), config=config, parent_name=""
)
assert isinstance(p, StringProperty)


class TestCreateSchemas:
def test_dereference_references(self, mocker, config):
Expand Down

Back | FazBrowse Home | New Git URL