diff --git a/end_to_end_tests/golden-record-custom/pyproject.toml b/end_to_end_tests/golden-record-custom/pyproject.toml index 9f9f94914..09f4ff975 100644 --- a/end_to_end_tests/golden-record-custom/pyproject.toml +++ b/end_to_end_tests/golden-record-custom/pyproject.toml @@ -14,8 +14,8 @@ include = ["CHANGELOG.md", "custom_e2e/py.typed"] [tool.poetry.dependencies] python = "^3.6" -httpx = "^0.15.0" -attrs = "^20.1.0" +httpx = ">=0.15.0, <=0.22.0" +attrs = ">=20.1.0, <22.0" python-dateutil = "^2.8.0" [tool.black] diff --git a/end_to_end_tests/golden-record/pyproject.toml b/end_to_end_tests/golden-record/pyproject.toml index 6b7d0be67..9fa7ba3c0 100644 --- a/end_to_end_tests/golden-record/pyproject.toml +++ b/end_to_end_tests/golden-record/pyproject.toml @@ -14,8 +14,8 @@ include = ["CHANGELOG.md", "my_test_api_client/py.typed"] [tool.poetry.dependencies] python = "^3.6" -httpx = "^0.15.0" -attrs = "^20.1.0" +httpx = ">=0.15.0, <=0.22.0" +attrs = ">=20.1.0, <22.0" python-dateutil = "^2.8.0" [tool.black] diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 3053ee305..a135b12cf 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -94,11 +94,29 @@ class Endpoint: path_parameters: List[Property] = field(default_factory=list) header_parameters: List[Property] = field(default_factory=list) responses: List[Response] = field(default_factory=list) + yaml_body: Optional[Property] = None form_body_reference: Optional[Reference] = None json_body: Optional[Property] = None multipart_body_reference: Optional[Reference] = None errors: List[ParseError] = field(default_factory=list) + @staticmethod + def parse_request_yaml_body( + *, body: oai.RequestBody, schemas: Schemas, parent_name: str + ) -> Tuple[Union[Property, PropertyError, None], Schemas]: + """ Return yaml_body """ + body_content = body.content + yaml_body = body_content.get("text/yaml") + if yaml_body is not None and yaml_body.media_type_schema is not None: + return property_from_data( + name="yaml_body", + required=True, + data=yaml_body.media_type_schema, + schemas=schemas, + parent_name=parent_name, + ) + return None, schemas + @staticmethod def parse_request_form_body(body: oai.RequestBody) -> Optional[Reference]: """ Return form_body_reference """ @@ -110,7 +128,7 @@ def parse_request_form_body(body: oai.RequestBody) -> Optional[Reference]: @staticmethod def parse_multipart_body(body: oai.RequestBody) -> Optional[Reference]: - """ Return form_body_reference """ + """ Return multipart_body_reference """ body_content = body.content json_body = body_content.get("multipart/form-data") if json_body is not None and isinstance(json_body.media_type_schema, oai.Reference): @@ -150,6 +168,12 @@ def _add_body( if isinstance(json_body, ParseError): return ParseError(detail=f"cannot parse body of endpoint {endpoint.name}", data=json_body.data), schemas + yaml_body, schemas = Endpoint.parse_request_yaml_body( + body=data.requestBody, schemas=schemas, parent_name=endpoint.name + ) + if isinstance(yaml_body, ParseError): + return ParseError(detail=f"cannot parse body of endpoint {endpoint.name}", data=yaml_body.data), schemas + endpoint.multipart_body_reference = Endpoint.parse_multipart_body(data.requestBody) if endpoint.form_body_reference: @@ -163,6 +187,10 @@ def _add_body( if json_body is not None: endpoint.json_body = json_body endpoint.relative_imports.update(endpoint.json_body.get_imports(prefix="...")) + if yaml_body is not None: + endpoint.yaml_body = yaml_body + endpoint.relative_imports.update(endpoint.yaml_body.get_imports(prefix="...")) + return endpoint, schemas @staticmethod @@ -177,7 +205,7 @@ def _add_responses(*, endpoint: "Endpoint", data: oai.Responses, schemas: Schema ParseError( detail=( f"Cannot parse response for status code {code}, " - f"response will be ommitted from generated client" + f"response will be omitted from generated client" ), data=response.data, ) diff --git a/openapi_python_client/parser/responses.py b/openapi_python_client/parser/responses.py index b59937cd8..88bcad16f 100644 --- a/openapi_python_client/parser/responses.py +++ b/openapi_python_client/parser/responses.py @@ -22,6 +22,7 @@ class Response: "application/json": "response.json()", "application/octet-stream": "response.content", "text/html": "response.text", + "text/yaml": "response.yaml", # Only used as an identifier, not the actual source } diff --git a/openapi_python_client/templates/endpoint_macros.pyi b/openapi_python_client/templates/endpoint_macros.pyi index 6586ecd70..3103029bb 100644 --- a/openapi_python_client/templates/endpoint_macros.pyi +++ b/openapi_python_client/templates/endpoint_macros.pyi @@ -56,6 +56,17 @@ if {% if not property.required %}not isinstance({{ property_name }}, Unset) and {% endif %} {% endmacro %} +{% macro yaml_body(endpoint) %} +{% if endpoint.yaml_body %} + {% set property = endpoint.yaml_body %} + {% set destination = "yaml_" + property.python_name %} + {% if property.template %} + {% from "property_templates/" + property.template import transform %} +{{ transform(property, property.python_name, destination) }} + {% endif %} +{% endif %} +{% endmacro %} + {% macro return_type(endpoint) %} {% if endpoint.responses | length == 0 %} None @@ -83,6 +94,10 @@ client: Client, {% for parameter in endpoint.path_parameters %} {{ parameter.to_string() }}, {% endfor %} +{# Yaml body if any #} +{% if endpoint.yaml_body %} +yaml_body: {{ endpoint.yaml_body.get_type_string() }}, +{% endif %} {# Form data if any #} {% if endpoint.form_body_reference %} form_data: {{ endpoint.form_body_reference.class_name }}, @@ -110,6 +125,9 @@ client=client, {% for parameter in endpoint.path_parameters %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} +{% if endpoint.yaml_body %} +yaml_body=yaml_body, +{% endif %} {% if endpoint.form_body_reference %} form_data=form_data, {% endif %} diff --git a/openapi_python_client/templates/endpoint_module.pyi b/openapi_python_client/templates/endpoint_module.pyi index 29dfadc46..b0a61c55e 100644 --- a/openapi_python_client/templates/endpoint_module.pyi +++ b/openapi_python_client/templates/endpoint_module.pyi @@ -2,6 +2,7 @@ from typing import Any, Dict, List, Optional, Union, cast import httpx from attr import asdict +from ruamel.yaml import YAML from ...client import AuthenticatedClient, Client from ...types import Response @@ -10,7 +11,7 @@ from ...types import Response {{ relative }} {% endfor %} -{% from "endpoint_macros.pyi" import header_params, query_params, json_body, return_type, arguments, client, kwargs, parse_response %} +{% from "endpoint_macros.pyi" import header_params, query_params, json_body, yaml_body, return_type, arguments, client, kwargs, parse_response %} {% set return_string = return_type(endpoint) %} {% set parsed_responses = (endpoint.responses | length > 0) and return_string != "None" %} @@ -33,6 +34,8 @@ def _get_kwargs( {{ json_body(endpoint) | indent(4) }} + {{ yaml_body(endpoint) | indent(4) }} + return { "url": url, "headers": headers, @@ -46,7 +49,9 @@ def _get_kwargs( {% endif %} {% if endpoint.json_body %} "json": {{ "json_" + endpoint.json_body.python_name }}, - {% endif %} + {%- elif endpoint.yaml_body %} + "json": {{ "yaml_" + endpoint.yaml_body.python_name }}, + {%- endif %} {% if endpoint.query_parameters %} "params": params, {% endif %} diff --git a/openapi_python_client/templates/property_templates/model_property.pyi b/openapi_python_client/templates/property_templates/model_property.pyi index 40a8a8b78..229823be9 100644 --- a/openapi_python_client/templates/property_templates/model_property.pyi +++ b/openapi_python_client/templates/property_templates/model_property.pyi @@ -1,6 +1,12 @@ {% macro construct(property, source, initial_value=None) %} {% if property.required and not property.nullable %} +{% if source == "response.yaml" %} +yaml = YAML(typ="base") +yaml_dict = yaml.load(response.text.encode('utf-8')) +{{ property.python_name }} = {{ property.reference.class_name }}.from_dict(yaml_dict) +{% else %} {{ property.python_name }} = {{ property.reference.class_name }}.from_dict({{ source }}) +{% endif %} {% else %} {% if initial_value != None %} {{ property.python_name }} = {{ initial_value }} diff --git a/poetry.lock b/poetry.lock index f8f3ff211..4856bb4cf 100644 --- a/poetry.lock +++ b/poetry.lock @@ -529,6 +529,29 @@ idna = {version = "*", optional = true, markers = "extra == \"idna2008\""} [package.extras] idna2008 = ["idna"] +[[package]] +name = "ruamel.yaml" +version = "0.17.21" +description = "ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order" +category = "main" +optional = false +python-versions = ">=3" + +[package.dependencies] +"ruamel.yaml.clib" = {version = ">=0.2.6", markers = "platform_python_implementation == \"CPython\" and python_version < \"3.11\""} + +[package.extras] +docs = ["ryd"] +jinja2 = ["ruamel.yaml.jinja2 (>=0.2)"] + +[[package]] +name = "ruamel.yaml.clib" +version = "0.2.6" +description = "C version of reader, parser and emitter for ruamel.yaml derived from libyaml" +category = "main" +optional = false +python-versions = ">=3.5" + [[package]] name = "safety" version = "1.10.0" @@ -657,7 +680,7 @@ testing = ["pytest (>=3.5,!=3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "465faade0fe4c4d54e69d3de573963a3515c8d057686b2847270956394f087f2" +content-hash = "b9beff0f1eb9aab0d72eb9c7a026d31c51ab58233dea92a640d45c24a2510ce8" [metadata.files] anyio = [ @@ -984,6 +1007,37 @@ rfc3986 = [ {file = "rfc3986-1.5.0-py2.py3-none-any.whl", hash = "sha256:a86d6e1f5b1dc238b218b012df0aa79409667bb209e58da56d0b94704e712a97"}, {file = "rfc3986-1.5.0.tar.gz", hash = "sha256:270aaf10d87d0d4e095063c65bf3ddbc6ee3d0b226328ce21e036f946e421835"}, ] +"ruamel.yaml" = [ + {file = "ruamel.yaml-0.17.21-py3-none-any.whl", hash = "sha256:742b35d3d665023981bd6d16b3d24248ce5df75fdb4e2924e93a05c1f8b61ca7"}, + {file = "ruamel.yaml-0.17.21.tar.gz", hash = "sha256:8b7ce697a2f212752a35c1ac414471dc16c424c9573be4926b56ff3f5d23b7af"}, +] +"ruamel.yaml.clib" = [ + {file = "ruamel.yaml.clib-0.2.6-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:6e7be2c5bcb297f5b82fee9c665eb2eb7001d1050deaba8471842979293a80b0"}, + {file = "ruamel.yaml.clib-0.2.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:221eca6f35076c6ae472a531afa1c223b9c29377e62936f61bc8e6e8bdc5f9e7"}, + {file = "ruamel.yaml.clib-0.2.6-cp310-cp310-win32.whl", hash = "sha256:1070ba9dd7f9370d0513d649420c3b362ac2d687fe78c6e888f5b12bf8bc7bee"}, + {file = "ruamel.yaml.clib-0.2.6-cp310-cp310-win_amd64.whl", hash = "sha256:77df077d32921ad46f34816a9a16e6356d8100374579bc35e15bab5d4e9377de"}, + {file = "ruamel.yaml.clib-0.2.6-cp35-cp35m-macosx_10_6_intel.whl", hash = "sha256:cfdb9389d888c5b74af297e51ce357b800dd844898af9d4a547ffc143fa56751"}, + {file = "ruamel.yaml.clib-0.2.6-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:7b2927e92feb51d830f531de4ccb11b320255ee95e791022555971c466af4527"}, + {file = "ruamel.yaml.clib-0.2.6-cp35-cp35m-win32.whl", hash = "sha256:ada3f400d9923a190ea8b59c8f60680c4ef8a4b0dfae134d2f2ff68429adfab5"}, + {file = "ruamel.yaml.clib-0.2.6-cp35-cp35m-win_amd64.whl", hash = "sha256:de9c6b8a1ba52919ae919f3ae96abb72b994dd0350226e28f3686cb4f142165c"}, + {file = "ruamel.yaml.clib-0.2.6-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:d67f273097c368265a7b81e152e07fb90ed395df6e552b9fa858c6d2c9f42502"}, + {file = "ruamel.yaml.clib-0.2.6-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:72a2b8b2ff0a627496aad76f37a652bcef400fd861721744201ef1b45199ab78"}, + {file = "ruamel.yaml.clib-0.2.6-cp36-cp36m-win32.whl", hash = "sha256:9efef4aab5353387b07f6b22ace0867032b900d8e91674b5d8ea9150db5cae94"}, + {file = "ruamel.yaml.clib-0.2.6-cp36-cp36m-win_amd64.whl", hash = "sha256:846fc8336443106fe23f9b6d6b8c14a53d38cef9a375149d61f99d78782ea468"}, + {file = "ruamel.yaml.clib-0.2.6-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0847201b767447fc33b9c235780d3aa90357d20dd6108b92be544427bea197dd"}, + {file = "ruamel.yaml.clib-0.2.6-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:78988ed190206672da0f5d50c61afef8f67daa718d614377dcd5e3ed85ab4a99"}, + {file = "ruamel.yaml.clib-0.2.6-cp37-cp37m-win32.whl", hash = "sha256:a49e0161897901d1ac9c4a79984b8410f450565bbad64dbfcbf76152743a0cdb"}, + {file = "ruamel.yaml.clib-0.2.6-cp37-cp37m-win_amd64.whl", hash = "sha256:bf75d28fa071645c529b5474a550a44686821decebdd00e21127ef1fd566eabe"}, + {file = "ruamel.yaml.clib-0.2.6-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:a32f8d81ea0c6173ab1b3da956869114cae53ba1e9f72374032e33ba3118c233"}, + {file = "ruamel.yaml.clib-0.2.6-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7f7ecb53ae6848f959db6ae93bdff1740e651809780822270eab111500842a84"}, + {file = "ruamel.yaml.clib-0.2.6-cp38-cp38-win32.whl", hash = "sha256:89221ec6d6026f8ae859c09b9718799fea22c0e8da8b766b0b2c9a9ba2db326b"}, + {file = "ruamel.yaml.clib-0.2.6-cp38-cp38-win_amd64.whl", hash = "sha256:31ea73e564a7b5fbbe8188ab8b334393e06d997914a4e184975348f204790277"}, + {file = "ruamel.yaml.clib-0.2.6-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:dc6a613d6c74eef5a14a214d433d06291526145431c3b964f5e16529b1842bed"}, + {file = "ruamel.yaml.clib-0.2.6-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:1866cf2c284a03b9524a5cc00daca56d80057c5ce3cdc86a52020f4c720856f0"}, + {file = "ruamel.yaml.clib-0.2.6-cp39-cp39-win32.whl", hash = "sha256:3fb9575a5acd13031c57a62cc7823e5d2ff8bc3835ba4d94b921b4e6ee664104"}, + {file = "ruamel.yaml.clib-0.2.6-cp39-cp39-win_amd64.whl", hash = "sha256:825d5fccef6da42f3c8eccd4281af399f21c02b32d98e113dbc631ea6a6ecbc7"}, + {file = "ruamel.yaml.clib-0.2.6.tar.gz", hash = "sha256:4ff604ce439abb20794f05613c374759ce10e3595d1867764dd1ae675b85acbd"}, +] safety = [ {file = "safety-1.10.0-py2.py3-none-any.whl", hash = "sha256:69437acf5dd617abd7086ccd0d50e813e67aa969bb9ca90f1847d5fbea047dcc"}, {file = "safety-1.10.0.tar.gz", hash = "sha256:2ebc71b44666588d7898905d86d575933fcd5fa3c92d301ed12482602b1e928a"}, diff --git a/pyproject.toml b/pyproject.toml index cad04c193..0d3feda95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,7 @@ attrs = ">=20.1.0, <22.0" python-dateutil = "^2.8.1" httpx = ">=0.15.4,<=0.22.0" autoflake = "^1.4" +"ruamel.yaml" = "^0.17.21" [tool.poetry.scripts] openapi-python-client = "openapi_python_client.cli:app" @@ -57,7 +58,8 @@ isort .\ && mypy openapi_python_client\ && task unit\ """ -unit = "pytest --cov openapi_python_client tests --cov-report=term-missing" +code_coverage = "pytest --cov openapi_python_client tests --cov-report=term-missing" +unit = "pytest openapi_python_client tests" regen = "python -m end_to_end_tests.regen_golden_record" regen_custom = "python -m end_to_end_tests.regen_golden_record custom" e2e = "pytest openapi_python_client end_to_end_tests/test_end_to_end.py" diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index 33fdb4658..a3f7fab5b 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -66,6 +66,32 @@ def test_from_dict_invalid_schema(self, mocker): class TestEndpoint: + def test_parse_yaml_body(self, mocker): + from openapi_python_client.parser.openapi import Endpoint, Schemas + schema = mocker.MagicMock() + body = oai.RequestBody.construct( + content={"text/yaml": oai.MediaType.construct(media_type_schema=schema)} + ) + property_from_data = mocker.patch(f"{MODULE_NAME}.property_from_data") + schemas = Schemas() + + result = Endpoint.parse_request_yaml_body(body=body, schemas=schemas, parent_name="parent") + + property_from_data.assert_called_once_with( + name="yaml_body", required=True, data=schema, schemas=schemas, parent_name="parent" + ) + assert result == property_from_data.return_value + + def test_parse_yaml_body_no_data(self): + from openapi_python_client.parser.openapi import Endpoint, Schemas + + body = oai.RequestBody.construct(content={}) + schemas = Schemas() + + result = Endpoint.parse_request_yaml_body(body=body, schemas=schemas, parent_name="parent") + + assert result == (None, schemas) + def test_parse_request_form_body(self, mocker): ref = mocker.MagicMock() body = oai.RequestBody.construct( @@ -211,6 +237,12 @@ def test_add_body_happy(self, mocker): parse_request_json_body = mocker.patch.object( Endpoint, "parse_request_json_body", return_value=(json_body, parsed_schemas) ) + yaml_body = mocker.MagicMock(autospec=Property) + yaml_body_imports = mocker.MagicMock() + yaml_body.get_imports.return_value = {yaml_body_imports} + parse_request_yaml_body = mocker.patch.object( + Endpoint, "parse_request_yaml_body", return_value=(yaml_body, parsed_schemas) + ) import_string_from_reference = mocker.patch( f"{MODULE_NAME}.import_string_from_reference", side_effect=["import_1", "import_2"] ) @@ -233,6 +265,7 @@ def test_add_body_happy(self, mocker): assert response_schemas == parsed_schemas parse_request_form_body.assert_called_once_with(request_body) parse_request_json_body.assert_called_once_with(body=request_body, schemas=initial_schemas, parent_name="name") + parse_request_yaml_body.assert_called_once_with(body=request_body, schemas=parsed_schemas, parent_name="name") parse_multipart_body.assert_called_once_with(request_body) import_string_from_reference.assert_has_calls( [ @@ -240,8 +273,10 @@ def test_add_body_happy(self, mocker): mocker.call(multipart_body_reference, prefix="...models"), ] ) + yaml_body.get_imports.assert_called_once_with(prefix="...") json_body.get_imports.assert_called_once_with(prefix="...") - assert endpoint.relative_imports == {"import_1", "import_2", "import_3", json_body_imports} + assert endpoint.relative_imports == {"import_1", "import_2", "import_3", yaml_body_imports, json_body_imports} + assert endpoint.yaml_body == yaml_body assert endpoint.json_body == json_body assert endpoint.form_body_reference == form_body_reference assert endpoint.multipart_body_reference == multipart_body_reference @@ -312,12 +347,12 @@ def test__add_responses(self, mocker): response_1 = Response( status_code=200, source="source", - prop=DateTimeProperty(name="datetime", required=True, nullable=False, default=None), + prop=DateTimeProperty(name="datetime", required=True, nullable=False, default=None, description=None), ) response_2 = Response( status_code=404, source="source", - prop=DateProperty(name="date", required=True, nullable=False, default=None), + prop=DateProperty(name="date", required=True, nullable=False, default=None, description=None), ) response_from_data = mocker.patch( f"{MODULE_NAME}.response_from_data", side_effect=[(response_1, schemas_1), (response_2, schemas_2)] diff --git a/tests/test_parser/test_properties/test_init.py b/tests/test_parser/test_properties/test_init.py index 9e856e26f..2c424007d 100644 --- a/tests/test_parser/test_properties/test_init.py +++ b/tests/test_parser/test_properties/test_init.py @@ -27,7 +27,7 @@ class TestProperty: (False, True, False, True, "TestType"), (False, True, True, False, "Optional[TestType]"), (False, True, True, True, "TestType"), - (True, False, False, False, "Union[Unset, None, TestType]"), + (True, False, False, False, "Union[Unset, TestType]"), (True, False, False, True, "TestType"), (True, False, True, False, "TestType"), (True, False, True, True, "TestType"), @@ -41,7 +41,7 @@ def test_get_type_string(self, mocker, query_parameter, nullable, required, no_o from openapi_python_client.parser.properties import Property mocker.patch.object(Property, "_type_string", "TestType") - p = Property(name="test", required=required, default=None, nullable=nullable) + p = Property(name="test", required=required, default=None, nullable=nullable, description=None) assert p.get_type_string(no_optional=no_optional, query_parameter=query_parameter) == expected @pytest.mark.parametrize( @@ -51,9 +51,9 @@ def test_get_type_string(self, mocker, query_parameter, nullable, required, no_o (False, None, True, "test: TestType"), (False, "Test", False, "test: Union[Unset, TestType] = Test"), (False, "Test", True, "test: TestType = Test"), - (True, None, False, "test: Union[Unset, None, TestType] = UNSET"), + (True, None, False, "test: Union[Unset, TestType] = UNSET"), (True, None, True, "test: TestType"), - (True, "Test", False, "test: Union[Unset, None, TestType] = Test"), + (True, "Test", False, "test: Union[Unset, TestType] = Test"), (True, "Test", True, "test: TestType = Test"), ], ) @@ -62,20 +62,20 @@ def test_to_string(self, mocker, query_parameter, default, required, expected): name = "test" mocker.patch.object(Property, "_type_string", "TestType") - p = Property(name=name, required=required, default=default, nullable=False) + p = Property(name=name, required=required, default=default, nullable=False, description=None) assert p.to_string(query_parameter=query_parameter) == expected def test_get_imports(self): from openapi_python_client.parser.properties import Property - p = Property(name="test", required=True, default=None, nullable=False) + p = Property(name="test", required=True, default=None, nullable=False, description=None) assert p.get_imports(prefix="") == set() - p = Property(name="test", required=False, default=None, nullable=False) + p = Property(name="test", required=False, default=None, nullable=False, description=None) assert p.get_imports(prefix="") == {"from types import UNSET, Unset", "from typing import Union"} - p = Property(name="test", required=False, default=None, nullable=True) + p = Property(name="test", required=False, default=None, nullable=True, description=None) assert p.get_imports(prefix="") == { "from types import UNSET, Unset", "from typing import Optional", @@ -87,19 +87,19 @@ class TestStringProperty: def test_get_type_string(self): from openapi_python_client.parser.properties import StringProperty - p = StringProperty(name="test", required=True, default=None, nullable=False) + p = StringProperty(name="test", required=True, default=None, nullable=False, description=None) base_type_string = f"str" assert p.get_type_string() == base_type_string - p = StringProperty(name="test", required=True, default=None, nullable=True) + p = StringProperty(name="test", required=True, default=None, nullable=True, description=None) assert p.get_type_string() == f"Optional[{base_type_string}]" - p = StringProperty(name="test", required=False, default=None, nullable=True) + p = StringProperty(name="test", required=False, default=None, nullable=True, description=None) assert p.get_type_string() == f"Union[Unset, None, {base_type_string}]" - p = StringProperty(name="test", required=False, default=None, nullable=False) + p = StringProperty(name="test", required=False, default=None, nullable=False, description=None) assert p.get_type_string() == f"Union[Unset, {base_type_string}]" @@ -107,14 +107,14 @@ class TestDateTimeProperty: def test_get_imports(self): from openapi_python_client.parser.properties import DateTimeProperty - p = DateTimeProperty(name="test", required=True, default=None, nullable=False) + p = DateTimeProperty(name="test", required=True, default=None, nullable=False, description=None) assert p.get_imports(prefix="...") == { "import datetime", "from typing import cast", "from dateutil.parser import isoparse", } - p = DateTimeProperty(name="test", required=False, default=None, nullable=False) + p = DateTimeProperty(name="test", required=False, default=None, nullable=False, description=None) assert p.get_imports(prefix="...") == { "import datetime", "from typing import cast", @@ -123,7 +123,7 @@ def test_get_imports(self): "from ...types import UNSET, Unset", } - p = DateTimeProperty(name="test", required=False, default=None, nullable=True) + p = DateTimeProperty(name="test", required=False, default=None, nullable=True, description=None) assert p.get_imports(prefix="...") == { "import datetime", "from typing import cast", @@ -138,14 +138,14 @@ class TestDateProperty: def test_get_imports(self): from openapi_python_client.parser.properties import DateProperty - p = DateProperty(name="test", required=True, default=None, nullable=False) + p = DateProperty(name="test", required=True, default=None, nullable=False, description=None) assert p.get_imports(prefix="...") == { "import datetime", "from typing import cast", "from dateutil.parser import isoparse", } - p = DateProperty(name="test", required=False, default=None, nullable=False) + p = DateProperty(name="test", required=False, default=None, nullable=False, description=None) assert p.get_imports(prefix="...") == { "import datetime", "from typing import cast", @@ -154,7 +154,7 @@ def test_get_imports(self): "from ...types import UNSET, Unset", } - p = DateProperty(name="test", required=False, default=None, nullable=True) + p = DateProperty(name="test", required=False, default=None, nullable=True, description=None) assert p.get_imports(prefix="...") == { "import datetime", "from typing import cast", @@ -170,13 +170,13 @@ def test_get_imports(self): from openapi_python_client.parser.properties import FileProperty prefix = "..." - p = FileProperty(name="test", required=True, default=None, nullable=False) + p = FileProperty(name="test", required=True, default=None, nullable=False, description=None) assert p.get_imports(prefix=prefix) == { "from io import BytesIO", "from ...types import File", } - p = FileProperty(name="test", required=False, default=None, nullable=False) + p = FileProperty(name="test", required=False, default=None, nullable=False, description=None) assert p.get_imports(prefix=prefix) == { "from io import BytesIO", "from ...types import File", @@ -184,7 +184,7 @@ def test_get_imports(self): "from ...types import UNSET, Unset", } - p = FileProperty(name="test", required=False, default=None, nullable=True) + p = FileProperty(name="test", required=False, default=None, nullable=True, description=None) assert p.get_imports(prefix=prefix) == { "from io import BytesIO", "from ...types import File", @@ -201,21 +201,21 @@ def test_get_type_string(self, mocker): inner_property = mocker.MagicMock() inner_type_string = mocker.MagicMock() inner_property.get_type_string.return_value = inner_type_string - p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=False) + p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=False, description=None) base_type_string = f"List[{inner_type_string}]" assert p.get_type_string() == base_type_string - p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=True) + p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=True, description=None) assert p.get_type_string() == f"Optional[{base_type_string}]" assert p.get_type_string(no_optional=True) == base_type_string - p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=True) + p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=True, description=None) assert p.get_type_string() == f"Union[Unset, None, {base_type_string}]" assert p.get_type_string(no_optional=True) == base_type_string - p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=False) + p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=False, description=None) assert p.get_type_string() == f"Union[Unset, {base_type_string}]" assert p.get_type_string(no_optional=True) == base_type_string @@ -226,14 +226,14 @@ def test_get_type_imports(self, mocker): inner_import = mocker.MagicMock() inner_property.get_imports.return_value = {inner_import} prefix = "..." - p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=False) + p = ListProperty(name="test", required=True, default=None, inner_property=inner_property, nullable=False, description=None) assert p.get_imports(prefix=prefix) == { inner_import, "from typing import cast, List", } - p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=False) + p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=False, description=None) assert p.get_imports(prefix=prefix) == { inner_import, "from typing import cast, List", @@ -241,7 +241,7 @@ def test_get_type_imports(self, mocker): "from ...types import UNSET, Unset", } - p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=True) + p = ListProperty(name="test", required=False, default=None, inner_property=inner_property, nullable=True, description=None) assert p.get_imports(prefix=prefix) == { inner_import, "from typing import cast, List", @@ -255,22 +255,22 @@ class TestUnionProperty: @pytest.mark.parametrize( "query_parameter,nullable,required,no_optional,expected", [ - (False, False, False, False, "Union[Unset, inner_type_string_1, inner_type_string_2]"), - (False, False, False, True, "Union[inner_type_string_1, inner_type_string_2]"), - (False, False, True, False, "Union[inner_type_string_1, inner_type_string_2]"), - (False, False, True, True, "Union[inner_type_string_1, inner_type_string_2]"), - (False, True, False, False, "Union[Unset, None, inner_type_string_1, inner_type_string_2]"), - (False, True, False, True, "Union[inner_type_string_1, inner_type_string_2]"), - (False, True, True, False, "Union[None, inner_type_string_1, inner_type_string_2]"), - (False, True, True, True, "Union[inner_type_string_1, inner_type_string_2]"), - (True, False, False, False, "Union[Unset, None, inner_type_string_1, inner_type_string_2]"), - (True, False, False, True, "Union[inner_type_string_1, inner_type_string_2]"), - (True, False, True, False, "Union[inner_type_string_1, inner_type_string_2]"), - (True, False, True, True, "Union[inner_type_string_1, inner_type_string_2]"), - (True, True, False, False, "Union[Unset, None, inner_type_string_1, inner_type_string_2]"), - (True, True, False, True, "Union[inner_type_string_1, inner_type_string_2]"), - (True, True, True, False, "Union[None, inner_type_string_1, inner_type_string_2]"), - (True, True, True, True, "Union[inner_type_string_1, inner_type_string_2]"), + (False, False, False, False, "Union[Unset, inner_type_string_1, inner_type_string_2, UnknownType]"), + (False, False, False, True, "Union[inner_type_string_1, inner_type_string_2, UnknownType]"), + (False, False, True, False, "Union[inner_type_string_1, inner_type_string_2, UnknownType]"), + (False, False, True, True, "Union[inner_type_string_1, inner_type_string_2, UnknownType]"), + (False, True, False, False, "Union[Unset, None, inner_type_string_1, inner_type_string_2, UnknownType]"), + (False, True, False, True, "Union[inner_type_string_1, inner_type_string_2, UnknownType]"), + (False, True, True, False, "Union[None, inner_type_string_1, inner_type_string_2, UnknownType]"), + (False, True, True, True, "Union[inner_type_string_1, inner_type_string_2, UnknownType]"), + (True, False, False, False, "Union[Unset, None, inner_type_string_1, inner_type_string_2, UnknownType]"), + (True, False, False, True, "Union[inner_type_string_1, inner_type_string_2, UnknownType]"), + (True, False, True, False, "Union[inner_type_string_1, inner_type_string_2, UnknownType]"), + (True, False, True, True, "Union[inner_type_string_1, inner_type_string_2, UnknownType]"), + (True, True, False, False, "Union[Unset, None, inner_type_string_1, inner_type_string_2, UnknownType]"), + (True, True, False, True, "Union[inner_type_string_1, inner_type_string_2, UnknownType]"), + (True, True, True, False, "Union[None, inner_type_string_1, inner_type_string_2, UnknownType]"), + (True, True, True, True, "Union[inner_type_string_1, inner_type_string_2, UnknownType]"), ], ) def test_get_type_string(self, mocker, query_parameter, nullable, required, no_optional, expected): @@ -286,6 +286,9 @@ def test_get_type_string(self, mocker, query_parameter, nullable, required, no_o default=None, inner_properties=[inner_property_1, inner_property_2], nullable=nullable, + discriminator_property=None, + discriminator_mappings=None, + description=None, ) assert p.get_type_string(query_parameter=query_parameter, no_optional=no_optional) == expected @@ -306,6 +309,9 @@ def test_get_imports(self, mocker): default=None, inner_properties=[inner_property_1, inner_property_2], nullable=False, + description=None, + discriminator_mappings=None, + discriminator_property=None, ) assert p.get_imports(prefix=prefix) == { @@ -320,6 +326,9 @@ def test_get_imports(self, mocker): default=None, inner_properties=[inner_property_1, inner_property_2], nullable=False, + description=None, + discriminator_mappings=None, + discriminator_property=None, ) assert p.get_imports(prefix=prefix) == { inner_import_1, @@ -335,6 +344,9 @@ def test_get_imports(self, mocker): default=None, inner_properties=[inner_property_1, inner_property_2], nullable=True, + description=None, + discriminator_mappings=None, + discriminator_property=None, ) assert p.get_imports(prefix=prefix) == { inner_import_1, @@ -360,6 +372,7 @@ def test_get_type_string(self, mocker): nullable=False, reference=fake_reference, value_type=str, + description=None, ) base_type_string = f"MyTestEnum" @@ -374,6 +387,7 @@ def test_get_type_string(self, mocker): nullable=True, reference=fake_reference, value_type=str, + description=None, ) assert p.get_type_string() == f"Optional[{base_type_string}]" assert p.get_type_string(no_optional=True) == base_type_string @@ -386,6 +400,7 @@ def test_get_type_string(self, mocker): nullable=True, reference=fake_reference, value_type=str, + description=None, ) assert p.get_type_string() == f"Union[Unset, None, {base_type_string}]" assert p.get_type_string(no_optional=True) == base_type_string @@ -398,6 +413,7 @@ def test_get_type_string(self, mocker): nullable=False, reference=fake_reference, value_type=str, + description=None, ) assert p.get_type_string() == f"Union[Unset, {base_type_string}]" assert p.get_type_string(no_optional=True) == base_type_string @@ -416,6 +432,7 @@ def test_get_imports(self, mocker): nullable=False, reference=fake_reference, value_type=str, + description=None, ) assert enum_property.get_imports(prefix=prefix) == { @@ -430,6 +447,7 @@ def test_get_imports(self, mocker): nullable=False, reference=fake_reference, value_type=str, + description=None, ) assert enum_property.get_imports(prefix=prefix) == { f"from {prefix}models.{fake_reference.module_name} import {fake_reference.class_name}", @@ -445,6 +463,7 @@ def test_get_imports(self, mocker): nullable=True, reference=fake_reference, value_type=str, + description=None, ) assert enum_property.get_imports(prefix=prefix) == { f"from {prefix}models.{fake_reference.module_name} import {fake_reference.class_name}", @@ -505,6 +524,7 @@ def test_property_from_data_str_enum(self, mocker): reference=Reference(class_name="ParentAnEnum", module_name="parent_an_enum"), value_type=str, default="ParentAnEnum.B", + description=None, ) assert schemas != new_schemas, "Provided Schemas was mutated" assert new_schemas.enums == { @@ -536,6 +556,7 @@ def test_property_from_data_int_enum(self, mocker): reference=Reference(class_name="ParentAnEnum", module_name="parent_an_enum"), value_type=int, default="ParentAnEnum.VALUE_3", + description=None, ) assert schemas != new_schemas, "Provided Schemas was mutated" assert new_schemas.enums == { @@ -556,6 +577,7 @@ def test_property_from_data_ref_enum(self): values={"A": "a"}, value_type=str, reference=Reference(class_name="MyEnum", module_name="my_enum"), + description=None, ) schemas = Schemas(enums={"MyEnum": existing_enum}) @@ -569,6 +591,7 @@ def test_property_from_data_ref_enum(self): values={"A": "a"}, value_type=str, reference=Reference(class_name="MyEnum", module_name="my_enum"), + description=None, ) assert schemas == new_schemas @@ -667,7 +690,7 @@ def test_property_from_data_simple_types(self, openapi_type, prop_type, python_t name=name, required=required, data=data, schemas=schemas, parent_name="parent" ) - assert p == prop_type(name=name, required=required, default=python_type(data.default), nullable=False) + assert p == prop_type(name=name, required=required, default=python_type(data.default), nullable=False, description=None) assert new_schemas == schemas # Test nullable values @@ -675,7 +698,7 @@ def test_property_from_data_simple_types(self, openapi_type, prop_type, python_t data.nullable = True p, _ = property_from_data(name=name, required=required, data=data, schemas=schemas, parent_name="parent") - assert p == prop_type(name=name, required=required, default=python_type(data.default), nullable=True) + assert p == prop_type(name=name, required=required, default=python_type(data.default), nullable=True, description=None) # Test bad default value data.default = "a" @@ -766,7 +789,7 @@ def test_property_from_data_no_valid_props_in_data(self): name="blah", required=True, data=data, schemas=schemas, parent_name="parent" ) - assert prop == NoneProperty(name="blah", required=True, nullable=False, default=None) + assert prop == NoneProperty(name="blah", required=True, nullable=False, default=None, description=None) assert new_schemas == schemas def test_property_from_data_validation_error(self, mocker): @@ -877,14 +900,17 @@ def test_property_from_data_union(self, mocker): p, s = property_from_data(name=name, required=required, data=data, schemas=Schemas(), parent_name="parent") - FloatProperty.assert_called_once_with(name=name, required=required, default=0.0, nullable=False) - IntProperty.assert_called_once_with(name=name, required=required, default=0, nullable=False) + FloatProperty.assert_called_once_with(name=name, required=required, default=0.0, nullable=False, description=None) + IntProperty.assert_called_once_with(name=name, required=required, default=0, nullable=False, description=None) UnionProperty.assert_called_once_with( name=name, required=required, default=None, inner_properties=[FloatProperty.return_value, IntProperty.return_value], nullable=False, + description=None, + discriminator_property=None, + discriminator_mappings={}, ) assert p == UnionProperty.return_value assert s == Schemas() @@ -914,7 +940,7 @@ def test__string_based_property_no_format(self): p = _string_based_property(name=name, required=required, data=data) - assert p == StringProperty(name=name, required=required, nullable=True, default="'\\\\\"hello world\\\\\"'") + assert p == StringProperty(name=name, required=required, nullable=True, default="'\\\\\"hello world\\\\\"'", description=None) data.pattern = "abcdef" data.nullable = False @@ -925,7 +951,7 @@ def test__string_based_property_no_format(self): data=data, ) assert p == StringProperty( - name=name, required=required, nullable=False, default="'\\\\\"hello world\\\\\"'", pattern="abcdef" + name=name, required=required, nullable=False, default="'\\\\\"hello world\\\\\"'", pattern="abcdef", description=None ) def test__string_based_property_datetime_format(self): @@ -940,7 +966,7 @@ def test__string_based_property_datetime_format(self): p = _string_based_property(name=name, required=required, data=data) assert p == DateTimeProperty( - name=name, required=required, nullable=True, default="isoparse('2020-11-06T12:00:00')" + name=name, required=required, nullable=True, default="isoparse('2020-11-06T12:00:00')", description=None ) # Test bad default @@ -957,7 +983,7 @@ def test__string_based_property_date_format(self): p = _string_based_property(name=name, required=required, data=data) - assert p == DateProperty(name=name, required=required, nullable=True, default="isoparse('2020-11-06').date()") + assert p == DateProperty(name=name, required=required, nullable=True, default="isoparse('2020-11-06').date()", description=None) # Test bad default data.default = "a" @@ -972,7 +998,7 @@ def test__string_based_property_binary_format(self): data = oai.Schema.construct(type="string", schema_format="binary", nullable=True, default="a") p = _string_based_property(name=name, required=required, data=data) - assert p == FileProperty(name=name, required=required, nullable=True, default=None) + assert p == FileProperty(name=name, required=required, nullable=True, default=None, description=None) def test__string_based_property_unsupported_format(self, mocker): from openapi_python_client.parser.properties import StringProperty, _string_based_property @@ -983,7 +1009,7 @@ def test__string_based_property_unsupported_format(self, mocker): p = _string_based_property(name=name, required=required, data=data) - assert p == StringProperty(name=name, required=required, nullable=True, default=None) + assert p == StringProperty(name=name, required=required, nullable=True, default=None, description=None) def test_build_schemas(mocker): @@ -1062,7 +1088,7 @@ def test_build_enums(mocker): (False, False), ( oai.Schema.construct(type="string"), - StringProperty(name="AdditionalProperty", required=True, nullable=False, default=None), + StringProperty(name="AdditionalProperty", required=True, nullable=False, default=None,description=None), ), ], ) @@ -1102,8 +1128,8 @@ def test_build_model_property(additional_properties_schema, expected_additional_ default=None, reference=Reference(class_name="ParentMyModel", module_name="parent_my_model"), references=[], - required_properties=[StringProperty(name="req", required=True, nullable=False, default=None)], - optional_properties=[DateTimeProperty(name="opt", required=False, nullable=False, default=None)], + required_properties=[StringProperty(name="req", required=True, nullable=False, default=None, description=None)], + optional_properties=[DateTimeProperty(name="opt", required=False, nullable=False, default=None, description=None)], description=data.description, relative_imports={ "from dateutil.parser import isoparse", diff --git a/tests/test_parser/test_responses.py b/tests/test_parser/test_responses.py index eb20fb338..cbefbf593 100644 --- a/tests/test_parser/test_responses.py +++ b/tests/test_parser/test_responses.py @@ -9,12 +9,12 @@ def test_response_from_data_no_content(): from openapi_python_client.parser.responses import Response, response_from_data response, schemas = response_from_data( - status_code=200, data=oai.Response.construct(description=""), schemas=Schemas(), parent_name="parent" + status_code=200, data=oai.Response.construct(description="description"), schemas=Schemas(), parent_name="parent" ) assert response == Response( status_code=200, - prop=NoneProperty(name="response_200", default=None, nullable=False, required=True), + prop=NoneProperty(name="response_200", default=None, nullable=False, required=True, description=None), source="None", ) @@ -22,7 +22,7 @@ def test_response_from_data_no_content(): def test_response_from_data_unsupported_content_type(): from openapi_python_client.parser.responses import response_from_data - data = oai.Response.construct(description="", content={"blah": None}) + data = oai.Response.construct(description="description", content={"blah": None}) response, schemas = response_from_data(status_code=200, data=data, schemas=Schemas(), parent_name="parent") assert response == ParseError(data=data, detail="Unsupported content_type {'blah': None}") @@ -33,10 +33,9 @@ def test_response_from_data_no_content_schema(): data = oai.Response.construct(description="", content={"application/json": oai.MediaType.construct()}) response, schemas = response_from_data(status_code=200, data=data, schemas=Schemas(), parent_name="parent") - assert response == Response( status_code=200, - prop=NoneProperty(name="response_200", default=None, nullable=False, required=True), + prop=NoneProperty(name="response_200", default=None, nullable=False, required=True, description=None), source="None", ) @@ -46,7 +45,7 @@ def test_response_from_data_property_error(mocker): property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(PropertyError(), Schemas())) data = oai.Response.construct( - description="", content={"application/json": oai.MediaType.construct(media_type_schema="something")} + description="description", content={"application/json": oai.MediaType.construct(media_type_schema="something")} ) response, schemas = responses.response_from_data( status_code=400, data=data, schemas=Schemas(), parent_name="parent" @@ -61,7 +60,7 @@ def test_response_from_data_property_error(mocker): def test_response_from_data_property(mocker): from openapi_python_client.parser import responses - prop = StringProperty(name="prop", required=True, nullable=False, default=None) + prop = StringProperty(name="prop", required=True, nullable=False, default=None, description=None) property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas())) data = oai.Response.construct( description="", content={"application/json": oai.MediaType.construct(media_type_schema="something")} @@ -78,3 +77,25 @@ def test_response_from_data_property(mocker): property_from_data.assert_called_once_with( name="response_400", required=True, data="something", schemas=Schemas(), parent_name="parent" ) + + +def test_response_from_data_property_of_type_text_yaml(mocker): + from openapi_python_client.parser import responses + + prop = StringProperty(name="prop", required=True, nullable=False, default=None, description=None) + property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas())) + data = oai.Response.construct( + description="", content={"text/yaml": oai.MediaType.construct(media_type_schema="something")} + ) + response, schemas = responses.response_from_data( + status_code=400, data=data, schemas=Schemas(), parent_name="parent" + ) + + assert response == responses.Response( + status_code=400, + prop=prop, + source="response.yaml", + ) + property_from_data.assert_called_once_with( + name="response_400", required=True, data="something", schemas=Schemas(), parent_name="parent" + ) diff --git a/tests/test_templates/endpoint_module.py b/tests/test_templates/endpoint_module.py index def57a78f..84a7d13f9 100644 --- a/tests/test_templates/endpoint_module.py +++ b/tests/test_templates/endpoint_module.py @@ -2,6 +2,7 @@ import httpx from attr import asdict +from ruamel.yaml import YAML from ...client import AuthenticatedClient, Client from ...types import Response @@ -13,6 +14,7 @@ def _get_kwargs( *, client: AuthenticatedClient, + yaml_body: Json, form_data: FormBody, multipart_data: MultiPartBody, json_body: Json, @@ -54,12 +56,14 @@ def _build_response(*, response: httpx.Response) -> Response[Union[str, int]]: def sync_detailed( *, client: AuthenticatedClient, + yaml_body: Json, form_data: FormBody, multipart_data: MultiPartBody, json_body: Json, ) -> Response[Union[str, int]]: kwargs = _get_kwargs( client=client, + yaml_body=yaml_body, form_data=form_data, multipart_data=multipart_data, json_body=json_body, @@ -75,6 +79,7 @@ def sync_detailed( def sync( *, client: AuthenticatedClient, + yaml_body: Json, form_data: FormBody, multipart_data: MultiPartBody, json_body: Json, @@ -83,6 +88,7 @@ def sync( return sync_detailed( client=client, + yaml_body=yaml_body, form_data=form_data, multipart_data=multipart_data, json_body=json_body, @@ -92,12 +98,14 @@ def sync( async def asyncio_detailed( *, client: AuthenticatedClient, + yaml_body: Json, form_data: FormBody, multipart_data: MultiPartBody, json_body: Json, ) -> Response[Union[str, int]]: kwargs = _get_kwargs( client=client, + yaml_body=yaml_body, form_data=form_data, multipart_data=multipart_data, json_body=json_body, @@ -112,6 +120,7 @@ async def asyncio_detailed( async def asyncio( *, client: AuthenticatedClient, + yaml_body: Json, form_data: FormBody, multipart_data: MultiPartBody, json_body: Json, @@ -121,6 +130,7 @@ async def asyncio( return ( await asyncio_detailed( client=client, + yaml_body=yaml_body, form_data=form_data, multipart_data=multipart_data, json_body=json_body, diff --git a/tests/test_templates/test_endpoint_module.py b/tests/test_templates/test_endpoint_module.py index 082ca84b3..b15f5a973 100644 --- a/tests/test_templates/test_endpoint_module.py +++ b/tests/test_templates/test_endpoint_module.py @@ -20,6 +20,8 @@ def test_async_module(template, mocker): header_param.name = "headerParam" header_param.to_string.return_value = "header_param_1: str" + yaml_body = mocker.MagicMock(template=None, python_name="yaml_body") + yaml_body.get_type_string.return_value = "Json" form_body_reference = mocker.MagicMock(class_name="FormBody") multipart_body_reference = mocker.MagicMock(class_name="MultiPartBody") json_body = mocker.MagicMock(template=None, python_name="json_body") @@ -37,6 +39,7 @@ def test_async_module(template, mocker): requires_security=True, path_parameters=[], query_parameters=[], + yaml_body=yaml_body, form_body_reference=form_body_reference, multipart_body_reference=multipart_body_reference, json_body=json_body, diff --git a/tests/test_templates/test_property_templates/test_date_property/test_date_property.py b/tests/test_templates/test_property_templates/test_date_property/test_date_property.py index 3a8ad435f..5f6ee6921 100644 --- a/tests/test_templates/test_property_templates/test_date_property/test_date_property.py +++ b/tests/test_templates/test_property_templates/test_date_property/test_date_property.py @@ -11,6 +11,7 @@ def test_required_not_nullable(): required=True, nullable=False, default=None, + description=None, ) here = Path(__file__).parent templates_dir = here.parent.parent.parent.parent / "openapi_python_client" / "templates" @@ -33,6 +34,7 @@ def test_required_nullable(): required=True, nullable=True, default=None, + description=None, ) here = Path(__file__).parent templates_dir = here.parent.parent.parent.parent / "openapi_python_client" / "templates" @@ -55,6 +57,7 @@ def test_optional_nullable(): required=False, nullable=True, default=None, + description=None, ) here = Path(__file__).parent templates_dir = here.parent.parent.parent.parent / "openapi_python_client" / "templates"