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

Mapped-type creating redundant intermediary definition (--aliasRefs) #293

Open
HoldYourWaffle opened this issue May 31, 2019 · 2 comments
Open

Comments

@HoldYourWaffle
Copy link
Contributor

Possibly related to #232, although this seems more complicated than that.

Given the following TypeScript:

enum MyEnum { MY, AWESOME, ENUM }
type MappedType = { [key in MyEnum]?: string };

interface Type {
	map: MappedType;
}

The following schema is generated (with --aliasRefs):

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "MappedType": {
            "$ref": "#/definitions/__type"
        },
        "__type": {
            "properties": {
                "0": {
                    "type": "string"
                },
                "1": {
                    "type": "string"
                },
                "2": {
                    "type": "string"
                }
            },
            "type": "object"
        }
    },
    "properties": {
        "map": {
            "$ref": "#/definitions/MappedType"
        }
    },
    "type": "object"
}

As you can see there's a "intermediary" (and very much redundant) definitions created for the mapped type (__type). The actual MappedType definition references this definition.
No seperate enum definition is created, which makes sense because it's never truly referenced. If I do create an explicit reference the enum is generated correctly.

@HoldYourWaffle
Copy link
Contributor Author

HoldYourWaffle commented May 31, 2019

It should also be noted that type aliases used in the mapped type aren't preserved either, the following TypeScript results in the same schema as in the initial comment:

/** @minLength 1 */
type Word = string;

enum MyEnum { MY, AWESOME, ENUM }
type MappedType = { [key in MyEnum]?: Word };

interface Type {
	map: MappedType;
}

Should I create a separate issue for this?

@HoldYourWaffle
Copy link
Contributor Author

This might be related to vega/ts-json-schema-generator#30.

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

1 participant