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.66k stars 296 forks source link

References to other files don't work #1819

Open leonardopsantos opened 8 months ago

leonardopsantos commented 8 months ago

Describe the bug

References to other files don't work.

I have a custom schema that uses file references like so:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "file:Foo.schema.json",
    "title": "A schema file",
    "description": "Schema for validating the serialization of a Foo object.",
    "type": "object",
    "properties": {
        "bar": {
            "$ref": "Bar.schema.json"
        }
}

When calling datamodel-codegen:

$ datamodel-codegen --input /home/user/schemas/Foo.schema.json --output out --input-file-type jsonschema

Only the out folder is created with a Bar.py file.

Expected behavior

The out folder to have both Python files.

Version:

luca-knaack-webcom commented 3 months ago

As I understand it, the package creates just one output file, with all references being included directly (e.g. multiple models in one file), if your input is just one file (in your case home/user/schemas/Foo.schema.json). Have you tried giving as input /home/user/schemas?