Skip to content

Commit 0ab86bf

Browse files
committed
fix model_<anyof/oneof>.mustache
add to_json / to_dict/ to_str ./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exi
1 parent 279d739 commit 0ab86bf

28 files changed

Lines changed: 94 additions & 56 deletions

File tree

modules/openapi-generator/src/main/resources/python/model_anyof.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import pprint
44
{{{.}}}
55
{{/vendorExtensions.x-py-model-imports}}
66
from pydantic import Field, RootModel
7-
from typing import Any, Dict, Optional, Union
7+
from typing import Any, Dict, Union
88

99
{{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ANY_OF_SCHEMAS = [{{#anyOf}}"{{.}}"{{^-last}}, {{/-last}}{{/anyOf}}]
1010

@@ -37,7 +37,7 @@ class {{classname}}(RootModel[Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyO
3737
"""Returns the JSON representation of the actual instance"""
3838
return self.model_dump_json(by_alias=True)
3939

40-
def to_dict(self) -> Optional[Union[Dict[str, Any], {{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}]]:
40+
def to_dict(self) -> Dict[str, Any]:
4141
"""Returns the dict representation of the actual instance"""
4242
return self.model_dump(by_alias=True)
4343

modules/openapi-generator/src/main/resources/python/model_oneof.mustache

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import pprint
44
{{{.}}}
55
{{/vendorExtensions.x-py-model-imports}}
66
from pydantic import Field, RootModel
7-
from typing import Any, Dict, Optional, Union
7+
from typing import Any, Dict, Union
8+
89

910
{{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ONE_OF_SCHEMAS = [{{#oneOf}}"{{.}}"{{^-last}}, {{/-last}}{{/oneOf}}]
1011

12+
1113
class {{classname}}(RootModel[Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]]):
1214
"""
1315
{{{description}}}{{^description}}{{{classname}}}{{/description}}
@@ -35,7 +37,7 @@ class {{classname}}(RootModel[Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/on
3537
"""Returns the JSON representation of the actual instance"""
3638
return self.model_dump_json(by_alias=True)
3739

38-
def to_dict(self) -> Optional[Union[Dict[str, Any], {{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}]]:
40+
def to_dict(self) -> Dict[str, Any]:
3941
"""Returns the dict representation of the actual instance"""
4042
return self.model_dump(by_alias=True)
4143

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_color.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import annotations
1616
import pprint
1717
from pydantic import Field, RootModel
18-
from typing import Any, Dict, Optional, Union
18+
from typing import Any, Dict, Union
1919

2020
ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"]
2121

@@ -48,7 +48,7 @@ def to_json(self) -> str:
4848
"""Returns the JSON representation of the actual instance"""
4949
return self.model_dump_json(by_alias=True)
5050

51-
def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]:
51+
def to_dict(self) -> Dict[str, Any]:
5252
"""Returns the dict representation of the actual instance"""
5353
return self.model_dump(by_alias=True)
5454

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/any_of_pig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from petstore_api.models.basque_pig import BasquePig
1818
from petstore_api.models.danish_pig import DanishPig
1919
from pydantic import Field, RootModel
20-
from typing import Any, Dict, Optional, Union
20+
from typing import Any, Dict, Union
2121

2222
ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"]
2323

@@ -50,7 +50,7 @@ def to_json(self) -> str:
5050
"""Returns the JSON representation of the actual instance"""
5151
return self.model_dump_json(by_alias=True)
5252

53-
def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]:
53+
def to_dict(self) -> Dict[str, Any]:
5454
"""Returns the dict representation of the actual instance"""
5555
return self.model_dump(by_alias=True)
5656

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/color.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
from __future__ import annotations
1616
import pprint
1717
from pydantic import Field, RootModel
18-
from typing import Any, Dict, Optional, Union
18+
from typing import Any, Dict, Union
19+
1920

2021
COLOR_ONE_OF_SCHEMAS = ["List[int]", "str"]
2122

23+
2224
class Color(RootModel[Union[List[int], str]]):
2325
"""
2426
RGB array, RGBA array, or hex string.
@@ -46,7 +48,7 @@ def to_json(self) -> str:
4648
"""Returns the JSON representation of the actual instance"""
4749
return self.model_dump_json(by_alias=True)
4850

49-
def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
51+
def to_dict(self) -> Dict[str, Any]:
5052
"""Returns the dict representation of the actual instance"""
5153
return self.model_dump(by_alias=True)
5254

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/int_or_string.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
from __future__ import annotations
1616
import pprint
1717
from pydantic import Field, RootModel
18-
from typing import Any, Dict, Optional, Union
18+
from typing import Any, Dict, Union
19+
1920

2021
INTORSTRING_ONE_OF_SCHEMAS = ["int", "str"]
2122

23+
2224
class IntOrString(RootModel[Union[int, str]]):
2325
"""
2426
IntOrString
@@ -46,7 +48,7 @@ def to_json(self) -> str:
4648
"""Returns the JSON representation of the actual instance"""
4749
return self.model_dump_json(by_alias=True)
4850

49-
def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
51+
def to_dict(self) -> Dict[str, Any]:
5052
"""Returns the dict representation of the actual instance"""
5153
return self.model_dump(by_alias=True)
5254

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pig.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
from petstore_api.models.basque_pig import BasquePig
1818
from petstore_api.models.danish_pig import DanishPig
1919
from pydantic import Field, RootModel
20-
from typing import Any, Dict, Optional, Union
20+
from typing import Any, Dict, Union
21+
2122

2223
PIG_ONE_OF_SCHEMAS = ["BasquePig", "DanishPig"]
2324

25+
2426
class Pig(RootModel[Union[BasquePig, DanishPig]]):
2527
"""
2628
Pig
@@ -48,7 +50,7 @@ def to_json(self) -> str:
4850
"""Returns the JSON representation of the actual instance"""
4951
return self.model_dump_json(by_alias=True)
5052

51-
def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
53+
def to_dict(self) -> Dict[str, Any]:
5254
"""Returns the dict representation of the actual instance"""
5355
return self.model_dump(by_alias=True)
5456

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/task_activity.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
from petstore_api.models.feeding import Feeding
1919
from petstore_api.models.poop_cleaning import PoopCleaning
2020
from pydantic import Field, RootModel
21-
from typing import Any, Dict, Optional, Union
21+
from typing import Any, Dict, Union
22+
2223

2324
TASKACTIVITY_ONE_OF_SCHEMAS = ["Bathing", "Feeding", "PoopCleaning"]
2425

26+
2527
class TaskActivity(RootModel[Union[Bathing, Feeding, PoopCleaning]]):
2628
"""
2729
TaskActivity
@@ -49,7 +51,7 @@ def to_json(self) -> str:
4951
"""Returns the JSON representation of the actual instance"""
5052
return self.model_dump_json(by_alias=True)
5153

52-
def to_dict(self) -> Optional[Union[Dict[str, Any], ]]:
54+
def to_dict(self) -> Dict[str, Any]:
5355
"""Returns the dict representation of the actual instance"""
5456
return self.model_dump(by_alias=True)
5557

samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_color.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import annotations
1616
import pprint
1717
from pydantic import Field, RootModel
18-
from typing import Any, Dict, Optional, Union
18+
from typing import Any, Dict, Union
1919

2020
ANYOFCOLOR_ANY_OF_SCHEMAS = ["List[int]", "str"]
2121

@@ -48,7 +48,7 @@ def to_json(self) -> str:
4848
"""Returns the JSON representation of the actual instance"""
4949
return self.model_dump_json(by_alias=True)
5050

51-
def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]:
51+
def to_dict(self) -> Dict[str, Any]:
5252
"""Returns the dict representation of the actual instance"""
5353
return self.model_dump(by_alias=True)
5454

samples/openapi3/client/petstore/python-httpx/petstore_api/models/any_of_pig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from petstore_api.models.basque_pig import BasquePig
1818
from petstore_api.models.danish_pig import DanishPig
1919
from pydantic import Field, RootModel
20-
from typing import Any, Dict, Optional, Union
20+
from typing import Any, Dict, Union
2121

2222
ANYOFPIG_ANY_OF_SCHEMAS = ["BasquePig", "DanishPig"]
2323

@@ -50,7 +50,7 @@ def to_json(self) -> str:
5050
"""Returns the JSON representation of the actual instance"""
5151
return self.model_dump_json(by_alias=True)
5252

53-
def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]:
53+
def to_dict(self) -> Dict[str, Any]:
5454
"""Returns the dict representation of the actual instance"""
5555
return self.model_dump(by_alias=True)
5656

0 commit comments

Comments
 (0)