Skip to content

Commit 61fde48

Browse files
fix: Disable warnings for model_* properties (#17066)
For model classes with model_something fields, pydantic raises a warning by default: `Field "model_something" has conflict with protected namespace "model_".`. These warnings make no sense here, because most users of the generator have established APIs that they cannot change to conform to pydantic's safety rules. Pydantic will raise an error if we ever conflict with a current attribute like `model_dump`.
1 parent 6be4d2e commit 61fde48

File tree

167 files changed

+334
-167
lines changed

Some content is hidden

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

167 files changed

+334
-167
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
3838
any_of_schemas: List[str] = Literal[{{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ANY_OF_SCHEMAS]
3939

4040
model_config = {
41-
"validate_assignment": True
41+
"validate_assignment": True,
42+
"protected_namespaces": (),
4243
}
4344
{{#discriminator}}
4445

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

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

8383
model_config = {
8484
"populate_by_name": True,
85-
"validate_assignment": True
85+
"validate_assignment": True,
86+
"protected_namespaces": (),
8687
}
8788

8889

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
3434
one_of_schemas: List[str] = Literal[{{#oneOf}}"{{.}}"{{^-last}}, {{/-last}}{{/oneOf}}]
3535

3636
model_config = {
37-
"validate_assignment": True
37+
"validate_assignment": True,
38+
"protected_namespaces": (),
3839
}
3940

4041
{{#discriminator}}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class Bird(BaseModel):
3636

3737
model_config = {
3838
"populate_by_name": True,
39-
"validate_assignment": True
39+
"validate_assignment": True,
40+
"protected_namespaces": (),
4041
}
4142

4243

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class Category(BaseModel):
3636

3737
model_config = {
3838
"populate_by_name": True,
39-
"validate_assignment": True
39+
"validate_assignment": True,
40+
"protected_namespaces": (),
4041
}
4142

4243

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class DataQuery(Query):
3939

4040
model_config = {
4141
"populate_by_name": True,
42-
"validate_assignment": True
42+
"validate_assignment": True,
43+
"protected_namespaces": (),
4344
}
4445

4546

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

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

5555
model_config = {
5656
"populate_by_name": True,
57-
"validate_assignment": True
57+
"validate_assignment": True,
58+
"protected_namespaces": (),
5859
}
5960

6061

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class NumberPropertiesOnly(BaseModel):
3939

4040
model_config = {
4141
"populate_by_name": True,
42-
"validate_assignment": True
42+
"validate_assignment": True,
43+
"protected_namespaces": (),
4344
}
4445

4546

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/models/pet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def status_validate_enum(cls, value):
5353

5454
model_config = {
5555
"populate_by_name": True,
56-
"validate_assignment": True
56+
"validate_assignment": True,
57+
"protected_namespaces": (),
5758
}
5859

5960

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/models/query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def outcomes_validate_enum(cls, value):
4848

4949
model_config = {
5050
"populate_by_name": True,
51-
"validate_assignment": True
51+
"validate_assignment": True,
52+
"protected_namespaces": (),
5253
}
5354

5455

0 commit comments

Comments
 (0)