YousefED / typescript-json-schema

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

annotations will be ignored if use a referred type #431

Open zhumengyue opened 2 years ago

zhumengyue commented 2 years ago

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?

aniket7824 commented 3 months ago

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