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

Don't expand defined types #232

Open
schani opened this issue Jul 24, 2018 · 5 comments
Open

Don't expand defined types #232

schani opened this issue Jul 24, 2018 · 5 comments

Comments

@schani
Copy link
Contributor

schani commented Jul 24, 2018

This input will produce a schema where the type Result is not used in Response:

export type Result = { key: string };

export type Response = {
    items: { [name: string]: Result };
};

This is the output:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "Response": {
            "properties": {
                "items": {
                    "additionalProperties": {
                        "properties": {
                            "key": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    },
                    "type": "object"
                }
            },
            "type": "object"
        },
        "Result": {
            "properties": {
                "key": {
                    "type": "string"
                }
            },
            "type": "object"
        }
    }
}

It works with interfaces:

export interface Result { key: string }

export interface Response {
    items: { [name: string]: Result };
}
@HoldYourWaffle
Copy link
Contributor

I'm pretty new to using this library, but wouldn't --aliasRefs solve this issue?

@HoldYourWaffle
Copy link
Contributor

Tested it, this is not fixed by --aliasRefs, although I'm not sure if that's a bug or if --aliasRefs is supposed to do something else.

@domoritz
Copy link
Collaborator

aliasRefs only somewhat works with the approach in this library.

@HoldYourWaffle
Copy link
Contributor

Yeah I noticed that... One of the main reasons why I think we should switch to the AST approach (vega/ts-json-schema-generator#101)

@domoritz
Copy link
Collaborator

Yep, that's why I switched to the different approach for Vega-Lite.

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

No branches or pull requests

3 participants