Skip to content

Commit

Permalink
fix: support enums with single value (#33) (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
mankdev authored Jul 27, 2019
1 parent 312caf6 commit 98000b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/language/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ const serializeSchemaObject = (schema: TSchemaObject, rootName: string, cwd: str

const serializeEnum = (enumValue: Array<string | number | boolean>): TSerializedType => {
const type = enumValue.map(value => `'${value}'`).join(' | ');
const io = `union([${enumValue.map(value => `literal('${value}')`).join(',')}])`;
const io =
enumValue.length === 1
? `literal(${type})`
: `union([${enumValue.map(value => `literal('${value}')`).join(',')}])`;
return serializedType(type, io, [dependency('union', 'io-ts'), dependency('literal', 'io-ts')], EMPTY_REFS);
};

Expand Down
5 changes: 5 additions & 0 deletions test/specs/json/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"delivered"
]
},
"state" : {
"type" : "string",
"description" : "order state",
"enum" : [ "ACTIVE" ]
},
"complete": {
"type": "boolean",
"default": false
Expand Down

0 comments on commit 98000b4

Please sign in to comment.