Describe the bug
Generating models from a nested directory structure with relative references leads to invalid imports. For the structure shown below, the generated class for B has invalid relative import. It's almost perfect besides that issue, the exported directory structure mirrors my schema directory correctly:
from __future__ import annotations
from typing import Optional
from ..foo.barA import A
# should be >> from ..foo.bar.A import A
class B(A):
name: Optional[str] = None
To Reproduce
A nested schema directory structure as:
schema/foo/bar/A.yml
---
title: A
type: object
properties:
something:
type: string
schema/baz/B.yml
---
title: B
type: object
allOf:
- $ref: "../foo/bar/A.yml#"
properties:
name:
type: string
Used commandline:
$ datamodel-codegen --input aschema/ --input-file-type jsonschema --output tmp
Expected behavior
The relative import in the generated python file should correctly reference the nested submodule
from ..foo.bar.A import A
Version:
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