Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
[feat] Allow for making sets of primatives (#468)
Browse files Browse the repository at this point in the history
* Allow for making sets

* fix types in visitor

* seed tests

* run seed again but bumped v

* other seed tests

* add fastapi tests too...
  • Loading branch information
armandobelardo authored Dec 19, 2023
1 parent 8e57f68 commit 0bcdcef
Show file tree
Hide file tree
Showing 31 changed files with 94 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_and_return_list_of_objects(
...

@abc.abstractmethod
def get_and_return_set_of_primitives(self, *, body: typing.List[str], auth: ApiAuth) -> typing.List[str]:
def get_and_return_set_of_primitives(self, *, body: typing.Set[str], auth: ApiAuth) -> typing.Set[str]:
...

@abc.abstractmethod
Expand Down Expand Up @@ -173,7 +173,7 @@ def __init_get_and_return_set_of_primitives(cls, router: fastapi.APIRouter) -> N
)

@functools.wraps(cls.get_and_return_set_of_primitives)
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.List[str]:
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Set[str]:
try:
return cls.get_and_return_set_of_primitives(*args, **kwargs)
except FernHTTPException as e:
Expand All @@ -190,7 +190,7 @@ def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.List[str]:

router.post(
path="/container/set-of-primitives",
response_model=typing.List[str],
response_model=typing.Set[str],
description=AbstractEndpointsContainerService.get_and_return_set_of_primitives.__doc__,
**get_route_args(cls.get_and_return_set_of_primitives, default_tag="endpoints.container"),
)(wrapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ObjectWithOptionalField(pydantic.BaseModel):
uuid: typing.Optional[uuid.UUID]
base_64: typing.Optional[str] = pydantic.Field(alias="base64")
list: typing.Optional[typing.List[str]]
set: typing.Optional[typing.List[str]]
set: typing.Optional[typing.Set[str]]
map: typing.Optional[typing.Dict[int, str]]

def json(self, **kwargs: typing.Any) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_and_return_list_of_objects(
...

@abc.abstractmethod
def get_and_return_set_of_primitives(self, *, body: typing.List[str], auth: ApiAuth) -> typing.List[str]:
def get_and_return_set_of_primitives(self, *, body: typing.Set[str], auth: ApiAuth) -> typing.Set[str]:
...

@abc.abstractmethod
Expand Down Expand Up @@ -173,7 +173,7 @@ def __init_get_and_return_set_of_primitives(cls, router: fastapi.APIRouter) -> N
)

@functools.wraps(cls.get_and_return_set_of_primitives)
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.List[str]:
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Set[str]:
try:
return cls.get_and_return_set_of_primitives(*args, **kwargs)
except FernHTTPException as e:
Expand All @@ -190,7 +190,7 @@ def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.List[str]:

router.post(
path="/container/set-of-primitives",
response_model=typing.List[str],
response_model=typing.Set[str],
description=AbstractEndpointsContainerService.get_and_return_set_of_primitives.__doc__,
**get_route_args(cls.get_and_return_set_of_primitives, default_tag="endpoints.container"),
)(wrapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ObjectWithOptionalField(pydantic.BaseModel):
uuid: typing.Optional[uuid.UUID]
base_64: typing.Optional[str] = pydantic.Field(alias="base64")
list: typing.Optional[typing.List[str]]
set: typing.Optional[typing.List[str]]
set: typing.Optional[typing.Set[str]]
map: typing.Optional[typing.Dict[int, str]]

def json(self, **kwargs: typing.Any) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_and_return_list_of_objects(
...

@abc.abstractmethod
def get_and_return_set_of_primitives(self, *, body: typing.List[str], auth: ApiAuth) -> typing.List[str]:
def get_and_return_set_of_primitives(self, *, body: typing.Set[str], auth: ApiAuth) -> typing.Set[str]:
...

@abc.abstractmethod
Expand Down Expand Up @@ -173,7 +173,7 @@ def __init_get_and_return_set_of_primitives(cls, router: fastapi.APIRouter) -> N
)

@functools.wraps(cls.get_and_return_set_of_primitives)
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.List[str]:
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Set[str]:
try:
return cls.get_and_return_set_of_primitives(*args, **kwargs)
except FernHTTPException as e:
Expand All @@ -190,7 +190,7 @@ def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.List[str]:

router.post(
path="/container/set-of-primitives",
response_model=typing.List[str],
response_model=typing.Set[str],
description=AbstractEndpointsContainerService.get_and_return_set_of_primitives.__doc__,
**get_route_args(cls.get_and_return_set_of_primitives, default_tag="endpoints.container"),
)(wrapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ObjectWithOptionalField(pydantic.BaseModel):
uuid: typing.Optional[uuid.UUID]
base_64: typing.Optional[str] = pydantic.Field(alias="base64")
list: typing.Optional[typing.List[str]]
set: typing.Optional[typing.List[str]]
set: typing.Optional[typing.Set[str]]
map: typing.Optional[typing.Dict[int, str]]

def json(self, **kwargs: typing.Any) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_and_return_list_of_primitives(self, *, body: typing.List[str], auth: Api
def get_and_return_list_of_objects(self, *, body: typing.List[ObjectWithRequiredField], auth: ApiAuth) -> typing.List[ObjectWithRequiredField]:
...
@abc.abstractmethod
def get_and_return_set_of_primitives(self, *, body: typing.List[str], auth: ApiAuth) -> typing.List[str]:
def get_and_return_set_of_primitives(self, *, body: typing.Set[str], auth: ApiAuth) -> typing.Set[str]:
...
@abc.abstractmethod
def get_and_return_set_of_objects(self, *, body: typing.List[ObjectWithRequiredField], auth: ApiAuth) -> typing.List[ObjectWithRequiredField]:
Expand Down Expand Up @@ -144,7 +144,7 @@ def __init_get_and_return_set_of_primitives(cls, router: fastapi.APIRouter) -> N
setattr(cls.get_and_return_set_of_primitives, "__signature__", endpoint_function.replace(parameters=new_parameters))

@functools.wraps(cls.get_and_return_set_of_primitives)
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.List[str]:
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Set[str]:
try:
return cls.get_and_return_set_of_primitives(*args, **kwargs)
except FernHTTPException as e:
Expand All @@ -161,7 +161,7 @@ def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.List[str]:

router.post(
path="/container/set-of-primitives",
response_model=typing.List[str],
response_model=typing.Set[str],
description=AbstractEndpointsContainerService.get_and_return_set_of_primitives.__doc__,
**get_route_args(cls.get_and_return_set_of_primitives, default_tag="endpoints.container"),
)(wrapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ObjectWithOptionalField(pydantic.BaseModel):
uuid: typing.Optional[uuid.UUID]
base_64: typing.Optional[str] = pydantic.Field(alias="base64")
list: typing.Optional[typing.List[str]]
set: typing.Optional[typing.List[str]]
set: typing.Optional[typing.Set[str]]
map: typing.Optional[typing.Dict[int, str]]
def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = { "by_alias": True, "exclude_unset": True, **kwargs }
Expand Down
2 changes: 1 addition & 1 deletion seed/fastapi/object/types/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Type(pydantic.BaseModel):
eight: uuid.UUID
nine: str
ten: typing.List[int]
eleven: typing.List[float]
eleven: typing.Set[float]
twelve: typing.Dict[str, bool]
thirteen: typing.Optional[int]
fourteen: typing.Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Base(pydantic.BaseModel):
"""

extra: typing.Dict[str, str]
tags: typing.List[str]
tags: typing.Set[str]

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ObjectWithOptionalField(pydantic.BaseModel):
uuid: typing.Optional[uuid.UUID]
base_64: typing.Optional[str] = pydantic.Field(alias="base64")
list: typing.Optional[typing.List[str]]
set: typing.Optional[typing.List[str]]
set: typing.Optional[typing.Set[str]]
map: typing.Optional[typing.Dict[int, str]]

def json(self, **kwargs: typing.Any) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ObjectWithOptionalField(pydantic.BaseModel):
uuid: typing.Optional[uuid.UUID]
base_64: typing.Optional[str] = pydantic.Field(alias="base64")
list: typing.Optional[typing.List[str]]
set: typing.Optional[typing.List[str]]
set: typing.Optional[typing.Set[str]]
map: typing.Optional[typing.Dict[int, str]]

def json(self, **kwargs: typing.Any) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import typing

MaybeListOrSet = typing.Union[
str, typing.List[str], int, typing.List[int], typing.List[typing.List[int]], typing.List[str]
str, typing.List[str], int, typing.List[int], typing.List[typing.List[int]], typing.Set[str]
]
2 changes: 1 addition & 1 deletion seed/pydantic/object/src/seed/object/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Type(pydantic.BaseModel):
eight: uuid.UUID
nine: str
ten: typing.List[int]
eleven: typing.List[float]
eleven: typing.Set[float]
twelve: typing.Dict[str, bool]
thirteen: typing.Optional[int]
fourteen: typing.Any
Expand Down
2 changes: 1 addition & 1 deletion seed/sdk/examples/src/seed/types/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Base(pydantic.BaseModel):
"""

extra: typing.Dict[str, str]
tags: typing.List[str]
tags: typing.Set[str]

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def get_and_return_list_of_objects(
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -> typing.List[str]:
def get_and_return_set_of_primitives(self, *, request: typing.Set[str]) -> typing.Set[str]:
"""
Parameters:
- request: typing.List[str].
- request: typing.Set[str].
"""
_response = self._client_wrapper.httpx_client.request(
"POST",
Expand All @@ -77,7 +77,7 @@ def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -> typi
timeout=60,
)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
return pydantic.parse_obj_as(typing.Set[str], _response.json()) # type: ignore
try:
_response_json = _response.json()
except JSONDecodeError:
Expand Down Expand Up @@ -217,10 +217,10 @@ async def get_and_return_list_of_objects(
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

async def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -> typing.List[str]:
async def get_and_return_set_of_primitives(self, *, request: typing.Set[str]) -> typing.Set[str]:
"""
Parameters:
- request: typing.List[str].
- request: typing.Set[str].
"""
_response = await self._client_wrapper.httpx_client.request(
"POST",
Expand All @@ -230,7 +230,7 @@ async def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -
timeout=60,
)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
return pydantic.parse_obj_as(typing.Set[str], _response.json()) # type: ignore
try:
_response_json = _response.json()
except JSONDecodeError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ObjectWithOptionalField(pydantic.BaseModel):
uuid: typing.Optional[uuid.UUID]
base_64: typing.Optional[str] = pydantic.Field(alias="base64")
list: typing.Optional[typing.List[str]]
set: typing.Optional[typing.List[str]]
set: typing.Optional[typing.Set[str]]
map: typing.Optional[typing.Dict[int, str]]

def json(self, **kwargs: typing.Any) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def get_and_return_list_of_objects(
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -> typing.List[str]:
def get_and_return_set_of_primitives(self, *, request: typing.Set[str]) -> typing.Set[str]:
"""
Parameters:
- request: typing.List[str].
- request: typing.Set[str].
"""
_response = self._client_wrapper.httpx_client.request(
"POST",
Expand All @@ -77,7 +77,7 @@ def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -> typi
timeout=5,
)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
return pydantic.parse_obj_as(typing.Set[str], _response.json()) # type: ignore
try:
_response_json = _response.json()
except JSONDecodeError:
Expand Down Expand Up @@ -217,10 +217,10 @@ async def get_and_return_list_of_objects(
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

async def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -> typing.List[str]:
async def get_and_return_set_of_primitives(self, *, request: typing.Set[str]) -> typing.Set[str]:
"""
Parameters:
- request: typing.List[str].
- request: typing.Set[str].
"""
_response = await self._client_wrapper.httpx_client.request(
"POST",
Expand All @@ -230,7 +230,7 @@ async def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -
timeout=5,
)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
return pydantic.parse_obj_as(typing.Set[str], _response.json()) # type: ignore
try:
_response_json = _response.json()
except JSONDecodeError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ObjectWithOptionalField(pydantic.BaseModel):
uuid: typing.Optional[uuid.UUID]
base_64: typing.Optional[str] = pydantic.Field(alias="base64")
list: typing.Optional[typing.List[str]]
set: typing.Optional[typing.List[str]]
set: typing.Optional[typing.Set[str]]
map: typing.Optional[typing.Dict[int, str]]

def json(self, **kwargs: typing.Any) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def get_and_return_list_of_objects(
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -> typing.List[str]:
def get_and_return_set_of_primitives(self, *, request: typing.Set[str]) -> typing.Set[str]:
"""
Parameters:
- request: typing.List[str].
- request: typing.Set[str].
"""
_response = self._client_wrapper.httpx_client.request(
"POST",
Expand All @@ -77,7 +77,7 @@ def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -> typi
timeout=None,
)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
return pydantic.parse_obj_as(typing.Set[str], _response.json()) # type: ignore
try:
_response_json = _response.json()
except JSONDecodeError:
Expand Down Expand Up @@ -217,10 +217,10 @@ async def get_and_return_list_of_objects(
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

async def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -> typing.List[str]:
async def get_and_return_set_of_primitives(self, *, request: typing.Set[str]) -> typing.Set[str]:
"""
Parameters:
- request: typing.List[str].
- request: typing.Set[str].
"""
_response = await self._client_wrapper.httpx_client.request(
"POST",
Expand All @@ -230,7 +230,7 @@ async def get_and_return_set_of_primitives(self, *, request: typing.List[str]) -
timeout=None,
)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
return pydantic.parse_obj_as(typing.Set[str], _response.json()) # type: ignore
try:
_response_json = _response.json()
except JSONDecodeError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ObjectWithOptionalField(pydantic.BaseModel):
uuid: typing.Optional[uuid.UUID]
base_64: typing.Optional[str] = pydantic.Field(alias="base64")
list: typing.Optional[typing.List[str]]
set: typing.Optional[typing.List[str]]
set: typing.Optional[typing.Set[str]]
map: typing.Optional[typing.Dict[int, str]]

def json(self, **kwargs: typing.Any) -> str:
Expand Down
Loading

0 comments on commit 0bcdcef

Please sign in to comment.