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

Certain names (e.g. those shared by @types/node) are missing from generated schema #539

Open hanvyj opened 1 year ago

hanvyj commented 1 year ago

I have an interface that's just completely missing from my output schema, I've narrowed it down to the name. Here's an example:

export interface Cluster {
  test: string;
}

This produces the schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {}
}

Using any name other than Cluster, say Cluster2 and I get the expected:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "Cluster2": {
      "type": "object",
      "properties": {
        "test": {
          "type": "string"
        }
      },
      "required": [
        "test"
      ]
    }
  }
}

Are there any reserved words or something we can't use? Is this expected? Can I overwrite that behaviour?

hanvyj commented 1 year ago

So the issue is

  if (isUserFile(sourceFile)) {
    userSymbols[name] = symbol;
  }

Hits the following symbols in ...node_modules/@types/node/cluster.d.ts: ClusterSettings Address Worker Cluster

Which, given userSymbols is a map, overwrite the userSymbols["Cluster"], and it's then filtered out by getMainFileSymbols with files.indexOf(node.getSourceFile())