grantila / typeconv

Convert between JSON Schema, TypeScript, GraphQL, Open API and SureType

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[jsc-to-ts] Discards descriptions on enums

notpushkin opened this issue · comments

Consider this schema:

{
  "title": "RDAP schema",
  "definitions": {
    "RdapEvent": {
      "title": "RdapEvent",
      "description": "This data structure represents events that have occurred on an instance of\nan object class.",
      "type": "object",
      "properties": {
        "eventAction": {
          "description": "the reason for the event",
          "type": "string"
        }
      },
      "required": ["eventAction"],
      "additionalProperties": false
    }
  }
}

typeconv translates this to the following TypeScript definition:

/**
 * This data structure represents events that have occurred on an instance of
 * an object class.
 */
export interface RdapEvent {
    /** the reason for the event */
    eventAction: string;
}

However if you update eventAction's definition to

{
  "description": "the reason for the event",
  "enum": ["registration", "reregistration", "last changed"]
}

The property's TSDoc comment is gone:

/**
 * This data structure represents events that have occurred on an instance of
 * an object class.
 */
export interface RdapEvent {
    eventAction: "registration" | "reregistration" | "last changed";
}

Slightly orthogonal, typeconv discards descriptions on enum definitions as well. Consider this schema:

{
  "definitions": {
    "EventAction": {
      "description": "This is some action that happened.",
      "enum": ["registration", "reregistration", "last changed"]
    },
    "Event": {
      "description": "This data structure represents events that have occurred on an instance of\nan object class.",
      "type": "object",
      "properties": {
        "eventAction": {
          "description": "the reason for the event",
          "allOf": [{ "$ref": "#/definitions/EventAction" }]
        }
      },
      "required": ["eventAction"],
      "additionalProperties": false
    }
  }
}

typeconv translates this to:

export type EventAction = "registration" | "reregistration" | "last changed";

/**
 * This data structure represents events that have occurred on an instance of
 * an object class.
 */
export interface Event {
    eventAction: EventAction;
}

While something like this would be more reasonable:

/** This is some action that happened. */
export type EventAction = "registration" | "reregistration" | "last changed";

/**
 * This data structure represents events that have occurred on an instance of
 * an object class.
 */
export interface Event {
    /** the reason for the event */
    eventAction: EventAction;
}

P. S. Thank you for this amazing project!