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

`constAsEnum` not aways working in combination with `strictNullChecks`

Open robaca opened this issue 1 year ago • 2 comments

The following example still in one case generates const instead of enum:

type A = B | C

interface B {
    myProp?: false
}

interface C {
    myProp: true
}

When generating the schema like this:

typescript-json-schema --constAsEnum --strictNullChecks test.ts A

The outcome is:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "anyOf": [
        {
            "$ref": "#/definitions/B"
        },
        {
            "$ref": "#/definitions/C"
        }
    ],
    "definitions": {
        "B": {
            "properties": {
                "myProp": {
                    "const": false,
                    "type": "boolean"
                }
            },
            "type": "object"
        },
        "C": {
            "properties": {
                "myProp": {
                    "enum": [
                        true
                    ],
                    "type": "boolean"
                }
            },
            "type": "object"
        }
    }
}

robaca avatar Jan 15 '24 10:01 robaca

@domoritz do you still maintain this package? Any thoughts about this problem?

ruettenm avatar Mar 18 '24 06:03 ruettenm

I don't use it anymore but merge PRs and make releases. I don't have time to triage or fix issues.

domoritz avatar Mar 18 '24 13:03 domoritz