typescript-json-schema icon indicating copy to clipboard operation
typescript-json-schema copied to clipboard

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

Open hanvyj opened this issue 1 year ago • 1 comments

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 avatar May 04 '23 14:05 hanvyj

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())

hanvyj avatar May 04 '23 15:05 hanvyj