quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

Support Typescript extends while converting to JSONSchema

Open abhishiv opened this issue 6 years ago • 0 comments

Hey guys

interface Statement {
  [key: string]: any;
}
interface Declaration {
  [key: string]: any;
}

export interface VariableDeclaration extends Statement, Declaration {
  attributes: {
    kind: "let" | "const" | "var";
  };
}

Produces this output

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "Statement": {
            "title": "Statement",
            "type": "object",
            "additionalProperties": {}
        },
        "Declaration": {
            "title": "Declaration",
            "type": "object",
            "additionalProperties": {}
        },
        "VariableDeclaration": {
            "title": "VariableDeclaration",
            "type": "object",
            "properties": {
                "attributes": {
                    "type": "object",
                    "properties": {
                        "kind": {
                            "enum": [
                                "const",
                                "let",
                                "var"
                            ],
                            "type": "string",
                            "title": "kind"
                        }
                    },
                    "required": [
                        "kind"
                    ],
                    "title": "attributes"
                }
            },
            "required": [
                "attributes"
            ]
        }
    }
}

https://app.quicktype.io?share=5zNZSMfizoUwqZGplo7i

My understanding is that inheritance can be expressed in JSonSchema with $allOf. Would be really great for quicktype to support this.

Edit1: updated example

abhishiv avatar Dec 21 '18 15:12 abhishiv