koxudaxi / datamodel-code-generator

Pydantic model and dataclasses.dataclass generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
https://koxudaxi.github.io/datamodel-code-generator/
MIT License
2.77k stars 304 forks source link

Modular references require output directory error #1638

Open yogeshVU opened 1 year ago

yogeshVU commented 1 year ago

Describe the bug When working with a jsonschema and invoking the model generator, one encounters following error:

Modular references require an output directory, not a file

It appears that the naming causes this error
"title": "GenomeStudio 2.0 - Methylation Module",

To Reproduce

Example schema:


{
  "title": "test",
  "type": "object",
  "properties": {
"Liquid Biomarkers Input Data": {
      "type": "object",
      "properties": {
                "Methylomics": {
          "title": "Methylomics",
          "type": "object",
          "properties": {
            "Software": {
              "title": "Software",
              "type": "object",
              "anyOf": [
                {
                  "title": "GenomeStudio 2.0 - Methylation Module",
                  "type": "object",
                  "properties": {
                    "GenomeStudio": {
                      "title": "GenomeStudio",
                      "type": "object",
                      "properties": {},
                      "required": [],
                      "additionalProperties": false
                    }
                  },
                  "additionalProperties": false
                }

              ]
            }

          },
          "required": [],
          "additionalProperties": false
        }
      },
      "required": []
    }
  },
  "additionalProperties": false,
  "required": []
}

Used commandline:

$ datamodel-codegen --use-annotated --use-title-as-name --use-subclass-enum --disable-appending-item-suffix --input-file-type jsonschema  --input EnigmaContentModel.json --output testEnigmaModel.py --output-model-type pydantic_v2.BaseModel --allow-population-by-field-name --snake-case-field

Expected behavior Should not produce any modular reference errors.

Version:

Additional context Changing the tittle to simple naming eliminates the issue: such as "title": "GenomeStudio", So basically removing . from the title does not produce this bug

koxudaxi commented 1 year ago

Thank you for creating the PR. I guess some users may use the . in the title. it's to define a model as a module :thinking: Should we provide the option to strip . from the title?