ts-json-schema-generator icon indicating copy to clipboard operation
ts-json-schema-generator copied to clipboard

External reference breaks arrays

Open wburgers opened this issue 1 year ago • 0 comments

Suppose we have the following types:

fileA:

export interface ClassA {
  property: string;
}

fileB:

export interface ClassB {
  /**
     * @ref ./ClassA.json
     */
  array: ClassA[];
}

Then the output becomes:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "additionalProperties": false,
    "definitions": {},
    "properties": {
        "array": {
            "$ref": "./ClassA.json"
        },
    },
    "required": [
        "array",
    ],
    "type": "object"
}

Where I would expect:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "additionalProperties": false,
    "definitions": {},
    "properties": {
        "array": {
            "items": {
                "$ref": "./ClassA.json"
            },
            "type": "array"
        },
    },
    "required": [
        "array",
    ],
    "type": "object"
}

Is there a way to get the right output as expected? Am I using the generator incorrectly?

wburgers avatar Feb 29 '24 09:02 wburgers