YousefED / typescript-json-schema

Generate json-schema from your Typescript sources
BSD 3-Clause "New" or "Revised" License
3.17k stars 323 forks source link

Array of types vs array of interfaces inconsistency #517

Open filiplikavcan opened 1 year ago

filiplikavcan commented 1 year ago

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"
  }
}