Skip to content

Commit

Permalink
Hotfix for simple anyof ref schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
artsmolin committed Jul 29, 2024
1 parent 20ce3d4 commit 31eb925
Show file tree
Hide file tree
Showing 10 changed files with 757 additions and 217 deletions.
52 changes: 39 additions & 13 deletions examples/petstore/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -2333,16 +2333,42 @@ def _parse_any_of(self, item: dict[str, Any], schema_classes: list[Any]) -> Any:
raise Exception('Can\'t parse "{item}"')


CreateuserswithlistinputRequestBody.model_rebuild()
FindpetsbytagsResponse200.model_rebuild()
FindpetsbystatusResponse200.model_rebuild()
AddpetortagRequestBody.model_rebuild()
AddpetortagResponse200.model_rebuild()
ApiResponse.model_rebuild()
Tag.model_rebuild()
Category.model_rebuild()
Pet.model_rebuild()
User.model_rebuild()
Address.model_rebuild()
Customer.model_rebuild()
Order.model_rebuild()
if hasattr(CreateuserswithlistinputRequestBody, "model_rebuild"):
CreateuserswithlistinputRequestBody.model_rebuild()


if hasattr(FindpetsbytagsResponse200, "model_rebuild"):
FindpetsbytagsResponse200.model_rebuild()

if hasattr(FindpetsbystatusResponse200, "model_rebuild"):
FindpetsbystatusResponse200.model_rebuild()

if hasattr(AddpetortagRequestBody, "model_rebuild"):
AddpetortagRequestBody.model_rebuild()

if hasattr(AddpetortagResponse200, "model_rebuild"):
AddpetortagResponse200.model_rebuild()

if hasattr(ApiResponse, "model_rebuild"):
ApiResponse.model_rebuild()

if hasattr(Tag, "model_rebuild"):
Tag.model_rebuild()

if hasattr(Category, "model_rebuild"):
Category.model_rebuild()

if hasattr(Pet, "model_rebuild"):
Pet.model_rebuild()

if hasattr(User, "model_rebuild"):
User.model_rebuild()

if hasattr(Address, "model_rebuild"):
Address.model_rebuild()

if hasattr(Customer, "model_rebuild"):
Customer.model_rebuild()

if hasattr(Order, "model_rebuild"):
Order.model_rebuild()
52 changes: 39 additions & 13 deletions examples/petstore/client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2309,16 +2309,42 @@ def _parse_any_of(self, item: dict[str, Any], schema_classes: list[Any]) -> Any:
raise Exception('Can\'t parse "{item}"')


CreateuserswithlistinputRequestBody.model_rebuild()
FindpetsbytagsResponse200.model_rebuild()
FindpetsbystatusResponse200.model_rebuild()
AddpetortagRequestBody.model_rebuild()
AddpetortagResponse200.model_rebuild()
ApiResponse.model_rebuild()
Tag.model_rebuild()
Category.model_rebuild()
Pet.model_rebuild()
User.model_rebuild()
Address.model_rebuild()
Customer.model_rebuild()
Order.model_rebuild()
if hasattr(CreateuserswithlistinputRequestBody, "model_rebuild"):
CreateuserswithlistinputRequestBody.model_rebuild()


if hasattr(FindpetsbytagsResponse200, "model_rebuild"):
FindpetsbytagsResponse200.model_rebuild()

if hasattr(FindpetsbystatusResponse200, "model_rebuild"):
FindpetsbystatusResponse200.model_rebuild()

if hasattr(AddpetortagRequestBody, "model_rebuild"):
AddpetortagRequestBody.model_rebuild()

if hasattr(AddpetortagResponse200, "model_rebuild"):
AddpetortagResponse200.model_rebuild()

if hasattr(ApiResponse, "model_rebuild"):
ApiResponse.model_rebuild()

if hasattr(Tag, "model_rebuild"):
Tag.model_rebuild()

if hasattr(Category, "model_rebuild"):
Category.model_rebuild()

if hasattr(Pet, "model_rebuild"):
Pet.model_rebuild()

if hasattr(User, "model_rebuild"):
User.model_rebuild()

if hasattr(Address, "model_rebuild"):
Address.model_rebuild()

if hasattr(Customer, "model_rebuild"):
Customer.model_rebuild()

if hasattr(Order, "model_rebuild"):
Order.model_rebuild()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pythogen"
version = "0.2.40"
version = "0.2.41"
description = "Generator of python HTTP-clients from OpenApi specification."
homepage = "https://github.com/artsmolin/pythogen"
repository = "https://github.com/artsmolin/pythogen"
Expand Down
5 changes: 3 additions & 2 deletions pythogen/templates/http_client/main.j2
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ class {{ name }}:

{% for model in models %}
{%- if model.type.value not in ("any_of", "null") and not model.is_empty_object %}
{{ classname(model.id) }}.model_rebuild()
if hasattr({{ classname(model.id) }}, "model_rebuild"):
{{ classname(model.id) }}.model_rebuild()
{%- else %}
{%- endif -%}
{%- endif %}
{% endfor %}
169 changes: 132 additions & 37 deletions tests/clients/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,21 @@ class OptionalAnyofStringDataObj(RootModel):
root: str | None


class PropertyAllOfSimpleStringRefRefObj(
str,
):
"""
None
"""

model_config = ConfigDict(
populate_by_name=True, # Addressing by field name, even if there is an alias.
)

...


class DictOdArrayOfDictsObj(RootModel):
"""
None
Expand Down Expand Up @@ -710,6 +725,7 @@ class GetObjectResp(BaseModel):
animal: AnimalObj | None = None
dictOdArrayOfDicts: DictOdArrayOfDictsObj | None = Field(None, alias="dictOdArrayOfDicts")
integer_data_min_max: int | None = Field(None, ge=1, le=20)
propertyAllOfSimpleStringRef: str | None = Field(None, alias="propertyAllOfSimpleStringRef")


class GetMessageResp(BaseModel):
Expand Down Expand Up @@ -2836,40 +2852,119 @@ def _parse_any_of(self, item: dict[str, Any], schema_classes: list[Any]) -> Any:
raise Exception('Can\'t parse "{item}"')


RequestBodyAnyofRequestBody.model_rebuild()
GetListObjectsResponse200.model_rebuild()
RewardsListItem.model_rebuild()
GetObjectWithInlineArrayResponse200.model_rebuild()
GetObjectWithArrayResponseResponse200.model_rebuild()
GetObjectWithArrayResponseResponse200Item.model_rebuild()
GetObjectNoRefSchemaResponse200.model_rebuild()
IntEnumOrNullObj.model_rebuild()
OptionalAnyofStringDataObj.model_rebuild()
DictOdArrayOfDictsObj.model_rebuild()
DictOdArrayOfDictsObjItem0.model_rebuild()
AnimalObj.model_rebuild()
AnyOfChildObj.model_rebuild()
TierObj.model_rebuild()
AllOfRefObjItem2.model_rebuild()
Cat.model_rebuild()
Data.model_rebuild()
AllOfRefObj.model_rebuild()
AnyOfChildItem.model_rebuild()
ListAnyOfResp.model_rebuild()
SafetyKeyForTesting.model_rebuild()
UnknownError.model_rebuild()
DeleteObjectResp.model_rebuild()
PutObjectResp.model_rebuild()
PatchObjectResp.model_rebuild()
PostObjectResp.model_rebuild()
PostFile.model_rebuild()
PutObjectData.model_rebuild()
PatchObjectData.model_rebuild()
PostObjectData.model_rebuild()
GetObjectResp.model_rebuild()
GetMessageResp.model_rebuild()
Dog.model_rebuild()
DogWithKind.model_rebuild()
CatWithKind.model_rebuild()
DiscriminatedOneOfResp.model_rebuild()
AllOfResp.model_rebuild()
if hasattr(RequestBodyAnyofRequestBody, "model_rebuild"):
RequestBodyAnyofRequestBody.model_rebuild()

if hasattr(GetListObjectsResponse200, "model_rebuild"):
GetListObjectsResponse200.model_rebuild()

if hasattr(RewardsListItem, "model_rebuild"):
RewardsListItem.model_rebuild()

if hasattr(GetObjectWithInlineArrayResponse200, "model_rebuild"):
GetObjectWithInlineArrayResponse200.model_rebuild()

if hasattr(GetObjectWithArrayResponseResponse200, "model_rebuild"):
GetObjectWithArrayResponseResponse200.model_rebuild()

if hasattr(GetObjectWithArrayResponseResponse200Item, "model_rebuild"):
GetObjectWithArrayResponseResponse200Item.model_rebuild()


if hasattr(GetObjectNoRefSchemaResponse200, "model_rebuild"):
GetObjectNoRefSchemaResponse200.model_rebuild()

if hasattr(IntEnumOrNullObj, "model_rebuild"):
IntEnumOrNullObj.model_rebuild()

if hasattr(OptionalAnyofStringDataObj, "model_rebuild"):
OptionalAnyofStringDataObj.model_rebuild()

if hasattr(PropertyAllOfSimpleStringRefRefObj, "model_rebuild"):
PropertyAllOfSimpleStringRefRefObj.model_rebuild()

if hasattr(DictOdArrayOfDictsObj, "model_rebuild"):
DictOdArrayOfDictsObj.model_rebuild()


if hasattr(DictOdArrayOfDictsObjItem0, "model_rebuild"):
DictOdArrayOfDictsObjItem0.model_rebuild()


if hasattr(AnimalObj, "model_rebuild"):
AnimalObj.model_rebuild()

if hasattr(AnyOfChildObj, "model_rebuild"):
AnyOfChildObj.model_rebuild()

if hasattr(TierObj, "model_rebuild"):
TierObj.model_rebuild()

if hasattr(AllOfRefObjItem2, "model_rebuild"):
AllOfRefObjItem2.model_rebuild()

if hasattr(Cat, "model_rebuild"):
Cat.model_rebuild()

if hasattr(Data, "model_rebuild"):
Data.model_rebuild()

if hasattr(AllOfRefObj, "model_rebuild"):
AllOfRefObj.model_rebuild()

if hasattr(AnyOfChildItem, "model_rebuild"):
AnyOfChildItem.model_rebuild()

if hasattr(ListAnyOfResp, "model_rebuild"):
ListAnyOfResp.model_rebuild()

if hasattr(SafetyKeyForTesting, "model_rebuild"):
SafetyKeyForTesting.model_rebuild()

if hasattr(UnknownError, "model_rebuild"):
UnknownError.model_rebuild()

if hasattr(DeleteObjectResp, "model_rebuild"):
DeleteObjectResp.model_rebuild()

if hasattr(PutObjectResp, "model_rebuild"):
PutObjectResp.model_rebuild()

if hasattr(PatchObjectResp, "model_rebuild"):
PatchObjectResp.model_rebuild()

if hasattr(PostObjectResp, "model_rebuild"):
PostObjectResp.model_rebuild()

if hasattr(PostFile, "model_rebuild"):
PostFile.model_rebuild()

if hasattr(PutObjectData, "model_rebuild"):
PutObjectData.model_rebuild()

if hasattr(PatchObjectData, "model_rebuild"):
PatchObjectData.model_rebuild()

if hasattr(PostObjectData, "model_rebuild"):
PostObjectData.model_rebuild()

if hasattr(GetObjectResp, "model_rebuild"):
GetObjectResp.model_rebuild()

if hasattr(GetMessageResp, "model_rebuild"):
GetMessageResp.model_rebuild()

if hasattr(Dog, "model_rebuild"):
Dog.model_rebuild()

if hasattr(DogWithKind, "model_rebuild"):
DogWithKind.model_rebuild()

if hasattr(CatWithKind, "model_rebuild"):
CatWithKind.model_rebuild()

if hasattr(DiscriminatedOneOfResp, "model_rebuild"):
DiscriminatedOneOfResp.model_rebuild()

if hasattr(AllOfResp, "model_rebuild"):
AllOfResp.model_rebuild()
Loading

0 comments on commit 31eb925

Please sign in to comment.