Open Timur941 opened 1 year ago
Thank you for creating the issue. I'm sorry for my late reply. I found the same issue https://github.com/koxudaxi/datamodel-code-generator/issues/1638
I guess some users use .
in schema name. They want to define the schema as a module.
I am considering introducing an option to exclude .
from the schema name.
The CLI should Introduce the option as a warning if the model name contains a .
.
I think the option is a good solution.
In my case it would be quite enough to exclude .
from the title and concat its parts into one PascalCase word to generate just one output file.
But what if it is necessary to maintain a modular structure with all these directories? As I understand, the imports error mentioned in this issue will persist?
Describe the bug When generating models from the openapi specification and when the names of the schemas contain dots, incorrect imports are generated inside init.py for modules that are actually located in the same directory
Only inside init.py the extra dot in the import statement is added. In other generated .py files, imports are generated correct
To Reproduce
Example schema:
Used commandline:
Actual behavior The following file and folder structure was created
Code for init.py inside B folder
There are one extra '.' in 'from .. import D' statement because module D is in the same directory
Trying to use a class from that init.py and getting error
Expected behavior Relative Import inside init.py should not contain an extra dot in situations where reference to a module in the same directory is used
For init.py code from above it expected to look like this
Version:
Additional context I guess such behavior is related to these lines of code in parser/base.py https://github.com/koxudaxi/datamodel-code-generator/blob/60256efafc34377e93640134bbed757e579acfb3/datamodel_code_generator/parser/base.py#L688-L690