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

Classes with default values are added to 'required' array #502

Open morgante opened 2 years ago

morgante commented 2 years ago

When a property has a default value, it should not be added to the required array.

This comes up in classes. For example, this TypeScript

class Test {
  enabled = true;
}

Generates this schema:

    "Test": {
      "additionalProperties": false,
      "properties": {
        "enabled": {
          "default": true,
          "type": "boolean"
        },
      },
      "required": ["enabled"],
      "type": "object"
    }
ahochsteger commented 1 year ago

I have the same requirement and expected properties with default values not be required. Any chance, that may be solved?