I'm generating a pydantic_v2.BaseModel from the envoy config jsonschema found here:
https://github.com/jcchavezs/envoy-config-schema/releases/tag/v1.21.0
For some of these schema files, if I pass a directory for output it produces this error:
$ pip install datamodel-code-generator[http]
$ mkdir schema_models/
$ datamodel-codegen --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output schema_models/ --url https://github.com/jcchavezs/envoy-config-schema/releases/download/v1.21.0/v2_Runtime.json
Traceback (most recent call last):
File "xxx/datamodel_code_generator/__main__.py", line 447, in main
generate(
File "xxx/site-packages/datamodel_code_generator/__init__.py", line 513, in generate
file = path.open('wt', encoding=encoding)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/adamh/.pyenv/versions/3.11.5/lib/python3.11/pathlib.py", line 1044, in open
return io.open(self, mode, buffering, encoding, errors, newline)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IsADirectoryError: [Errno 21] Is a directory: 'xxx/schema_models'
But if I try to always output to a file it fails in a different way on another file:
$ datamodel-codegen --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output v2_LayeredRuntime.py --url https://github.com/jcchavezs/envoy-config-schema/releases/download/v1.21.0/v2_LayeredRuntime.json
xxx/datamodel_code_generator/parser/jsonschema.py:338: UserWarning: format of 'regex' not understood for 'string' - using default
warn(f'format of {format__!r} not understood for {type_!r} - using default' '')
Modular references require an output directory, not a file
If I comment out this line it does seem to work for all input files with output going to one directory:
But I'm not sure what the impact of that is, the line is quite old.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too