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

How to generate string enums #44

Open
zengfenfei opened this issue Mar 27, 2017 · 0 comments
Open

How to generate string enums #44

zengfenfei opened this issue Mar 27, 2017 · 0 comments

Comments

@zengfenfei
Copy link

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.

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

No branches or pull requests

1 participant