typescript-json-schema icon indicating copy to clipboard operation
typescript-json-schema copied to clipboard

Array of types vs array of interfaces inconsistency

Open filiplikavcan opened this issue 2 years ago • 0 comments

I think there is an inconsistency when generating custom type/interface array schema. I would expect $ref for both cases when using this config:

{
    topRef: true,
    ref: true,
    aliasRef: true,
}

CardLink as type

type CardLink = {
    URL: string;
};

type Card = {
    Links: CardLink[];
};

When CardLink is type the resulting schema for CardLink[] is:

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "URL": {
        "type": "string"
      }
    }
  }
}

CardLink as interface

interface CardLink {
    URL: string;
}

type Card = {
    Links: CardLink[];
};

When CardLink is interface the resulting schema for CardLink[] is:

{
  "type": "array",
  "items": {
    "$ref": "#/definitions/CardLink"
  }
}

filiplikavcan avatar Dec 10 '22 10:12 filiplikavcan