-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support prefixItems for arrays
Generates a union of all types in `prefixItems` and `items` for the inner list item type
- Loading branch information
Showing
8 changed files
with
410 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
150 changes: 150 additions & 0 deletions
150
...sts/test-3-1-golden-record/test_3_1_features_client/api/prefix_items/post_prefix_items.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
from http import HTTPStatus | ||
from typing import Any, Dict, Optional, Union, cast | ||
|
||
import httpx | ||
|
||
from ... import errors | ||
from ...client import AuthenticatedClient, Client | ||
from ...models.post_prefix_items_body import PostPrefixItemsBody | ||
from ...types import Response | ||
|
||
|
||
def _get_kwargs( | ||
*, | ||
body: PostPrefixItemsBody, | ||
) -> Dict[str, Any]: | ||
headers: Dict[str, Any] = {} | ||
|
||
_kwargs: Dict[str, Any] = { | ||
"method": "post", | ||
"url": "/prefixItems", | ||
} | ||
|
||
_body = body.to_dict() | ||
|
||
_kwargs["json"] = _body | ||
headers["Content-Type"] = "application/json" | ||
|
||
_kwargs["headers"] = headers | ||
return _kwargs | ||
|
||
|
||
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[str]: | ||
if response.status_code == HTTPStatus.OK: | ||
response_200 = cast(str, response.json()) | ||
return response_200 | ||
if client.raise_on_unexpected_status: | ||
raise errors.UnexpectedStatus(response.status_code, response.content) | ||
else: | ||
return None | ||
|
||
|
||
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[str]: | ||
return Response( | ||
status_code=HTTPStatus(response.status_code), | ||
content=response.content, | ||
headers=response.headers, | ||
parsed=_parse_response(client=client, response=response), | ||
) | ||
|
||
|
||
def sync_detailed( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
body: PostPrefixItemsBody, | ||
) -> Response[str]: | ||
""" | ||
Args: | ||
body (PostPrefixItemsBody): | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Response[str] | ||
""" | ||
|
||
kwargs = _get_kwargs( | ||
body=body, | ||
) | ||
|
||
response = client.get_httpx_client().request( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(client=client, response=response) | ||
|
||
|
||
def sync( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
body: PostPrefixItemsBody, | ||
) -> Optional[str]: | ||
""" | ||
Args: | ||
body (PostPrefixItemsBody): | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
str | ||
""" | ||
|
||
return sync_detailed( | ||
client=client, | ||
body=body, | ||
).parsed | ||
|
||
|
||
async def asyncio_detailed( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
body: PostPrefixItemsBody, | ||
) -> Response[str]: | ||
""" | ||
Args: | ||
body (PostPrefixItemsBody): | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Response[str] | ||
""" | ||
|
||
kwargs = _get_kwargs( | ||
body=body, | ||
) | ||
|
||
response = await client.get_async_httpx_client().request(**kwargs) | ||
|
||
return _build_response(client=client, response=response) | ||
|
||
|
||
async def asyncio( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
body: PostPrefixItemsBody, | ||
) -> Optional[str]: | ||
""" | ||
Args: | ||
body (PostPrefixItemsBody): | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
str | ||
""" | ||
|
||
return ( | ||
await asyncio_detailed( | ||
client=client, | ||
body=body, | ||
) | ||
).parsed |
6 changes: 5 additions & 1 deletion
6
end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
"""Contains all the data models used in inputs/outputs""" | ||
|
||
from .post_const_path_body import PostConstPathBody | ||
from .post_prefix_items_body import PostPrefixItemsBody | ||
|
||
__all__ = ("PostConstPathBody",) | ||
__all__ = ( | ||
"PostConstPathBody", | ||
"PostPrefixItemsBody", | ||
) |
103 changes: 103 additions & 0 deletions
103
...nd_tests/test-3-1-golden-record/test_3_1_features_client/models/post_prefix_items_body.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from typing import Any, Dict, List, Literal, Type, TypeVar, Union, cast | ||
|
||
from attrs import define as _attrs_define | ||
from attrs import field as _attrs_field | ||
|
||
from ..types import UNSET, Unset | ||
|
||
T = TypeVar("T", bound="PostPrefixItemsBody") | ||
|
||
|
||
@_attrs_define | ||
class PostPrefixItemsBody: | ||
""" | ||
Attributes: | ||
prefix_items_and_items (Union[Unset, List[Union[Literal['prefix'], float, str]]]): | ||
prefix_items_only (Union[Unset, List[Union[float, str]]]): | ||
""" | ||
|
||
prefix_items_and_items: Union[Unset, List[Union[Literal["prefix"], float, str]]] = UNSET | ||
prefix_items_only: Union[Unset, List[Union[float, str]]] = UNSET | ||
additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) | ||
|
||
def to_dict(self) -> Dict[str, Any]: | ||
prefix_items_and_items: Union[Unset, List[Union[Literal["prefix"], float, str]]] = UNSET | ||
if not isinstance(self.prefix_items_and_items, Unset): | ||
prefix_items_and_items = [] | ||
for prefix_items_and_items_item_data in self.prefix_items_and_items: | ||
prefix_items_and_items_item: Union[Literal["prefix"], float, str] | ||
prefix_items_and_items_item = prefix_items_and_items_item_data | ||
prefix_items_and_items.append(prefix_items_and_items_item) | ||
|
||
prefix_items_only: Union[Unset, List[Union[float, str]]] = UNSET | ||
if not isinstance(self.prefix_items_only, Unset): | ||
prefix_items_only = [] | ||
for prefix_items_only_item_data in self.prefix_items_only: | ||
prefix_items_only_item: Union[float, str] | ||
prefix_items_only_item = prefix_items_only_item_data | ||
prefix_items_only.append(prefix_items_only_item) | ||
|
||
field_dict: Dict[str, Any] = {} | ||
field_dict.update(self.additional_properties) | ||
field_dict.update({}) | ||
if prefix_items_and_items is not UNSET: | ||
field_dict["prefixItemsAndItems"] = prefix_items_and_items | ||
if prefix_items_only is not UNSET: | ||
field_dict["prefixItemsOnly"] = prefix_items_only | ||
|
||
return field_dict | ||
|
||
@classmethod | ||
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: | ||
d = src_dict.copy() | ||
prefix_items_and_items = [] | ||
_prefix_items_and_items = d.pop("prefixItemsAndItems", UNSET) | ||
for prefix_items_and_items_item_data in _prefix_items_and_items or []: | ||
|
||
def _parse_prefix_items_and_items_item(data: object) -> Union[Literal["prefix"], float, str]: | ||
prefix_items_and_items_item_type_0 = cast(Literal["prefix"], data) | ||
if prefix_items_and_items_item_type_0 != "prefix": | ||
raise ValueError( | ||
f"prefixItemsAndItems_item_type_0 must match const 'prefix', got '{prefix_items_and_items_item_type_0}'" | ||
) | ||
return prefix_items_and_items_item_type_0 | ||
return cast(Union[Literal["prefix"], float, str], data) | ||
|
||
prefix_items_and_items_item = _parse_prefix_items_and_items_item(prefix_items_and_items_item_data) | ||
|
||
prefix_items_and_items.append(prefix_items_and_items_item) | ||
|
||
prefix_items_only = [] | ||
_prefix_items_only = d.pop("prefixItemsOnly", UNSET) | ||
for prefix_items_only_item_data in _prefix_items_only or []: | ||
|
||
def _parse_prefix_items_only_item(data: object) -> Union[float, str]: | ||
return cast(Union[float, str], data) | ||
|
||
prefix_items_only_item = _parse_prefix_items_only_item(prefix_items_only_item_data) | ||
|
||
prefix_items_only.append(prefix_items_only_item) | ||
|
||
post_prefix_items_body = cls( | ||
prefix_items_and_items=prefix_items_and_items, | ||
prefix_items_only=prefix_items_only, | ||
) | ||
|
||
post_prefix_items_body.additional_properties = d | ||
return post_prefix_items_body | ||
|
||
@property | ||
def additional_keys(self) -> List[str]: | ||
return list(self.additional_properties.keys()) | ||
|
||
def __getitem__(self, key: str) -> Any: | ||
return self.additional_properties[key] | ||
|
||
def __setitem__(self, key: str, value: Any) -> None: | ||
self.additional_properties[key] = value | ||
|
||
def __delitem__(self, key: str) -> None: | ||
del self.additional_properties[key] | ||
|
||
def __contains__(self, key: str) -> bool: | ||
return key in self.additional_properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.