Skip to content

Union with string and false creates wrong output #2207

Closed
@pixunil

Description

@pixunil

Hello,

I think I discovered a regression defect when upgrading from 1.5.0 to 2.3.0.

Given following minimal example:

export interface Example {
    property: string | false;
}

I get:

{
  "$ref": "#/definitions/Example",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "Example": {
      "additionalProperties": false,
      "properties": {
        "property": {
          "enum": [
            false
          ],
          "type": "boolean"
        }
      },
      "required": [
        "property"
      ],
      "type": "object"
    }
  }
}

Where I would expect:

{
  "$ref": "#/definitions/Example",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "Example": {
      "additionalProperties": false,
      "properties": {
        "property": {
            "anyOf": [
                {
                    "type": "string"
                },
                {
                    "type": "boolean",
                    "const": false
                }
            ],
        }
      },
      "required": [
        "property"
      ],
      "type": "object"
    }
  }
}

Interestingly, unions like number | false and string[] | false work fine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions