Skip to content

Commit 122e377

Browse files
committed
Ran checks and addressed some comments for PR #32
1 parent 2de3c57 commit 122e377

File tree

6 files changed

+23
-21
lines changed

6 files changed

+23
-21
lines changed

openapi_python_client/openapi_parser/openapi.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ def dict(d: Dict[str, Dict[str, Any]], /) -> Dict[str, Schema]:
191191

192192
@dataclass
193193
class OpenAPI:
194-
""" Top level OpenAPI spec """
194+
""" Top level OpenAPI document """
195195

196196
title: str
197-
description: str
197+
description: Optional[str]
198198
version: str
199199
schemas: Dict[str, Schema]
200200
endpoint_collections_by_tag: Dict[str, EndpointCollection]
@@ -236,9 +236,7 @@ def _iterate_properties() -> Generator[Property, None, None]:
236236

237237
@staticmethod
238238
def from_dict(d: Dict[str, Dict[str, Any]], /) -> OpenAPI:
239-
""" Create an OpenAPI from dict
240-
:rtype: object
241-
"""
239+
""" Create an OpenAPI from dict """
242240
schemas = Schema.dict(d["components"]["schemas"])
243241
endpoint_collections_by_tag = EndpointCollection.from_dict(d["paths"])
244242
enums = OpenAPI._check_enums(schemas.values(), endpoint_collections_by_tag.values())

openapi_python_client/templates/async_endpoint_module.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import asdict
2-
from typing import Dict, List, Optional, Union, Any, cast
2+
from typing import Any, Dict, List, Optional, Union, cast
33

44
import httpx
55

openapi_python_client/templates/endpoint_module.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import asdict
2-
from typing import Dict, List, Optional, Union, Any, cast
2+
from typing import Any, Dict, List, Optional, Union, cast
33

44
import httpx
55

tests/test_end_to_end/test_end_to_end.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _compare_directories(first: Path, second: Path, /):
2424
_compare_directories(first / sub_path, second / sub_path)
2525

2626

27-
def test_end_to_end(capsys):
27+
def test_end_to_end():
2828
runner = CliRunner()
2929
openapi_path = Path(__file__).parent / "fastapi" / "openapi.json"
3030
config_path = Path(__file__).parent / "config.yml"
@@ -38,7 +38,8 @@ def test_end_to_end(capsys):
3838
_compare_directories(gm_path, output_path)
3939

4040
import mypy.api
41+
4142
out, err, status = mypy.api.run([str(output_path), "--strict"])
42-
assert status == 0, f"Hello Type checking client failed: {err}"
43+
assert status == 0, f"Type checking client failed: {err}"
4344

4445
shutil.rmtree(output_path)

tests/test_openapi_parser/test_properties.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,15 @@ def test_constructor_from_dict(self, mocker):
167167

168168
enum_property = EnumProperty(name="test_enum", required=True, default=None, values={})
169169

170-
assert (
171-
enum_property.constructor_from_dict("my_dict")
172-
== 'MyTestEnum(my_dict["test_enum"])'
173-
)
170+
assert enum_property.constructor_from_dict("my_dict") == 'MyTestEnum(my_dict["test_enum"])'
174171

175-
enum_property = EnumProperty(name="test_enum", required=False,
176-
default=None, values={})
172+
enum_property = EnumProperty(name="test_enum", required=False, default=None, values={})
177173

178174
assert (
179-
enum_property.constructor_from_dict("my_dict")
180-
== 'MyTestEnum(my_dict["test_enum"]) if "test_enum" in my_dict else None'
175+
enum_property.constructor_from_dict("my_dict")
176+
== 'MyTestEnum(my_dict["test_enum"]) if "test_enum" in my_dict else None'
181177
)
182178

183-
184-
185179
def test_values_from_list(self):
186180
from openapi_python_client.openapi_parser.properties import EnumProperty
187181

@@ -402,7 +396,13 @@ def test_property_from_dict_enum_array(self, mocker):
402396

403397
@pytest.mark.parametrize(
404398
"openapi_type,python_type",
405-
[("string", "str"), ("number", "float"), ("integer", "int"), ("boolean", "bool"), ("object", "Dict[Any, Any]"),],
399+
[
400+
("string", "str"),
401+
("number", "float"),
402+
("integer", "int"),
403+
("boolean", "bool"),
404+
("object", "Dict[Any, Any]"),
405+
],
406406
)
407407
def test_property_from_dict_simple_array(self, mocker, openapi_type, python_type):
408408
name = mocker.MagicMock()

tests/test_openapi_parser/test_responses.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def test_constructor(self, mocker):
3232

3333
r = ListRefResponse(200, reference=mocker.MagicMock(class_name="SuperCoolClass"))
3434

35-
assert r.constructor() == "[SuperCoolClass.from_dict(item) for item in cast(List[Dict[str, Any]], response.json())]"
35+
assert (
36+
r.constructor()
37+
== "[SuperCoolClass.from_dict(item) for item in cast(List[Dict[str, Any]], response.json())]"
38+
)
3639

3740

3841
class TestRefResponse:

0 commit comments

Comments
 (0)