datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Generated python file names contain invalid caharacters

Open pulasthibandara opened this issue 2 years ago • 2 comments

Describe the bug When generating data models from schemas in a directory (owned by another team in my case), the generated file names contain invalid characters, which doesn't allow python to import the module.

To Reproduce

example: INPUT

schemas:
  - order-request.schema.json
  - cancel-request.schema.json

example: OUTPUT

gen:
  - order-request.schema.py
  - cancel-request.schema.py

Used commandline:

$ datamodel-codegen --input "../schemas" --input-file-type jsonschema --output "./gen" 

Expected behavior The file names to be valid python module names, ex: periods and dash characters to be replaced by underscores.

Version:

  • OS: MacOs
  • Python version: 3.8
  • datamodel-code-generator version: 0.17.1

Additional context Workaround to import the module: https://stackoverflow.com/questions/8350853/how-to-import-module-when-module-name-has-a-dash-or-hyphen-in-it

pulasthibandara avatar Feb 26 '23 09:02 pulasthibandara

@pulasthibandara Thank you for creating the issue. I will fix it.

koxudaxi avatar Apr 18 '23 16:04 koxudaxi

Apologies, closed the wrong issue.

pulasthibandara avatar Oct 10 '23 23:10 pulasthibandara