Skip to content

When all keys is [enum] - whole "properties" is empty #344

Open
@mixalbl4-127

Description

@mixalbl4-127
$(npm bin)/typescript-json-schema --version
0.42.0

ITest.ts

declare enum ButtonType {
    PRIMARY = "PRIMARY",
    SECONDARY = "SECONDARY"
}

export interface ITest {
    button: {
        [ButtonType.PRIMARY]: {
            click: string;
        };
        [ButtonType.SECONDARY]: {
            click: string;
        };
    };
}
$(npm bin)/typescript-json-schema --noExtraProps src/interfaces/ITest.ts ITest
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "additionalProperties": false,
    "properties": {
        "button": {
            "properties": {
            },
            "type": "object"
        }
    },
    "type": "object"
}

button is empty

But when I add at least 1 string name - it works fine. Example:

declare enum ButtonType {
    PRIMARY = "PRIMARY",
    SECONDARY = "SECONDARY"
}

export interface ITest {
    button: {
        [ButtonType.PRIMARY]: {
            click: string;
        };
        [ButtonType.SECONDARY]: {
            click: string;
        };
        z: string;
    };
}
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "additionalProperties": false,
    "properties": {
        "button": {
            "additionalProperties": false,
            "properties": {
                "PRIMARY": {
                    "additionalProperties": false,
                    "properties": {
                        "click": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "SECONDARY": {
                    "additionalProperties": false,
                    "properties": {
                        "click": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "z": {
                    "type": "string"
                }
            },
            "type": "object"
        }
    },
    "type": "object"
}

I think there is a bug when "all names is from variabled (enum)".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions