datamodel-code-generator
datamodel-code-generator copied to clipboard
Elastic's Kibana API interaction with datamodel-code-generator not working
Describe the bug
While trying to generate a pydantic code model with datamodel-codegen for Kibana's API, command didn't work. API is available here (https://www.elastic.co/docs/api/doc/kibana)
pydantic_core._pydantic_core.ValidationError: 1 validation error for JsonSchemaObject
required.2
Input should be a valid string [type=string_type, input_value={'anyOf': ['to', 'cc', 'bcc']}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.10/v/string_type
Honestly I'm not able to figure out whether Kibana's OpenAPI export is malformed or is there a problem with the datamodel-code-generator, since the error is not very explicative, so this may not be a bug.
To Reproduce
Used commandline:
Local:
datamodel-codegen --input ~/Downloads/kibana-openapi-source.json
Remote
$ datamodel-codegen --url "https://www.elastic.co/docs/api/doc/kibana/v8.json"
Expected behavior Not getting an error
Version:
- OS: Ubuntu 24
- Python version: 3.10
- datamodel-code-generator version: 0.26.5
These are the errors I currently get with the newest OpenAPI specifications provided by Elastic:
❯ uvx --from "datamodel-code-generator[http]" datamodel-codegen --url https://www.elastic.co/docs/api/doc/kibana.json --input-file-type openapi --disable-warnings --output model.py
Traceback (most recent call last):
File "/home/user/.cache/uv/archive-v0/UCkDNN2DAHUrkULTwK1Qb/lib/python3.8/site-packages/datamodel_code_generator/__main__.py", line 473, in main
generate(
File "/home/user/.cache/uv/archive-v0/UCkDNN2DAHUrkULTwK1Qb/lib/python3.8/site-packages/datamodel_code_generator/__init__.py", line 480, in generate
results = parser.parse()
File "/home/user/.cache/uv/archive-v0/UCkDNN2DAHUrkULTwK1Qb/lib/python3.8/site-packages/datamodel_code_generator/parser/base.py", line 1178, in parse
self.parse_raw()
File "/home/user/.cache/uv/archive-v0/UCkDNN2DAHUrkULTwK1Qb/lib/python3.8/site-packages/datamodel_code_generator/parser/openapi.py", line 582, in parse_raw
self.parse_raw_obj(
File "/home/user/.cache/uv/archive-v0/UCkDNN2DAHUrkULTwK1Qb/lib/python3.8/site-packages/datamodel_code_generator/parser/jsonschema.py", line 1526, in parse_raw_obj
self.parse_obj(name, self.SCHEMA_OBJECT_TYPE.parse_obj(raw), path)
File "/home/user/.cache/uv/archive-v0/UCkDNN2DAHUrkULTwK1Qb/lib/python3.8/site-packages/pydantic/main.py", line 1222, in parse_obj
return cls.model_validate(obj)
File "/home/user/.cache/uv/archive-v0/UCkDNN2DAHUrkULTwK1Qb/lib/python3.8/site-packages/pydantic/main.py", line 627, in model_validate
return cls.__pydantic_validator__.validate_python(
pydantic_core._pydantic_core.ValidationError: 1 validation error for JsonSchemaObject
required
Input should be a valid list [type=list_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.10/v/list_type
It is the same output with uvx --from "datamodel-code-generator[http]" datamodel-codegen --url https://www.elastic.co/docs/api/doc/kibana.yaml --input-file-type openapi --disable-warnings --output model.py.