Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nicer schema for string literals + string #20

Closed
domoritz opened this issue Nov 6, 2017 · 0 comments
Closed

Nicer schema for string literals + string #20

domoritz opened this issue Nov 6, 2017 · 0 comments

Comments

@domoritz
Copy link
Member

domoritz commented Nov 6, 2017

I believe this only requires minor changes in https://github.com/vega/ts-json-schema-generator/blob/master/src/TypeFormatter/EnumTypeFormatter.ts.

export interface MyObject {
    bar: "ok" | "fail" | "abort" | string;
}

produces

> [email protected] run /Users/domoritz/Developer/UW/ts-json-schema-generator
> ts-node ts-json-schema-generator.ts "--path" "test.ts" "--type" "MyObject"

{
  "$ref": "#/definitions/MyObject",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "MyObject": {
      "additionalProperties": false,
      "properties": {
        "bar": {
          "anyOf": [
            {
              "enum": [
                "ok"
              ],
              "type": "string"
            },
            {
              "enum": [
                "fail"
              ],
              "type": "string"
            },
            {
              "enum": [
                "abort"
              ],
              "type": "string"
            },
            {
              "type": "string"
            }
          ]
        }
      },
      "required": [
        "bar"
      ],
      "type": "object"
    }
  }
}

The enums could be consolidated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant