Skip to content

Commit

Permalink
Fix deprecation warnings around "copy_on_model_validation" (#927)
Browse files Browse the repository at this point in the history
* Fix deprecation warnings

* Support old pydantic version

* Add packaging to deps

Co-authored-by: Koudai Aono <koxudaxi@gmail.com>
  • Loading branch information
Dominic-Walther and koxudaxi committed Nov 22, 2022
1 parent 2b1b1d2 commit f7dfb11
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 551 deletions.
8 changes: 7 additions & 1 deletion datamodel_code_generator/reference.py
Expand Up @@ -29,6 +29,8 @@
)

import inflect
import pydantic
from packaging import version
from pydantic import BaseModel, validator

from datamodel_code_generator import cached_property
Expand Down Expand Up @@ -92,7 +94,11 @@ def validate_original_name(cls, v: Any, values: Dict[str, Any]) -> str:
class Config:
arbitrary_types_allowed = True
keep_untouched = (cached_property,)
copy_on_model_validation = False
copy_on_model_validation = (
False
if version.parse(pydantic.VERSION) < version.parse('1.9.2')
else 'none'
)

@property
def short_name(self) -> str:
Expand Down
10 changes: 8 additions & 2 deletions datamodel_code_generator/types.py
Expand Up @@ -21,6 +21,8 @@
Union,
)

import pydantic
from packaging import version
from pydantic import StrictBool, StrictInt, StrictStr, create_model

from datamodel_code_generator import Protocol, runtime_checkable
Expand Down Expand Up @@ -64,8 +66,12 @@ def module_name(self) -> str:

class DataType(_BaseModel):
class Config:
extra = "forbid"
copy_on_model_validation = False
extra = 'forbid'
copy_on_model_validation = (
False
if version.parse(pydantic.VERSION) < version.parse('1.9.2')
else 'none'
)

type: Optional[str]
reference: Optional[Reference]
Expand Down

0 comments on commit f7dfb11

Please sign in to comment.