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

use anyof for unions with type and consts

Open lublak opened this issue 2 years ago • 5 comments

sometimes i write some default values in typescript:

dpi?:number|72|96;

which should generate:

"dpi": {
    "anyOf": [
        {
            "type": "number"
        },
        {
            "type": "number",
            "enum": [
                72,
                96
            ]
        }
    ]
},

currently it only generates:

"dpi": {
    "type": "number"
},

lublak avatar Apr 24 '23 11:04 lublak

https://github.com/YousefED/typescript-json-schema/blob/master/typescript-json-schema.ts#L936

@domoritz should i create a flag for this? (not default) useAnyOfEnum

lublak avatar Apr 24 '23 12:04 lublak

That would be great. Your flag sounds good as there are more cases beyond numbers (e.g. string, boolean) that should also be supported.

domoritz avatar Apr 24 '23 12:04 domoritz

@domoritz how can i add tests only with this flag? Currently i see no options for this.

lublak avatar Apr 24 '23 13:04 lublak

You need to add the flag to the options and pass that into the test case you add.

domoritz avatar Apr 24 '23 13:04 domoritz

@domoritz i found out: Typescript dont use this values: grafik so the only solutions would be a comment:

/**
 * @anyOfEnum number|96|72
*/

or something like this?

/**
 * @type number|96|72
*/

lublak avatar Apr 25 '23 12:04 lublak