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

Adding a description to a $ref object referencing an enum inlines the enum

Open JoshuaKGoldberg opened this issue 3 years ago • 3 comments

Perhaps related to #470, but not the same issue. Here, I'm seeing that when a $ref pointing to a defined enum has a description, the enum gets inlined.

{
  "$definitions": {
    "shared": {
      "enum": ["a", "b"]
    }
  },
  "properties": {
    "first": {
      "$ref": "#/$definitions/shared",
      "description": "A first property."
    }
  },
  "additionalProperties": false,
  "title": "Example Schema",
  "type": "object"
}

Note that if the description is removed from properties.first, the export type Shared = "a" | "b"; gets printed as expected.

Actual

export interface ExampleSchema {
  /**
   * A first property.
   */
  first?: "a" | "b";
}

Expected

export type Shared = "a" | "b";

export interface ExampleSchema {
  /**
   * A first property.
   */
  first?: Shared;
}

JoshuaKGoldberg avatar Jul 29 '22 07:07 JoshuaKGoldberg