You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ datamodel-codegen --input repro.yaml --output repro.py --enum-field-as-literal all
Expected behavior
I expected my models to be generated looking like...
class MyObject(BaseModel):
my_nullable_enum: Optional[Literal['foo', 'bar']] = Field(...)
Error
Traceback (most recent call last):
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/__main__.py", line 407, in main
generate(
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/__init__.py", line 334, in generate
results = parser.parse()
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/parser/base.py", line 393, in parse
self.parse_raw()
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/parser/openapi.py", line 31, in parse_raw
self.parse_raw_obj(
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/parser/jsonschema.py", line 1023, in parse_raw_obj
self.parse_obj(name, JsonSchemaObject.parse_obj(raw), path)
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/parser/jsonschema.py", line 1033, in parse_obj
self.parse_object(name, obj, path)
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/parser/jsonschema.py", line 556, in parse_object
fields=self.parse_object_fields(
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/parser/jsonschema.py", line 509, in parse_object_fields
field_type = self.parse_item(modular_name, field, [*path, field_name])
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/parser/jsonschema.py", line 633, in parse_item
return self.data_type(literals=item.enum)
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/types.py", line 197, in __init__
super().__init__(**values) # type: ignore
File "/Users/philipbjorge/.cache/pre-commit/repor4mhqibo/py_env-python3.9/lib/python3.9/site-packages/datamodel_code_generator/reference.py", line 41, in __init__
super().__init__(**values)
File "pydantic/main.py", line 400, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for ContextDataType
literals -> 2
none is not an allowed value (type=type_error.none.not_allowed)
Version:
OS: OSX
Python version: 3.9.4
datamodel-code-generator version: 0.11.3
Thanks for taking a look at this, really appreciate all the great work gone into this library!
The text was updated successfully, but these errors were encountered:
@koxudaxi --
Thank you so much for being so responsive on this project! Thanks for cutting a release too!
I didn't even have to explain to my team why we're taking a fork :)
Describe the bug
We are creating a nullable enum type as described here and supported here.
To Reproduce
Example schema:
Used commandline:
Expected behavior
I expected my models to be generated looking like...
Error
Version:
Thanks for taking a look at this, really appreciate all the great work gone into this library!
The text was updated successfully, but these errors were encountered: