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
Describe the bug
allOf with a single $ref with a local json-pointer in schemaA.json is not resolved correctly with schemaA.json is itself referenced from schemaB.json.
It seems like schemaB.json (where no definitions exist) is passed as self.raw_obj to get_model_by_path() but it should be schemaB.json. get_model_by_path() tries to look up the path but fails.
File ".venv\lib\site-packages\datamodel_code_generator\parser\jsonschema.py", line 1807, in _parse_file
self.parse_obj(obj_name, root_obj, path_parts or ['#'])
File ".venv\lib\site-packages\datamodel_code_generator\parser\jsonschema.py", line 1667, in parse_obj
self.parse_all_of(name, obj, path)
File ".venv\lib\site-packages\datamodel_code_generator\parser\jsonschema.py", line 871, in parse_all_of
if get_model_by_path(self.raw_obj, single_obj.ref[2:].split('/')).get(
File ".venv\lib\site-packages\datamodel_code_generator\parser\jsonschema.py", line 87, in get_model_by_path
model = get_model_by_path(schema[keys[0]], keys[1:]) # type: ignore
KeyError: 'definitions'
Expected behavior
No exception and the following model.py
Describe the bug
allOf with a single
$ref
with a local json-pointer in schemaA.json is not resolved correctly with schemaA.json is itself referenced from schemaB.json.It seems like schemaB.json (where no definitions exist) is passed as
self.raw_obj
toget_model_by_path()
but it should be schemaB.json.get_model_by_path()
tries to look up the path but fails.datamodel-code-generator/datamodel_code_generator/parser/jsonschema.py
Line 871 in 222f718
To Reproduce
schemaA
schemaB.json
Used commandline:
Error:
Expected behavior
No exception and the following model.py
or, even better, with the empty class SchemaA merged with SchemaAGenerated
Workarounds:
replacing
with
works, but produces
even with
--collapse-root-models
.Having an array of two
$refs
in allOf also works as expected:Version:
The text was updated successfully, but these errors were encountered: