YousefED / typescript-json-schema

Generate json-schema from your Typescript sources
BSD 3-Clause "New" or "Revised" License
3.17k stars 323 forks source link

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

Open robaca opened 10 months ago

robaca commented 10 months ago

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"
        }
    }
}
ruettenm commented 8 months ago

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

domoritz commented 8 months ago

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