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

References to other files don't work

Open leonardopsantos opened this issue 1 year ago • 1 comments

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:

  • OS: Ubuntu 22.04.3 LTS
  • Python version: Python 3.10.12
  • datamodel-code-generator version: 80266b4f6ea09bc7675466af459c7f6617f0c307

leonardopsantos avatar Jan 25 '24 17:01 leonardopsantos

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?

luca-knaack-webcom avatar Jun 17 '24 12:06 luca-knaack-webcom