datamodel-code-generator
datamodel-code-generator copied to clipboard
Have option to generate config which allows extra fields
Is your feature request related to a problem? Please describe. Use extra field in the generated pydantic datamodel, that will not raise an error that extra fields are not permitted.
Describe the solution you'd like We do want to keep raising errors if required fields are not there, but we don't want errors anymore when there are extra fields.
Code example (source: https://stackoverflow.com/questions/67201952/pydantic-add-field-to-model-after-a-model-validation-add-filed-to-incoming-mode):
import pydantic
from pydantic import Extra
class A(pydantic.BaseModel):
a: str = "qwer"
class Config:
extra = Extra.allow
a = A()
a.b = 1234
print(a) # a = 'qwer' b = 1234
Bumping. Looking for this as well.
I'm sorry for my too-late reply.
@Davidswinkels @jheck88 @fgebhart I have released the new version as 0.14.1
Thank you very much.