Skip to content

Commit b0e4320

Browse files
committed
Add array of scalar and JSON objects to multipart integration tests
1 parent 023a1d4 commit b0e4320

File tree

10 files changed

+232
-129
lines changed

10 files changed

+232
-129
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ jobs:
158158
- "pdm.minimal.lock"
159159
services:
160160
openapi-test-server:
161-
image: ghcr.io/openapi-generators/openapi-test-server:0.2.0
161+
image: ghcr.io/openapi-generators/openapi-test-server:0.2.1
162162
ports:
163163
- "3000:3000"
164164
steps:

end_to_end_tests/test_end_to_end.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_generate_dir_already_exists():
266266

267267

268268
def test_update_integration_tests():
269-
url = "https://raw.githubusercontent.com/openapi-generators/openapi-test-server/refs/tags/v0.2.0/openapi.yaml"
269+
url = "https://raw.githubusercontent.com/openapi-generators/openapi-test-server/refs/tags/v0.2.1/openapi.yaml"
270270
source_path = Path(__file__).parent.parent / "integration-tests"
271271
temp_dir = Path.cwd() / "test_update_integration_tests"
272272
shutil.rmtree(temp_dir, ignore_errors=True)

integration-tests/integration_tests/models/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
"""Contains all the data models used in inputs/outputs"""
22

3+
from .an_object import AnObject
4+
from .file import File
35
from .post_body_multipart_body import PostBodyMultipartBody
46
from .post_body_multipart_response_200 import PostBodyMultipartResponse200
5-
from .post_body_multipart_response_200_files_item import PostBodyMultipartResponse200FilesItem
67
from .post_parameters_header_response_200 import PostParametersHeaderResponse200
78
from .problem import Problem
89
from .public_error import PublicError
910

1011
__all__ = (
12+
"AnObject",
13+
"File",
1114
"PostBodyMultipartBody",
1215
"PostBodyMultipartResponse200",
13-
"PostBodyMultipartResponse200FilesItem",
1416
"PostParametersHeaderResponse200",
1517
"Problem",
1618
"PublicError",
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from collections.abc import Mapping
2+
from typing import Any, TypeVar
3+
4+
from attrs import define as _attrs_define
5+
from attrs import field as _attrs_field
6+
7+
T = TypeVar("T", bound="AnObject")
8+
9+
10+
@_attrs_define
11+
class AnObject:
12+
"""
13+
Attributes:
14+
an_int (int):
15+
a_float (float):
16+
"""
17+
18+
an_int: int
19+
a_float: float
20+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
21+
22+
def to_dict(self) -> dict[str, Any]:
23+
an_int = self.an_int
24+
25+
a_float = self.a_float
26+
27+
field_dict: dict[str, Any] = {}
28+
field_dict.update(self.additional_properties)
29+
field_dict.update(
30+
{
31+
"an_int": an_int,
32+
"a_float": a_float,
33+
}
34+
)
35+
36+
return field_dict
37+
38+
@classmethod
39+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
40+
d = dict(src_dict)
41+
an_int = d.pop("an_int")
42+
43+
a_float = d.pop("a_float")
44+
45+
an_object = cls(
46+
an_int=an_int,
47+
a_float=a_float,
48+
)
49+
50+
an_object.additional_properties = d
51+
return an_object
52+
53+
@property
54+
def additional_keys(self) -> list[str]:
55+
return list(self.additional_properties.keys())
56+
57+
def __getitem__(self, key: str) -> Any:
58+
return self.additional_properties[key]
59+
60+
def __setitem__(self, key: str, value: Any) -> None:
61+
self.additional_properties[key] = value
62+
63+
def __delitem__(self, key: str) -> None:
64+
del self.additional_properties[key]
65+
66+
def __contains__(self, key: str) -> bool:
67+
return key in self.additional_properties

integration-tests/integration_tests/models/post_body_multipart_response_200_files_item.py renamed to integration-tests/integration_tests/models/file.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
from ..types import UNSET, Unset
88

9-
T = TypeVar("T", bound="PostBodyMultipartResponse200FilesItem")
9+
T = TypeVar("T", bound="File")
1010

1111

1212
@_attrs_define
13-
class PostBodyMultipartResponse200FilesItem:
13+
class File:
1414
"""
1515
Attributes:
1616
data (Union[Unset, str]): Echo of content of the 'file' input parameter from the form.
@@ -51,14 +51,14 @@ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
5151

5252
content_type = d.pop("content_type", UNSET)
5353

54-
post_body_multipart_response_200_files_item = cls(
54+
file = cls(
5555
data=data,
5656
name=name,
5757
content_type=content_type,
5858
)
5959

60-
post_body_multipart_response_200_files_item.additional_properties = d
61-
return post_body_multipart_response_200_files_item
60+
file.additional_properties = d
61+
return file
6262

6363
@property
6464
def additional_keys(self) -> list[str]:

integration-tests/integration_tests/models/post_body_multipart_body.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
import datetime
2+
import json
13
from collections.abc import Mapping
24
from io import BytesIO
3-
from typing import Any, TypeVar
5+
from typing import TYPE_CHECKING, Any, TypeVar
46

57
from attrs import define as _attrs_define
68
from attrs import field as _attrs_field
9+
from dateutil.parser import isoparse
710

811
from .. import types
912
from ..types import File
1013

14+
if TYPE_CHECKING:
15+
from ..models.an_object import AnObject
16+
17+
1118
T = TypeVar("T", bound="PostBodyMultipartBody")
1219

1320

@@ -18,11 +25,15 @@ class PostBodyMultipartBody:
1825
a_string (str):
1926
files (list[File]):
2027
description (str):
28+
objects (list['AnObject']):
29+
times (list[datetime.datetime]):
2130
"""
2231

2332
a_string: str
2433
files: list[File]
2534
description: str
35+
objects: list["AnObject"]
36+
times: list[datetime.datetime]
2637
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
2738

2839
def to_dict(self) -> dict[str, Any]:
@@ -36,13 +47,25 @@ def to_dict(self) -> dict[str, Any]:
3647

3748
description = self.description
3849

50+
objects = []
51+
for objects_item_data in self.objects:
52+
objects_item = objects_item_data.to_dict()
53+
objects.append(objects_item)
54+
55+
times = []
56+
for times_item_data in self.times:
57+
times_item = times_item_data.isoformat()
58+
times.append(times_item)
59+
3960
field_dict: dict[str, Any] = {}
4061
field_dict.update(self.additional_properties)
4162
field_dict.update(
4263
{
4364
"a_string": a_string,
4465
"files": files,
4566
"description": description,
67+
"objects": objects,
68+
"times": times,
4669
}
4770
)
4871

@@ -58,13 +81,21 @@ def to_multipart(self) -> types.RequestFiles:
5881

5982
files.append(("description", (None, str(self.description).encode(), "text/plain")))
6083

84+
for objects_item_element in self.objects:
85+
files.append(("objects", (None, json.dumps(objects_item_element.to_dict()).encode(), "application/json")))
86+
87+
for times_item_element in self.times:
88+
files.append(("times", (None, times_item_element.isoformat().encode(), "text/plain")))
89+
6190
for prop_name, prop in self.additional_properties.items():
6291
files.append((prop_name, (None, str(prop).encode(), "text/plain")))
6392

6493
return files
6594

6695
@classmethod
6796
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
97+
from ..models.an_object import AnObject
98+
6899
d = dict(src_dict)
69100
a_string = d.pop("a_string")
70101

@@ -77,10 +108,26 @@ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
77108

78109
description = d.pop("description")
79110

111+
objects = []
112+
_objects = d.pop("objects")
113+
for objects_item_data in _objects:
114+
objects_item = AnObject.from_dict(objects_item_data)
115+
116+
objects.append(objects_item)
117+
118+
times = []
119+
_times = d.pop("times")
120+
for times_item_data in _times:
121+
times_item = isoparse(times_item_data)
122+
123+
times.append(times_item)
124+
80125
post_body_multipart_body = cls(
81126
a_string=a_string,
82127
files=files,
83128
description=description,
129+
objects=objects,
130+
times=times,
84131
)
85132

86133
post_body_multipart_body.additional_properties = d

integration-tests/integration_tests/models/post_body_multipart_response_200.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import datetime
12
from collections.abc import Mapping
23
from typing import TYPE_CHECKING, Any, TypeVar
34

45
from attrs import define as _attrs_define
56
from attrs import field as _attrs_field
7+
from dateutil.parser import isoparse
68

79
if TYPE_CHECKING:
8-
from ..models.post_body_multipart_response_200_files_item import PostBodyMultipartResponse200FilesItem
10+
from ..models.an_object import AnObject
11+
from ..models.file import File
912

1013

1114
T = TypeVar("T", bound="PostBodyMultipartResponse200")
@@ -17,12 +20,16 @@ class PostBodyMultipartResponse200:
1720
Attributes:
1821
a_string (str): Echo of the 'a_string' input parameter from the form.
1922
description (str): Echo of the 'description' input parameter from the form.
20-
files (list['PostBodyMultipartResponse200FilesItem']):
23+
files (list['File']):
24+
times (list[datetime.datetime]):
25+
objects (list['AnObject']):
2126
"""
2227

2328
a_string: str
2429
description: str
25-
files: list["PostBodyMultipartResponse200FilesItem"]
30+
files: list["File"]
31+
times: list[datetime.datetime]
32+
objects: list["AnObject"]
2633
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
2734

2835
def to_dict(self) -> dict[str, Any]:
@@ -35,21 +42,34 @@ def to_dict(self) -> dict[str, Any]:
3542
files_item = files_item_data.to_dict()
3643
files.append(files_item)
3744

45+
times = []
46+
for times_item_data in self.times:
47+
times_item = times_item_data.isoformat()
48+
times.append(times_item)
49+
50+
objects = []
51+
for objects_item_data in self.objects:
52+
objects_item = objects_item_data.to_dict()
53+
objects.append(objects_item)
54+
3855
field_dict: dict[str, Any] = {}
3956
field_dict.update(self.additional_properties)
4057
field_dict.update(
4158
{
4259
"a_string": a_string,
4360
"description": description,
4461
"files": files,
62+
"times": times,
63+
"objects": objects,
4564
}
4665
)
4766

4867
return field_dict
4968

5069
@classmethod
5170
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
52-
from ..models.post_body_multipart_response_200_files_item import PostBodyMultipartResponse200FilesItem
71+
from ..models.an_object import AnObject
72+
from ..models.file import File
5373

5474
d = dict(src_dict)
5575
a_string = d.pop("a_string")
@@ -59,14 +79,30 @@ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
5979
files = []
6080
_files = d.pop("files")
6181
for files_item_data in _files:
62-
files_item = PostBodyMultipartResponse200FilesItem.from_dict(files_item_data)
82+
files_item = File.from_dict(files_item_data)
6383

6484
files.append(files_item)
6585

86+
times = []
87+
_times = d.pop("times")
88+
for times_item_data in _times:
89+
times_item = isoparse(times_item_data)
90+
91+
times.append(times_item)
92+
93+
objects = []
94+
_objects = d.pop("objects")
95+
for objects_item_data in _objects:
96+
objects_item = AnObject.from_dict(objects_item_data)
97+
98+
objects.append(objects_item)
99+
66100
post_body_multipart_response_200 = cls(
67101
a_string=a_string,
68102
description=description,
69103
files=files,
104+
times=times,
105+
objects=objects,
70106
)
71107

72108
post_body_multipart_response_200.additional_properties = d

0 commit comments

Comments
 (0)