Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong schema generated for generics #173

Open
rp-work opened this issue Dec 7, 2017 · 4 comments
Open

Wrong schema generated for generics #173

rp-work opened this issue Dec 7, 2017 · 4 comments
Labels

Comments

@rp-work
Copy link

rp-work commented Dec 7, 2017

Hi,
I try to use the tool to generate schema for a generic interface which contains a map.
Here is my strip down interface ts code

interface Base\<dummy\> {
	map: { [key: string]: dummy };
}

interface Test extends Base\<string\> {
}

The tool generates the following schema for type Test

{
    "$ref": "#/definitions/Test",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "definitions": {
        "Test": {
            "properties": {
                "map": {
                    "additionalProperties": {
                        "$ref": "#/definitions/dummy"
                    },
                    "type": "object"
                }
            },
            "type": "object"
        },
        "dummy": {
            "type": "object"
        }
    }
}

I would expect the type of dummy be string instead of object.
Is this a bug ?

@domoritz
Copy link
Collaborator

domoritz commented Dec 7, 2017

Yes, this looks like a bug.

My other project, https://github.com/vega/ts-json-schema-generator, generates the correct schema so you could use that instead.

{
  "$ref": "#/definitions/MyObject",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "MyObject": {
      "additionalProperties": false,
      "properties": {
        "map": {
          "additionalProperties": {
            "type": "string"
          },
          "type": "object"
        }
      },
      "required": [
        "map"
      ],
      "type": "object"
    }
  }
}

@domoritz domoritz added the bug label Dec 7, 2017
@rp-work
Copy link
Author

rp-work commented Dec 7, 2017

Thanks for reply.
I will give the new tool a try.

@kayahr
Copy link
Contributor

kayahr commented May 31, 2019

Unfortunately the ts-json-schema-generator tool has other issues which prevents me from using it at the moment. Any chance to get this issue fixed in the typescript-json-schema tool? Or is this project deprecated and the other tool is the way to go anyway? I'm confused :)

I tried to track down the problem myself but only found out that the magic most likely must be added here: https://github.com/YousefED/typescript-json-schema/blob/master/typescript-json-schema.ts#L773
But I'm a complete noob when it comes to TypeScript internals so I have no idea how to fix this...

@domoritz
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants