Skip to content

Commit 3e64751

Browse files
committed
e2e test: add endpoint with inlined form_body schema
1 parent 871193f commit 3e64751

File tree

6 files changed

+207
-4
lines changed

6 files changed

+207
-4
lines changed

end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
no_response_tests_no_response_get,
1515
octet_stream_tests_octet_stream_get,
1616
post_form_data,
17+
post_form_data_inline,
1718
post_tests_json_body_string,
1819
test_inline_objects,
1920
token_with_cookie_auth_token_with_cookie_get,
@@ -66,6 +67,13 @@ def post_form_data(cls) -> types.ModuleType:
6667
"""
6768
return post_form_data
6869

70+
@classmethod
71+
def post_form_data_inline(cls) -> types.ModuleType:
72+
"""
73+
Post form data (inline schema)
74+
"""
75+
return post_form_data_inline
76+
6977
@classmethod
7078
def upload_file_tests_upload_post(cls) -> types.ModuleType:
7179
"""

end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _get_kwargs(
2323
"headers": headers,
2424
"cookies": cookies,
2525
"timeout": client.get_timeout(),
26-
"data": form_data.to_dict(),
26+
"data": form_data,
2727
}
2828

2929

@@ -41,7 +41,7 @@ def sync_detailed(
4141
client: Client,
4242
form_data: AFormData,
4343
) -> Response[Any]:
44-
"""Post from data
44+
"""Post form data
4545
4646
Post form data
4747
@@ -67,7 +67,7 @@ async def asyncio_detailed(
6767
client: Client,
6868
form_data: AFormData,
6969
) -> Response[Any]:
70-
"""Post from data
70+
"""Post form data
7171
7272
Post form data
7373
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from typing import Any, Dict
2+
3+
import httpx
4+
5+
from ...client import Client
6+
from ...models.post_form_data_inline_data import PostFormDataInlineData
7+
from ...types import Response
8+
9+
10+
def _get_kwargs(
11+
*,
12+
client: Client,
13+
form_data: PostFormDataInlineData,
14+
) -> Dict[str, Any]:
15+
url = "{}/tests/post_form_data_inline".format(client.base_url)
16+
17+
headers: Dict[str, str] = client.get_headers()
18+
cookies: Dict[str, Any] = client.get_cookies()
19+
20+
return {
21+
"method": "post",
22+
"url": url,
23+
"headers": headers,
24+
"cookies": cookies,
25+
"timeout": client.get_timeout(),
26+
"data": form_data,
27+
}
28+
29+
30+
def _build_response(*, response: httpx.Response) -> Response[Any]:
31+
return Response(
32+
status_code=response.status_code,
33+
content=response.content,
34+
headers=response.headers,
35+
parsed=None,
36+
)
37+
38+
39+
def sync_detailed(
40+
*,
41+
client: Client,
42+
form_data: PostFormDataInlineData,
43+
) -> Response[Any]:
44+
"""Post form data (inline schema)
45+
46+
Post form data (inline schema)
47+
48+
Returns:
49+
Response[Any]
50+
"""
51+
52+
kwargs = _get_kwargs(
53+
client=client,
54+
form_data=form_data,
55+
)
56+
57+
response = httpx.request(
58+
verify=client.verify_ssl,
59+
**kwargs,
60+
)
61+
62+
return _build_response(response=response)
63+
64+
65+
async def asyncio_detailed(
66+
*,
67+
client: Client,
68+
form_data: PostFormDataInlineData,
69+
) -> Response[Any]:
70+
"""Post form data (inline schema)
71+
72+
Post form data (inline schema)
73+
74+
Returns:
75+
Response[Any]
76+
"""
77+
78+
kwargs = _get_kwargs(
79+
client=client,
80+
form_data=form_data,
81+
)
82+
83+
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
84+
response = await _client.request(**kwargs)
85+
86+
return _build_response(response=response)

end_to_end_tests/golden-record/my_test_api_client/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from .model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0
4141
from .model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1
4242
from .none import None_
43+
from .post_form_data_inline_data import PostFormDataInlineData
4344
from .post_responses_unions_simple_before_complex_response_200 import PostResponsesUnionsSimpleBeforeComplexResponse200
4445
from .post_responses_unions_simple_before_complex_response_200a_type_1 import (
4546
PostResponsesUnionsSimpleBeforeComplexResponse200AType1,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from typing import Any, Dict, List, Type, TypeVar, Union
2+
3+
import attr
4+
5+
from ..types import UNSET, Unset
6+
7+
T = TypeVar("T", bound="PostFormDataInlineData")
8+
9+
10+
@attr.s(auto_attribs=True)
11+
class PostFormDataInlineData:
12+
"""
13+
Attributes:
14+
a_required_field (str):
15+
an_optional_field (Union[Unset, str]):
16+
"""
17+
18+
a_required_field: str
19+
an_optional_field: Union[Unset, str] = UNSET
20+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
21+
22+
def to_dict(self) -> Dict[str, Any]:
23+
a_required_field = self.a_required_field
24+
an_optional_field = self.an_optional_field
25+
26+
field_dict: Dict[str, Any] = {}
27+
field_dict.update(self.additional_properties)
28+
field_dict.update(
29+
{
30+
"a_required_field": a_required_field,
31+
}
32+
)
33+
if an_optional_field is not UNSET:
34+
field_dict["an_optional_field"] = an_optional_field
35+
36+
return field_dict
37+
38+
@classmethod
39+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
40+
d = src_dict.copy()
41+
a_required_field = d.pop("a_required_field")
42+
43+
an_optional_field = d.pop("an_optional_field", UNSET)
44+
45+
post_form_data_inline_data = cls(
46+
a_required_field=a_required_field,
47+
an_optional_field=an_optional_field,
48+
)
49+
50+
post_form_data_inline_data.additional_properties = d
51+
return post_form_data_inline_data
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

end_to_end_tests/openapi.json

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
"tags": [
218218
"tests"
219219
],
220-
"summary": "Post from data",
220+
"summary": "Post form data",
221221
"description": "Post form data",
222222
"operationId": "post_form_data",
223223
"requestBody": {
@@ -242,6 +242,47 @@
242242
}
243243
}
244244
},
245+
"/tests/post_form_data_inline": {
246+
"post": {
247+
"tags": [
248+
"tests"
249+
],
250+
"summary": "Post form data (inline schema)",
251+
"description": "Post form data (inline schema)",
252+
"operationId": "post_form_data_inline",
253+
"requestBody": {
254+
"content": {
255+
"application/x-www-form-urlencoded": {
256+
"schema": {
257+
"type": "object",
258+
"properties": {
259+
"an_optional_field": {
260+
"type": "string"
261+
},
262+
"a_required_field": {
263+
"type": "string"
264+
}
265+
},
266+
"required": [
267+
"a_required_field"
268+
]
269+
}
270+
}
271+
},
272+
"required": true
273+
},
274+
"responses": {
275+
"200": {
276+
"description": "Successful Response",
277+
"content": {
278+
"application/json": {
279+
"schema": {}
280+
}
281+
}
282+
}
283+
}
284+
}
285+
},
245286
"/tests/upload": {
246287
"post": {
247288
"tags": [

0 commit comments

Comments
 (0)