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

【求助】不是单体文件也可以正常解析吗? #27

Open 5icoder opened 1 year ago

5icoder commented 1 year ago

const { ThirdPartyType } = require('third-party);

const IType = {
    name: string;
    property: ThirdPartyType
}```

请问这样的文件能正确解析吗?
wangweianger commented 1 year ago

能够解析这种文件,前提是 third-party 中存在 ThirdPartyType 你应该修改为

import { ThirdPartyType } from 'third-party';
type IType = {
  name: string
  property: ThirdPartyType
}

或

interface IType {
  name: string
  property: ThirdPartyType
}

这边暂时未发现有ThirdPartyType类型导出,因此得出的结果为:

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "property": {
      "$ref": "#/definitions/ThirdPartyType"
    }
  },
  "required": [
    "name",
    "property"
  ],
  "additionalProperties": false,
  "definitions": {
    "ThirdPartyType": {}
  }
}