Skip to content

[FEATURE]: Enum for non string types #2814

@jabdinghoff

Description

@jabdinghoff

An enum that is not of type string currently just gets turned into that type. I would love if these would also get turned into proper enums

Context

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "type": "object",
  "properties": {
    "foo": {
      "type": "number",
      "enum": [0,1,2,3]
    },
    "bar": {
      "type": "string",
      "enum": ["0","1", "2", "3"]
    }
  }
}

Input Format: schema
Output Language: typescript

Description

I have a lot of data that uses integers to represent different states, I would love if quicktype would also support this jsonschema feature.

Current Behaviour / Output

export interface FooSchema {
    bar?: Bar;
    foo?: number;
    [property: string]: any;
}

export enum Bar {
    The0 = "0",
    The1 = "1",
    The2 = "2",
    The3 = "3",
}

Proposed Behaviour / Output

export interface FooSchema {
    bar?: Bar;
    foo?: Foo;
    [property: string]: any;
}

export enum Foo {
    The0 = 0,
    The1 = 1,
    The2 = 2,
    The3 = 3,
}

export enum Bar {
    The0 = "0",
    The1 = "1",
    The2 = "2",
    The3 = "3",
}

And similarly for other languages

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions