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

description in oneOf

Open dakom opened this issue 3 years ago • 1 comments

I have something like this:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "QueryMsg",
  "oneOf": [
    {
      "description": "This is variant 1",
      "type": "object",
      "required": [
        "kind"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "variant_1"
          ]
        }
      }
    },
    {
      "description": "This is variant 2",
      "type": "object",
      "required": [
        "kind"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "variant_2"
          ]
        }
      }
    }
  ]
}

and it turns it into the following:

export type QueryMsg =
  | {
      kind: "variant 1";
      [k: string]: unknown;
    }
  | {
      kind: "variant 0";
      [k: string]: unknown;
    };

Which is cool - but the descriptions are lost, i.e. no comments are generated for the variants

is there a way to make it preserve the comments somehow?

dakom avatar Nov 10 '21 13:11 dakom

This would be very nice if it was fixed.

It is also problem with arrays.

        test: {
            type: 'object',
            properties: {
                testArr: {
                    type: 'array',
                    items: {
                        description: 'some very important description',
                        type: 'string',
                    }
                }
            }
        }

Turns into:

test?: {
        testArr?: string[];
        [k: string]: unknown;
};

Description on string item inside testArr is lost.

psznm avatar May 04 '22 16:05 psznm