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

BUG: type enum generate error when have description (in v0.58.1, the reason for this issue is the submission #550 ) #555

Closed liangskyli closed 1 year ago

liangskyli commented 1 year ago

After upgrading from v0.57.0 to 0.58.1, is error! type

type MyObject = {
    param1: "1" | "2" | "3";
    param2: "1" | "2" | 3 | true;
    /** @enum {string} */
    param3: "1" | "2" | "3";
    /** @enum {unknown} */
    param4: "1" | "2" | 3 | true;
};

Example of generated json in v0.57.0, generator ok!

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "properties": {
    "param1": {
      "enum": ["1", "2", "3"],
      "type": "string"
    },
    "param2": {
      "enum": ["1", "2", 3, true]
    },
    "param3": {
      "enum": ["1", "2", "3"],
      "type": "string"
    },
    "param4": {
      "enum": ["1", "2", 3, true]
    }
  },
  "required": ["param1", "param2", "param3", "param4"],
  "type": "object"
}

Example of generated json in v0.58.1, generator ok!

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "properties": {
    "param1": {
      "enum": ["1", "2", "3"],
      "type": "string"
    },
    "param2": {
      "enum": ["1", "2", 3, true]
    },
    "param3": {
      "enum": "",
      "type": "string"
    },
    "param4": {
      "enum": ""
    }
  },
  "required": ["param1", "param2", "param3", "param4"],
  "type": "object"
}

in v0.58.1, param3 and param4 generator error! The reason for this issue is the submission #550

liangskyli commented 1 year ago

@jwatzman : in #550 causing this problem, the bug you fixed triggered this new bug!

liangskyli commented 1 year ago

If there is no good way, it is recommended to roll back this submission first

jwatzman commented 1 year ago

Huh weird! I'm taking a quick look at this now and might have a slightly better fix. But reverting is reasonable too.