Skip to content

Commit bfe5ca8

Browse files
authored
python(pydantic): Use validate_by_name config; populate_by_name will be deprecated (#22931)
* modules * pydantic bump * samples * revert for fastapi generator and apply pydantic constrain everywhere
1 parent df4a1d6 commit bfe5ca8

405 files changed

Lines changed: 789 additions & 406 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ To be able to use it, you will need these dependencies in your own package that
3939
* pem >= 19.3.0
4040
* pycryptodome >= 3.9.0
4141
{{/hasHttpSignatureMethods}}
42-
* pydantic >= 2
42+
* pydantic >= 2.11
4343
* typing-extensions >= 4.7.1
4444

4545
## Getting Started

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
9494
{{/vars}}
9595

9696
model_config = ConfigDict(
97-
populate_by_name=True,
97+
validate_by_name=True,
98+
validate_by_alias=True,
9899
validate_assignment=True,
99100
protected_namespaces=(),
100101
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ tornado = ">=4.2, <5"
5151
pem = ">= 19.3.0"
5252
pycryptodome = ">= 3.9.0"
5353
{{/hasHttpSignatureMethods}}
54-
pydantic = ">= 2"
54+
pydantic = ">= 2.11"
5555
typing-extensions = ">= 4.7.1"
5656
{{#lazyImports}}
5757
lazy-imports = ">= 1, < 2"
@@ -79,7 +79,7 @@ dependencies = [
7979
"pem (>=19.3.0)",
8080
"pycryptodome (>=3.9.0)",
8181
{{/hasHttpSignatureMethods}}
82-
"pydantic (>=2)",
82+
"pydantic (>=2.11)",
8383
"typing-extensions (>=4.7.1)",
8484
{{#lazyImports}}
8585
"lazy-imports (>=1,<2)"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tornado = ">= 4.2, < 5"
1616
pem >= 19.3.0
1717
pycryptodome >= 3.9.0
1818
{{/hasHttpSignatureMethods}}
19-
pydantic >= 2
19+
pydantic >= 2.11
2020
typing-extensions >= 4.7.1
2121
{{#lazyImports}}
2222
lazy-imports >= 1, < 2

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ REQUIRES = [
3030
"pem >= 19.3.0",
3131
"pycryptodome >= 3.9.0",
3232
{{/hasHttpSignatureMethods}}
33-
"pydantic >= 2",
33+
"pydantic >= 2.11",
3434
"typing-extensions >= 4.7.1",
3535
{{#lazyImports}}
3636
"lazy-imports >= 1, < 2",

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/bird.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class Bird(BaseModel):
3232
__properties: ClassVar[List[str]] = ["size", "color"]
3333

3434
model_config = ConfigDict(
35-
populate_by_name=True,
35+
validate_by_name=True,
36+
validate_by_alias=True,
3637
validate_assignment=True,
3738
protected_namespaces=(),
3839
)

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/category.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class Category(BaseModel):
3232
__properties: ClassVar[List[str]] = ["id", "name"]
3333

3434
model_config = ConfigDict(
35-
populate_by_name=True,
35+
validate_by_name=True,
36+
validate_by_alias=True,
3637
validate_assignment=True,
3738
protected_namespaces=(),
3839
)

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/data_query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class DataQuery(Query):
3535
__properties: ClassVar[List[str]] = ["id", "outcomes", "suffix", "text", "date"]
3636

3737
model_config = ConfigDict(
38-
populate_by_name=True,
38+
validate_by_name=True,
39+
validate_by_alias=True,
3940
validate_assignment=True,
4041
protected_namespaces=(),
4142
)

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def array_string_enum_default_validate_enum(cls, value):
5050
return value
5151

5252
model_config = ConfigDict(
53-
populate_by_name=True,
53+
validate_by_name=True,
54+
validate_by_alias=True,
5455
validate_assignment=True,
5556
protected_namespaces=(),
5657
)

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/number_properties_only.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class NumberPropertiesOnly(BaseModel):
3434
__properties: ClassVar[List[str]] = ["number", "float", "double"]
3535

3636
model_config = ConfigDict(
37-
populate_by_name=True,
37+
validate_by_name=True,
38+
validate_by_alias=True,
3839
validate_assignment=True,
3940
protected_namespaces=(),
4041
)

0 commit comments

Comments
 (0)