ts-json-schema-generator icon indicating copy to clipboard operation
ts-json-schema-generator copied to clipboard

Required<T> types do not generate required properties

Open mdesousa opened this issue 2 years ago • 0 comments

Define two types as follows:

export type MyType = {
  prop1?: string
  prop2?: string
}

export type MyRequiredType = Required<MyType>

Expected to see the json schema generated to show prop1 and prop2 listed as required for MyRequiredType However, they are not:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "MyType": {
      "type": "object",
      "properties": {
        "prop1": {
          "type": "string"
        },
        "prop2": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "MyRequiredType": {
      "type": "object",
      "properties": {
        "prop1": {
          "type": "string"
        },
        "prop2": {
          "type": "string"
        }
      },
      "additionalProperties": false
    }
  }
}

mdesousa avatar Sep 11 '21 22:09 mdesousa