Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsc-to-ts] Discards descriptions on enums #22

Open
notpushkin opened this issue Apr 15, 2022 · 1 comment
Open

[jsc-to-ts] Discards descriptions on enums #22

notpushkin opened this issue Apr 15, 2022 · 1 comment

Comments

@notpushkin
Copy link

notpushkin commented Apr 15, 2022

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";
}
@notpushkin
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant