yunke-yunfly / fast-typescript-to-jsonschema

typescript-to-jsonschema generates JSON Schema files from your Typescript sources.
MIT License
33 stars 2 forks source link

支持整体输出json嘛 #30

Open canyuegongzi opened 6 months ago

canyuegongzi commented 6 months ago

目前有定义类型如下:

/**
 * @Component 测试组件名称
 */
export interface BaseIProps {
    /**
     * @label 名称
     *
     * @type {string}
     */
    name: string;

    /**
     * 年龄
     *
     * @type {number} [age=25]
     */
    age: number;

    /**
     * @Title 文章集合
     */
    posts: Post[]
}

export interface Post {

    /**
     * @Title 文章Id
     */
    id: number;

    /**
     * @Title 文章缩略图
     */
    img: string;
}

输出了json 如下:

{
  "/Users/zcy1/Desktop/project/lowcode/lowcode-set-up-platform/packages/build-schema/__tests__/BaseIProps.ts": {
    "BaseIProps": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "age": {
          "type": "number",
          "description": "年龄"
        },
        "posts": {
          "type": "array",
          "items": {
            "$ref": "#Post"
          }
        }
      },
      "required": [
        "name",
        "age",
        "posts"
      ],
      "additionalProperties": false
    },
    "Post": {
      "type": "object",
      "properties": {
        "id": {
          "type": "number"
        },
        "img": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "img"
      ],
      "additionalProperties": false
    }
  }
}

请问能支持整体输出json嘛,如

{
  "/Users/zcy1/Desktop/project/lowcode/lowcode-set-up-platform/packages/build-schema/__tests__/BaseIProps.ts": {
    "BaseIProps": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "age": {
          "type": "number",
          "description": "年龄"
        },
        "posts": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "number"
              },
              "img": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "img"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "name",
        "age",
        "posts"
      ],
      "additionalProperties": false
    }
  }
}

不使用ref引用。