Skip to content

How to generate string enums #44

@zengfenfei

Description

@zengfenfei

I'm using react-jsonschema-form to generate UI with the schema generated by typson.

Current generated schema for:

export enum CallDirection {
	Inbound,
	Outbound
}

is :

{
	"id": "CallDirection",
	"enum": [
		"Inbound",
		"Outbound"
	]
}

There is no type property in the generated schema. But react-jsonschema-form requires a type property to render the UI.

So I try to define the string enums like this:

type CallDirection = "Inbound" | "Outbound";

But typson will report error:

lib/Config.ts(10,1): error TS1008: Unexpected token; 'module, class, interface, enum, import or statement' expected.
lib/Config.ts(10,13): error TS1005: ';' expected.

/Users/kevin.zeng/.config/yarn/global/node_modules/q/q.js:126
                    throw e;

I also try to add the type property by annotation, but it doesnot work:

/**
 * @type string
 */
export enum CallDirection {
	Inbound,
	Outbound
}

Is there any suggestions for me to generate string enums with default values, like:

{
	"id": "CallDirection",
	"type": "string",
	"enum": [
		"Inbound",
		"Outbound"
	],
	"default": "Outbound"
}

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions