datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Have option to generate config which allows extra fields

Open Davidswinkels opened this issue 3 years ago • 1 comments

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

Davidswinkels avatar Jun 03 '22 12:06 Davidswinkels

Bumping. Looking for this as well.

jheck88 avatar Aug 10 '22 18:08 jheck88

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.

koxudaxi avatar Dec 31 '22 01:12 koxudaxi