Skip to content

Commit 1aa1b51

Browse files
committed
Merge branch '2.x' into live-generated-code-tests-bl
2 parents 90df669 + d76c0fc commit 1aa1b51

File tree

22 files changed

+974
-113
lines changed

22 files changed

+974
-113
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ htmlcov/
3636
# Generated end to end test data
3737
my-test-api-client/
3838
custom-e2e/
39-
3-1-features-client
39+
3-1-features-client
40+
localtest

end_to_end_tests/baseline_openapi_3.0.json

+32-3
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,20 @@
991991
}
992992
}
993993
},
994+
"/responses/reference": {
995+
"get": {
996+
"tags": [
997+
"responses"
998+
],
999+
"summary": "Endpoint using predefined response",
1000+
"operationId": "reference_response",
1001+
"responses": {
1002+
"200": {
1003+
"$ref": "#/components/responses/AResponse"
1004+
}
1005+
}
1006+
}
1007+
},
9941008
"/auth/token_with_cookie": {
9951009
"get": {
9961010
"tags": [
@@ -2864,7 +2878,8 @@
28642878
"propertyName": "modelType",
28652879
"mapping": {
28662880
"type1": "#/components/schemas/ADiscriminatedUnionType1",
2867-
"type2": "#/components/schemas/ADiscriminatedUnionType2"
2881+
"type2": "#/components/schemas/ADiscriminatedUnionType2",
2882+
"type2-another-value": "#/components/schemas/ADiscriminatedUnionType2"
28682883
}
28692884
},
28702885
"oneOf": [
@@ -2882,15 +2897,17 @@
28822897
"modelType": {
28832898
"type": "string"
28842899
}
2885-
}
2900+
},
2901+
"required": ["modelType"]
28862902
},
28872903
"ADiscriminatedUnionType2": {
28882904
"type": "object",
28892905
"properties": {
28902906
"modelType": {
28912907
"type": "string"
28922908
}
2893-
}
2909+
},
2910+
"required": ["modelType"]
28942911
}
28952912
},
28962913
"parameters": {
@@ -2971,6 +2988,18 @@
29712988
}
29722989
}
29732990
}
2991+
},
2992+
"responses": {
2993+
"AResponse": {
2994+
"description": "OK",
2995+
"content": {
2996+
"application/json": {
2997+
"schema": {
2998+
"$ref": "#/components/schemas/AModel"
2999+
}
3000+
}
3001+
}
3002+
}
29743003
}
29753004
}
29763005
}

end_to_end_tests/baseline_openapi_3.1.yaml

+27-3
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,20 @@ info:
983983
}
984984
}
985985
},
986+
"/responses/reference": {
987+
"get": {
988+
"tags": [
989+
"responses"
990+
],
991+
"summary": "Endpoint using predefined response",
992+
"operationId": "reference_response",
993+
"responses": {
994+
"200": {
995+
"$ref": "#/components/responses/AResponse"
996+
}
997+
}
998+
}
999+
},
9861000
"/auth/token_with_cookie": {
9871001
"get": {
9881002
"tags": [
@@ -2858,7 +2872,8 @@ info:
28582872
"propertyName": "modelType",
28592873
"mapping": {
28602874
"type1": "#/components/schemas/ADiscriminatedUnionType1",
2861-
"type2": "#/components/schemas/ADiscriminatedUnionType2"
2875+
"type2": "#/components/schemas/ADiscriminatedUnionType2",
2876+
"type2-another-value": "#/components/schemas/ADiscriminatedUnionType2"
28622877
}
28632878
},
28642879
"oneOf": [
@@ -2876,15 +2891,17 @@ info:
28762891
"modelType": {
28772892
"type": "string"
28782893
}
2879-
}
2894+
},
2895+
"required": ["modelType"]
28802896
},
28812897
"ADiscriminatedUnionType2": {
28822898
"type": "object",
28832899
"properties": {
28842900
"modelType": {
28852901
"type": "string"
28862902
}
2887-
}
2903+
},
2904+
"required": ["modelType"]
28882905
}
28892906
}
28902907
"parameters": {
@@ -2962,3 +2979,10 @@ info:
29622979
"application/json":
29632980
"schema":
29642981
"$ref": "#/components/schemas/AModel"
2982+
responses:
2983+
AResponse:
2984+
description: OK
2985+
content:
2986+
"application/json":
2987+
"schema":
2988+
"$ref": "#/components/schemas/AModel"

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import types
44

5-
from . import post_responses_unions_simple_before_complex, text_response
5+
from . import post_responses_unions_simple_before_complex, reference_response, text_response
66

77

88
class ResponsesEndpoints:
@@ -19,3 +19,10 @@ def text_response(cls) -> types.ModuleType:
1919
Text Response
2020
"""
2121
return text_response
22+
23+
@classmethod
24+
def reference_response(cls) -> types.ModuleType:
25+
"""
26+
Endpoint using predefined response
27+
"""
28+
return reference_response
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
from http import HTTPStatus
2+
from typing import Any, Dict, Optional, Union
3+
4+
import httpx
5+
6+
from ... import errors
7+
from ...client import AuthenticatedClient, Client
8+
from ...models.a_model import AModel
9+
from ...types import Response
10+
11+
12+
def _get_kwargs() -> Dict[str, Any]:
13+
_kwargs: Dict[str, Any] = {
14+
"method": "get",
15+
"url": "/responses/reference",
16+
}
17+
18+
return _kwargs
19+
20+
21+
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[AModel]:
22+
if response.status_code == 200:
23+
response_200 = AModel.from_dict(response.json())
24+
25+
return response_200
26+
if client.raise_on_unexpected_status:
27+
raise errors.UnexpectedStatus(response.status_code, response.content)
28+
else:
29+
return None
30+
31+
32+
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[AModel]:
33+
return Response(
34+
status_code=HTTPStatus(response.status_code),
35+
content=response.content,
36+
headers=response.headers,
37+
parsed=_parse_response(client=client, response=response),
38+
)
39+
40+
41+
def sync_detailed(
42+
*,
43+
client: Union[AuthenticatedClient, Client],
44+
) -> Response[AModel]:
45+
"""Endpoint using predefined response
46+
47+
Raises:
48+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
49+
httpx.TimeoutException: If the request takes longer than Client.timeout.
50+
51+
Returns:
52+
Response[AModel]
53+
"""
54+
55+
kwargs = _get_kwargs()
56+
57+
response = client.get_httpx_client().request(
58+
**kwargs,
59+
)
60+
61+
return _build_response(client=client, response=response)
62+
63+
64+
def sync(
65+
*,
66+
client: Union[AuthenticatedClient, Client],
67+
) -> Optional[AModel]:
68+
"""Endpoint using predefined response
69+
70+
Raises:
71+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
72+
httpx.TimeoutException: If the request takes longer than Client.timeout.
73+
74+
Returns:
75+
AModel
76+
"""
77+
78+
return sync_detailed(
79+
client=client,
80+
).parsed
81+
82+
83+
async def asyncio_detailed(
84+
*,
85+
client: Union[AuthenticatedClient, Client],
86+
) -> Response[AModel]:
87+
"""Endpoint using predefined response
88+
89+
Raises:
90+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
91+
httpx.TimeoutException: If the request takes longer than Client.timeout.
92+
93+
Returns:
94+
Response[AModel]
95+
"""
96+
97+
kwargs = _get_kwargs()
98+
99+
response = await client.get_async_httpx_client().request(**kwargs)
100+
101+
return _build_response(client=client, response=response)
102+
103+
104+
async def asyncio(
105+
*,
106+
client: Union[AuthenticatedClient, Client],
107+
) -> Optional[AModel]:
108+
"""Endpoint using predefined response
109+
110+
Raises:
111+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
112+
httpx.TimeoutException: If the request takes longer than Client.timeout.
113+
114+
Returns:
115+
AModel
116+
"""
117+
118+
return (
119+
await asyncio_detailed(
120+
client=client,
121+
)
122+
).parsed

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
from typing import Any, Dict, List, Type, TypeVar, Union
1+
from typing import Any, Dict, List, Type, TypeVar
22

33
from attrs import define as _attrs_define
44
from attrs import field as _attrs_field
55

6-
from ..types import UNSET, Unset
7-
86
T = TypeVar("T", bound="ADiscriminatedUnionType1")
97

108

119
@_attrs_define
1210
class ADiscriminatedUnionType1:
1311
"""
1412
Attributes:
15-
model_type (Union[Unset, str]):
13+
model_type (str):
1614
"""
1715

18-
model_type: Union[Unset, str] = UNSET
16+
model_type: str
1917
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)
2018

2119
def to_dict(self) -> Dict[str, Any]:
2220
model_type = self.model_type
2321

2422
field_dict: Dict[str, Any] = {}
2523
field_dict.update(self.additional_properties)
26-
field_dict.update({})
27-
if model_type is not UNSET:
28-
field_dict["modelType"] = model_type
24+
field_dict.update(
25+
{
26+
"modelType": model_type,
27+
}
28+
)
2929

3030
return field_dict
3131

3232
@classmethod
3333
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
3434
d = src_dict.copy()
35-
model_type = d.pop("modelType", UNSET)
35+
model_type = d.pop("modelType")
3636

3737
a_discriminated_union_type_1 = cls(
3838
model_type=model_type,

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
from typing import Any, Dict, List, Type, TypeVar, Union
1+
from typing import Any, Dict, List, Type, TypeVar
22

33
from attrs import define as _attrs_define
44
from attrs import field as _attrs_field
55

6-
from ..types import UNSET, Unset
7-
86
T = TypeVar("T", bound="ADiscriminatedUnionType2")
97

108

119
@_attrs_define
1210
class ADiscriminatedUnionType2:
1311
"""
1412
Attributes:
15-
model_type (Union[Unset, str]):
13+
model_type (str):
1614
"""
1715

18-
model_type: Union[Unset, str] = UNSET
16+
model_type: str
1917
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)
2018

2119
def to_dict(self) -> Dict[str, Any]:
2220
model_type = self.model_type
2321

2422
field_dict: Dict[str, Any] = {}
2523
field_dict.update(self.additional_properties)
26-
field_dict.update({})
27-
if model_type is not UNSET:
28-
field_dict["modelType"] = model_type
24+
field_dict.update(
25+
{
26+
"modelType": model_type,
27+
}
28+
)
2929

3030
return field_dict
3131

3232
@classmethod
3333
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
3434
d = src_dict.copy()
35-
model_type = d.pop("modelType", UNSET)
35+
model_type = d.pop("modelType")
3636

3737
a_discriminated_union_type_2 = cls(
3838
model_type=model_type,

0 commit comments

Comments
 (0)