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

annotations will be ignored if use a referred type

Open zhumengyue opened this issue 3 years ago • 1 comments

for example, i have an interface UserInfo whose extra property is another interface, and there are some annotations:

interface AddressInfo {
  /**
   * @default xxx
   */
  address: string;
}

interface UserInfo {
  /**
   * @default xxx
   * @label xxx
   */
  name: string;
  /**
   * some desc ...
   *
   * @label xxx
   */
  extra: AddressInfo
}

when i tried generate schema with TJS.generateSchema(program, "UserInfo", { validationKeywords: [ 'label' ] });, i got: (From https://github.com/YousefED/typescript-json-schema/issues/251 i know that custom annotations should be declared in validationKeyowrds)

{
    "type": "object",
    "properties": {
        "name": {
            "default": "xxx",
            "label": "xxx",
            "type": "string"
        },
        "extra": {
            "$ref": "#/definitions/AddressInfo",
            "description": "some desc ..."
        }
    },
    "required": [
        "extra",
        "name"
    ],
    "definitions": {
        "AddressInfo": {
            "type": "object",
            "properties": {
                "address": {
                    "default": "xxx",
                    "type": "string"
                }
            },
            "required": [
                "address"
            ]
        }
    },
    "$schema": "http://json-schema.org/draft-07/schema#"
}

name has the property default and label,but extra only has description, label is ignored.

Is it a bug or how can i do with that?

zhumengyue avatar Aug 02 '21 07:08 zhumengyue

I have just verified this with the latest version and it is working as expected. Please close the bug.

aniket7824 avatar Mar 11 '24 07:03 aniket7824