Skip to content

Commit 1105d36

Browse files
committed
[python] regenerate public-name samples
Regenerate the modern Python petstore clients after separating wire, public, and storage names. The fixtures cover leading-underscore names, Pydantic and generated-member collisions, import names, and inherited fields while retaining the Pydantic 2.11 minimum.
1 parent 38de24b commit 1105d36

17 files changed

Lines changed: 948 additions & 49 deletions

File tree

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

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
import re # noqa: F401
1818
import json
1919

20-
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21-
from typing import Any, ClassVar, Dict, List, Optional
20+
from collections.abc import Mapping as _Mapping
21+
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, ModelWrapValidatorHandler as _ModelWrapValidatorHandler, StrictStr, model_validator as _model_validator
22+
from typing import Any, ClassVar, Dict, List, Optional, cast as _cast
2223
from typing import Optional, Set
2324
from typing_extensions import Self
2425
from pydantic_core import to_jsonable_python
@@ -27,11 +28,67 @@ class PropertyNameCollision(BaseModel):
2728
"""
2829
PropertyNameCollision
2930
""" # noqa: E501
30-
underscore_type: Optional[StrictStr] = Field(default=None, alias="_type")
31+
underscore_type: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("_type", "underscore_type"), serialization_alias="_type")
3132
type: Optional[StrictStr] = None
32-
type_with_underscore: Optional[StrictStr] = Field(default=None, alias="type_")
33+
type_with_underscore: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("type_", "type_with_underscore"), serialization_alias="type_")
3334
__properties: ClassVar[List[str]] = ["_type", "type", "type_"]
3435

36+
@classmethod
37+
def __preprocess_input_names(
38+
cls,
39+
obj: Any,
40+
remove_hidden_storage_names: bool = True,
41+
) -> Any:
42+
if not isinstance(obj, _Mapping):
43+
return obj
44+
obj = dict(obj)
45+
if (
46+
"_type" in obj
47+
and "underscore_type" in obj
48+
):
49+
raise ValueError(
50+
"%s received both %r and %r"
51+
% (
52+
cls.__name__,
53+
"_type",
54+
"underscore_type",
55+
)
56+
)
57+
if "_type" not in obj and "underscore_type" in obj:
58+
obj["_type"] = obj["underscore_type"]
59+
obj.pop("underscore_type", None)
60+
if (
61+
"type_" in obj
62+
and "type_with_underscore" in obj
63+
):
64+
raise ValueError(
65+
"%s received both %r and %r"
66+
% (
67+
cls.__name__,
68+
"type_",
69+
"type_with_underscore",
70+
)
71+
)
72+
if "type_" not in obj and "type_with_underscore" in obj:
73+
obj["type_"] = obj["type_with_underscore"]
74+
obj.pop("type_with_underscore", None)
75+
return obj
76+
77+
# Pydantic passes the model instance to wrap validators during assignment:
78+
# https://docs.pydantic.dev/2.11/migration/#changes-to-validators
79+
# Private names also keep inherited model validators distinct:
80+
# https://docs.pydantic.dev/2.11/concepts/validators/#on-inheritance
81+
@_model_validator(mode="wrap")
82+
@classmethod
83+
def __validate_input_names(
84+
cls,
85+
obj: Any,
86+
handler: _ModelWrapValidatorHandler[Self],
87+
) -> Self:
88+
if not isinstance(obj, cls):
89+
obj = cls.__preprocess_input_names(obj)
90+
return handler(obj)
91+
3592
model_config = ConfigDict(
3693
validate_by_name=True,
3794
validate_by_alias=True,
@@ -82,6 +139,14 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
82139
if not isinstance(obj, dict):
83140
return cls.model_validate(obj)
84141

142+
obj = _cast(
143+
Dict[str, Any],
144+
cls.__preprocess_input_names(
145+
obj,
146+
remove_hidden_storage_names=True,
147+
),
148+
)
149+
85150
_obj = cls.model_validate({
86151
"_type": obj.get("_type"),
87152
"type": obj.get("type"),

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

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
import re # noqa: F401
1818
import json
1919

20-
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21-
from typing import Any, ClassVar, Dict, List, Optional
20+
from collections.abc import Mapping as _Mapping
21+
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, ModelWrapValidatorHandler as _ModelWrapValidatorHandler, StrictStr, model_validator as _model_validator
22+
from typing import Any, ClassVar, Dict, List, Optional, cast as _cast
2223
from typing import Optional, Set
2324
from typing_extensions import Self
2425
from pydantic_core import to_jsonable_python
@@ -27,11 +28,67 @@ class PropertyNameCollision(BaseModel):
2728
"""
2829
PropertyNameCollision
2930
""" # noqa: E501
30-
underscore_type: Optional[StrictStr] = Field(default=None, alias="_type")
31+
underscore_type: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("_type", "underscore_type"), serialization_alias="_type")
3132
type: Optional[StrictStr] = None
32-
type_with_underscore: Optional[StrictStr] = Field(default=None, alias="type_")
33+
type_with_underscore: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("type_", "type_with_underscore"), serialization_alias="type_")
3334
__properties: ClassVar[List[str]] = ["_type", "type", "type_"]
3435

36+
@classmethod
37+
def __preprocess_input_names(
38+
cls,
39+
obj: Any,
40+
remove_hidden_storage_names: bool = True,
41+
) -> Any:
42+
if not isinstance(obj, _Mapping):
43+
return obj
44+
obj = dict(obj)
45+
if (
46+
"_type" in obj
47+
and "underscore_type" in obj
48+
):
49+
raise ValueError(
50+
"%s received both %r and %r"
51+
% (
52+
cls.__name__,
53+
"_type",
54+
"underscore_type",
55+
)
56+
)
57+
if "_type" not in obj and "underscore_type" in obj:
58+
obj["_type"] = obj["underscore_type"]
59+
obj.pop("underscore_type", None)
60+
if (
61+
"type_" in obj
62+
and "type_with_underscore" in obj
63+
):
64+
raise ValueError(
65+
"%s received both %r and %r"
66+
% (
67+
cls.__name__,
68+
"type_",
69+
"type_with_underscore",
70+
)
71+
)
72+
if "type_" not in obj and "type_with_underscore" in obj:
73+
obj["type_"] = obj["type_with_underscore"]
74+
obj.pop("type_with_underscore", None)
75+
return obj
76+
77+
# Pydantic passes the model instance to wrap validators during assignment:
78+
# https://docs.pydantic.dev/2.11/migration/#changes-to-validators
79+
# Private names also keep inherited model validators distinct:
80+
# https://docs.pydantic.dev/2.11/concepts/validators/#on-inheritance
81+
@_model_validator(mode="wrap")
82+
@classmethod
83+
def __validate_input_names(
84+
cls,
85+
obj: Any,
86+
handler: _ModelWrapValidatorHandler[Self],
87+
) -> Self:
88+
if not isinstance(obj, cls):
89+
obj = cls.__preprocess_input_names(obj)
90+
return handler(obj)
91+
3592
model_config = ConfigDict(
3693
validate_by_name=True,
3794
validate_by_alias=True,
@@ -82,6 +139,14 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
82139
if not isinstance(obj, dict):
83140
return cls.model_validate(obj)
84141

142+
obj = _cast(
143+
Dict[str, Any],
144+
cls.__preprocess_input_names(
145+
obj,
146+
remove_hidden_storage_names=True,
147+
),
148+
)
149+
85150
_obj = cls.model_validate({
86151
"_type": obj.get("_type"),
87152
"type": obj.get("type"),

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

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
import re # noqa: F401
1818
import json
1919

20-
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21-
from typing import Any, ClassVar, Dict, List, Optional
20+
from collections.abc import Mapping as _Mapping
21+
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, ModelWrapValidatorHandler as _ModelWrapValidatorHandler, StrictStr, model_validator as _model_validator
22+
from typing import Any, ClassVar, Dict, List, Optional, cast as _cast
2223
from typing import Optional, Set
2324
from typing_extensions import Self
2425
from pydantic_core import to_jsonable_python
@@ -27,11 +28,67 @@ class PropertyNameCollision(BaseModel):
2728
"""
2829
PropertyNameCollision
2930
""" # noqa: E501
30-
underscore_type: Optional[StrictStr] = Field(default=None, alias="_type")
31+
underscore_type: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("_type", "underscore_type"), serialization_alias="_type")
3132
type: Optional[StrictStr] = None
32-
type_with_underscore: Optional[StrictStr] = Field(default=None, alias="type_")
33+
type_with_underscore: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("type_", "type_with_underscore"), serialization_alias="type_")
3334
__properties: ClassVar[List[str]] = ["_type", "type", "type_"]
3435

36+
@classmethod
37+
def __preprocess_input_names(
38+
cls,
39+
obj: Any,
40+
remove_hidden_storage_names: bool = True,
41+
) -> Any:
42+
if not isinstance(obj, _Mapping):
43+
return obj
44+
obj = dict(obj)
45+
if (
46+
"_type" in obj
47+
and "underscore_type" in obj
48+
):
49+
raise ValueError(
50+
"%s received both %r and %r"
51+
% (
52+
cls.__name__,
53+
"_type",
54+
"underscore_type",
55+
)
56+
)
57+
if "_type" not in obj and "underscore_type" in obj:
58+
obj["_type"] = obj["underscore_type"]
59+
obj.pop("underscore_type", None)
60+
if (
61+
"type_" in obj
62+
and "type_with_underscore" in obj
63+
):
64+
raise ValueError(
65+
"%s received both %r and %r"
66+
% (
67+
cls.__name__,
68+
"type_",
69+
"type_with_underscore",
70+
)
71+
)
72+
if "type_" not in obj and "type_with_underscore" in obj:
73+
obj["type_"] = obj["type_with_underscore"]
74+
obj.pop("type_with_underscore", None)
75+
return obj
76+
77+
# Pydantic passes the model instance to wrap validators during assignment:
78+
# https://docs.pydantic.dev/2.11/migration/#changes-to-validators
79+
# Private names also keep inherited model validators distinct:
80+
# https://docs.pydantic.dev/2.11/concepts/validators/#on-inheritance
81+
@_model_validator(mode="wrap")
82+
@classmethod
83+
def __validate_input_names(
84+
cls,
85+
obj: Any,
86+
handler: _ModelWrapValidatorHandler[Self],
87+
) -> Self:
88+
if not isinstance(obj, cls):
89+
obj = cls.__preprocess_input_names(obj)
90+
return handler(obj)
91+
3592
model_config = ConfigDict(
3693
validate_by_name=True,
3794
validate_by_alias=True,
@@ -82,6 +139,14 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
82139
if not isinstance(obj, dict):
83140
return cls.model_validate(obj)
84141

142+
obj = _cast(
143+
Dict[str, Any],
144+
cls.__preprocess_input_names(
145+
obj,
146+
remove_hidden_storage_names=True,
147+
),
148+
)
149+
85150
_obj = cls.model_validate({
86151
"_type": obj.get("_type"),
87152
"type": obj.get("type"),

samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/property_name_collision.py

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
import re # noqa: F401
1818
import json
1919

20-
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21-
from typing import Any, ClassVar, Dict, List, Optional
20+
from collections.abc import Mapping as _Mapping
21+
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, ModelWrapValidatorHandler as _ModelWrapValidatorHandler, StrictStr, model_validator as _model_validator
22+
from typing import Any, ClassVar, Dict, List, Optional, cast as _cast
2223
from typing import Optional, Set
2324
from typing_extensions import Self
2425
from pydantic_core import to_jsonable_python
@@ -27,12 +28,68 @@ class PropertyNameCollision(BaseModel):
2728
"""
2829
PropertyNameCollision
2930
""" # noqa: E501
30-
underscore_type: Optional[StrictStr] = Field(default=None, alias="_type")
31+
underscore_type: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("_type", "underscore_type"), serialization_alias="_type")
3132
type: Optional[StrictStr] = None
32-
type_with_underscore: Optional[StrictStr] = Field(default=None, alias="type_")
33+
type_with_underscore: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("type_", "type_with_underscore"), serialization_alias="type_")
3334
additional_properties: Dict[str, Any] = {}
3435
__properties: ClassVar[List[str]] = ["_type", "type", "type_"]
3536

37+
@classmethod
38+
def __preprocess_input_names(
39+
cls,
40+
obj: Any,
41+
remove_hidden_storage_names: bool = True,
42+
) -> Any:
43+
if not isinstance(obj, _Mapping):
44+
return obj
45+
obj = dict(obj)
46+
if (
47+
"_type" in obj
48+
and "underscore_type" in obj
49+
):
50+
raise ValueError(
51+
"%s received both %r and %r"
52+
% (
53+
cls.__name__,
54+
"_type",
55+
"underscore_type",
56+
)
57+
)
58+
if "_type" not in obj and "underscore_type" in obj:
59+
obj["_type"] = obj["underscore_type"]
60+
obj.pop("underscore_type", None)
61+
if (
62+
"type_" in obj
63+
and "type_with_underscore" in obj
64+
):
65+
raise ValueError(
66+
"%s received both %r and %r"
67+
% (
68+
cls.__name__,
69+
"type_",
70+
"type_with_underscore",
71+
)
72+
)
73+
if "type_" not in obj and "type_with_underscore" in obj:
74+
obj["type_"] = obj["type_with_underscore"]
75+
obj.pop("type_with_underscore", None)
76+
return obj
77+
78+
# Pydantic passes the model instance to wrap validators during assignment:
79+
# https://docs.pydantic.dev/2.11/migration/#changes-to-validators
80+
# Private names also keep inherited model validators distinct:
81+
# https://docs.pydantic.dev/2.11/concepts/validators/#on-inheritance
82+
@_model_validator(mode="wrap")
83+
@classmethod
84+
def __validate_input_names(
85+
cls,
86+
obj: Any,
87+
handler: _ModelWrapValidatorHandler[Self],
88+
) -> Self:
89+
if not isinstance(obj, cls):
90+
obj = cls.__preprocess_input_names(obj)
91+
return handler(obj)
92+
3693
model_config = ConfigDict(
3794
validate_by_name=True,
3895
validate_by_alias=True,
@@ -90,6 +147,14 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
90147
if not isinstance(obj, dict):
91148
return cls.model_validate(obj)
92149

150+
obj = _cast(
151+
Dict[str, Any],
152+
cls.__preprocess_input_names(
153+
obj,
154+
remove_hidden_storage_names=True,
155+
),
156+
)
157+
93158
_obj = cls.model_validate({
94159
"_type": obj.get("_type"),
95160
"type": obj.get("type"),

samples/openapi3/client/petstore/python/docs/Animal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
Name | Type | Description | Notes
77
------------ | ------------- | ------------- | -------------
8-
**class_name** | **str** | |
8+
**_class_name** | **str** | |
99
**color** | **str** | | [optional] [default to 'red']
1010

1111
## Example

0 commit comments

Comments
 (0)