Skip to content

Commit 379f7cf

Browse files
committed
Refactor mapping association response model and update related API methods
- Replaced `ElementAssociationResponse` with `AssociationResponse` in the mapping association API, ensuring consistency across response types. - Updated method signatures and return types in `create_mapping_association.py` to reflect the new response model. - Removed the obsolete `ElementAssociationResponse` model from the codebase. - Enhanced the `__init__.py` file to include the new `AssociationResponse` model for public access. These changes streamline the API response structure and improve clarity in the mapping association functionality.
1 parent f4f555d commit 379f7cf

31 files changed

Lines changed: 2805 additions & 144 deletions
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
from http import HTTPStatus
2+
from typing import Any
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ... import errors
8+
from ...client import AuthenticatedClient, Client
9+
from ...models.closing_entry_response import ClosingEntryResponse
10+
from ...models.create_closing_entry_request import CreateClosingEntryRequest
11+
from ...models.http_validation_error import HTTPValidationError
12+
from ...types import Response
13+
14+
15+
def _get_kwargs(
16+
graph_id: str,
17+
structure_id: str,
18+
*,
19+
body: CreateClosingEntryRequest,
20+
) -> dict[str, Any]:
21+
headers: dict[str, Any] = {}
22+
23+
_kwargs: dict[str, Any] = {
24+
"method": "post",
25+
"url": "/v1/ledger/{graph_id}/schedules/{structure_id}/closing-entry".format(
26+
graph_id=quote(str(graph_id), safe=""),
27+
structure_id=quote(str(structure_id), safe=""),
28+
),
29+
}
30+
31+
_kwargs["json"] = body.to_dict()
32+
33+
headers["Content-Type"] = "application/json"
34+
35+
_kwargs["headers"] = headers
36+
return _kwargs
37+
38+
39+
def _parse_response(
40+
*, client: AuthenticatedClient | Client, response: httpx.Response
41+
) -> ClosingEntryResponse | HTTPValidationError | None:
42+
if response.status_code == 201:
43+
response_201 = ClosingEntryResponse.from_dict(response.json())
44+
45+
return response_201
46+
47+
if response.status_code == 422:
48+
response_422 = HTTPValidationError.from_dict(response.json())
49+
50+
return response_422
51+
52+
if client.raise_on_unexpected_status:
53+
raise errors.UnexpectedStatus(response.status_code, response.content)
54+
else:
55+
return None
56+
57+
58+
def _build_response(
59+
*, client: AuthenticatedClient | Client, response: httpx.Response
60+
) -> Response[ClosingEntryResponse | HTTPValidationError]:
61+
return Response(
62+
status_code=HTTPStatus(response.status_code),
63+
content=response.content,
64+
headers=response.headers,
65+
parsed=_parse_response(client=client, response=response),
66+
)
67+
68+
69+
def sync_detailed(
70+
graph_id: str,
71+
structure_id: str,
72+
*,
73+
client: AuthenticatedClient,
74+
body: CreateClosingEntryRequest,
75+
) -> Response[ClosingEntryResponse | HTTPValidationError]:
76+
"""Create Closing Entry
77+
78+
Create a draft closing entry from a schedule's facts for a period.
79+
80+
Args:
81+
graph_id (str):
82+
structure_id (str): Schedule structure ID
83+
body (CreateClosingEntryRequest):
84+
85+
Raises:
86+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
87+
httpx.TimeoutException: If the request takes longer than Client.timeout.
88+
89+
Returns:
90+
Response[ClosingEntryResponse | HTTPValidationError]
91+
"""
92+
93+
kwargs = _get_kwargs(
94+
graph_id=graph_id,
95+
structure_id=structure_id,
96+
body=body,
97+
)
98+
99+
response = client.get_httpx_client().request(
100+
**kwargs,
101+
)
102+
103+
return _build_response(client=client, response=response)
104+
105+
106+
def sync(
107+
graph_id: str,
108+
structure_id: str,
109+
*,
110+
client: AuthenticatedClient,
111+
body: CreateClosingEntryRequest,
112+
) -> ClosingEntryResponse | HTTPValidationError | None:
113+
"""Create Closing Entry
114+
115+
Create a draft closing entry from a schedule's facts for a period.
116+
117+
Args:
118+
graph_id (str):
119+
structure_id (str): Schedule structure ID
120+
body (CreateClosingEntryRequest):
121+
122+
Raises:
123+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
124+
httpx.TimeoutException: If the request takes longer than Client.timeout.
125+
126+
Returns:
127+
ClosingEntryResponse | HTTPValidationError
128+
"""
129+
130+
return sync_detailed(
131+
graph_id=graph_id,
132+
structure_id=structure_id,
133+
client=client,
134+
body=body,
135+
).parsed
136+
137+
138+
async def asyncio_detailed(
139+
graph_id: str,
140+
structure_id: str,
141+
*,
142+
client: AuthenticatedClient,
143+
body: CreateClosingEntryRequest,
144+
) -> Response[ClosingEntryResponse | HTTPValidationError]:
145+
"""Create Closing Entry
146+
147+
Create a draft closing entry from a schedule's facts for a period.
148+
149+
Args:
150+
graph_id (str):
151+
structure_id (str): Schedule structure ID
152+
body (CreateClosingEntryRequest):
153+
154+
Raises:
155+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
156+
httpx.TimeoutException: If the request takes longer than Client.timeout.
157+
158+
Returns:
159+
Response[ClosingEntryResponse | HTTPValidationError]
160+
"""
161+
162+
kwargs = _get_kwargs(
163+
graph_id=graph_id,
164+
structure_id=structure_id,
165+
body=body,
166+
)
167+
168+
response = await client.get_async_httpx_client().request(**kwargs)
169+
170+
return _build_response(client=client, response=response)
171+
172+
173+
async def asyncio(
174+
graph_id: str,
175+
structure_id: str,
176+
*,
177+
client: AuthenticatedClient,
178+
body: CreateClosingEntryRequest,
179+
) -> ClosingEntryResponse | HTTPValidationError | None:
180+
"""Create Closing Entry
181+
182+
Create a draft closing entry from a schedule's facts for a period.
183+
184+
Args:
185+
graph_id (str):
186+
structure_id (str): Schedule structure ID
187+
body (CreateClosingEntryRequest):
188+
189+
Raises:
190+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
191+
httpx.TimeoutException: If the request takes longer than Client.timeout.
192+
193+
Returns:
194+
ClosingEntryResponse | HTTPValidationError
195+
"""
196+
197+
return (
198+
await asyncio_detailed(
199+
graph_id=graph_id,
200+
structure_id=structure_id,
201+
client=client,
202+
body=body,
203+
)
204+
).parsed

‎robosystems_client/api/ledger/create_mapping_association.py‎

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

77
from ... import errors
88
from ...client import AuthenticatedClient, Client
9+
from ...models.association_response import AssociationResponse
910
from ...models.create_association_request import CreateAssociationRequest
10-
from ...models.element_association_response import ElementAssociationResponse
1111
from ...models.http_validation_error import HTTPValidationError
1212
from ...types import Response
1313

@@ -38,9 +38,9 @@ def _get_kwargs(
3838

3939
def _parse_response(
4040
*, client: AuthenticatedClient | Client, response: httpx.Response
41-
) -> ElementAssociationResponse | HTTPValidationError | None:
41+
) -> AssociationResponse | HTTPValidationError | None:
4242
if response.status_code == 201:
43-
response_201 = ElementAssociationResponse.from_dict(response.json())
43+
response_201 = AssociationResponse.from_dict(response.json())
4444

4545
return response_201
4646

@@ -57,7 +57,7 @@ def _parse_response(
5757

5858
def _build_response(
5959
*, client: AuthenticatedClient | Client, response: httpx.Response
60-
) -> Response[ElementAssociationResponse | HTTPValidationError]:
60+
) -> Response[AssociationResponse | HTTPValidationError]:
6161
return Response(
6262
status_code=HTTPStatus(response.status_code),
6363
content=response.content,
@@ -72,7 +72,7 @@ def sync_detailed(
7272
*,
7373
client: AuthenticatedClient,
7474
body: CreateAssociationRequest,
75-
) -> Response[ElementAssociationResponse | HTTPValidationError]:
75+
) -> Response[AssociationResponse | HTTPValidationError]:
7676
"""Create Mapping Association
7777
7878
Add a mapping association (CoA element → reporting concept).
@@ -87,7 +87,7 @@ def sync_detailed(
8787
httpx.TimeoutException: If the request takes longer than Client.timeout.
8888
8989
Returns:
90-
Response[ElementAssociationResponse | HTTPValidationError]
90+
Response[AssociationResponse | HTTPValidationError]
9191
"""
9292

9393
kwargs = _get_kwargs(
@@ -109,7 +109,7 @@ def sync(
109109
*,
110110
client: AuthenticatedClient,
111111
body: CreateAssociationRequest,
112-
) -> ElementAssociationResponse | HTTPValidationError | None:
112+
) -> AssociationResponse | HTTPValidationError | None:
113113
"""Create Mapping Association
114114
115115
Add a mapping association (CoA element → reporting concept).
@@ -124,7 +124,7 @@ def sync(
124124
httpx.TimeoutException: If the request takes longer than Client.timeout.
125125
126126
Returns:
127-
ElementAssociationResponse | HTTPValidationError
127+
AssociationResponse | HTTPValidationError
128128
"""
129129

130130
return sync_detailed(
@@ -141,7 +141,7 @@ async def asyncio_detailed(
141141
*,
142142
client: AuthenticatedClient,
143143
body: CreateAssociationRequest,
144-
) -> Response[ElementAssociationResponse | HTTPValidationError]:
144+
) -> Response[AssociationResponse | HTTPValidationError]:
145145
"""Create Mapping Association
146146
147147
Add a mapping association (CoA element → reporting concept).
@@ -156,7 +156,7 @@ async def asyncio_detailed(
156156
httpx.TimeoutException: If the request takes longer than Client.timeout.
157157
158158
Returns:
159-
Response[ElementAssociationResponse | HTTPValidationError]
159+
Response[AssociationResponse | HTTPValidationError]
160160
"""
161161

162162
kwargs = _get_kwargs(
@@ -176,7 +176,7 @@ async def asyncio(
176176
*,
177177
client: AuthenticatedClient,
178178
body: CreateAssociationRequest,
179-
) -> ElementAssociationResponse | HTTPValidationError | None:
179+
) -> AssociationResponse | HTTPValidationError | None:
180180
"""Create Mapping Association
181181
182182
Add a mapping association (CoA element → reporting concept).
@@ -191,7 +191,7 @@ async def asyncio(
191191
httpx.TimeoutException: If the request takes longer than Client.timeout.
192192
193193
Returns:
194-
ElementAssociationResponse | HTTPValidationError
194+
AssociationResponse | HTTPValidationError
195195
"""
196196

197197
return (

0 commit comments

Comments
 (0)