From a0285cc953744347943f8214ebbd6df1bbbfac09 Mon Sep 17 00:00:00 2001 From: Andy Gurden <420834+andyrooger@users.noreply.github.com> Date: Sat, 6 Jun 2020 20:33:27 +0100 Subject: [PATCH] Show x-enumNames where available Fixes #59 --- src/object-tree-gen.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/object-tree-gen.js b/src/object-tree-gen.js index 8966ac1..7651e13 100644 --- a/src/object-tree-gen.js +++ b/src/object-tree-gen.js @@ -32,12 +32,12 @@ export function getTypeInfo(schema) { // Set the Type if (schema.enum) { - let opt = ''; - schema.enum.map((v) => { - opt += `${v}, `; - }); + const opt = (schema['x-enumNames'] + ? schema.enum.map((val, idx) => `${val} (${schema['x-enumNames'][idx]})`) + : schema.enum + ).join(', '); info.type = 'enum'; - info.allowedValues = opt.slice(0, -2); + info.allowedValues = opt; } else if (schema.type) { info.type = schema.type; } @@ -47,11 +47,11 @@ export function getTypeInfo(schema) { info.arrayType = `${schema.type} of ${arraySchema.type}`; info.default = arraySchema.default === 0 ? '0 ' : (arraySchema.default ? arraySchema.default : ''); if (arraySchema.enum) { - let opt = ''; - arraySchema.enum.map((v) => { - opt += `${v}, `; - }); - info.allowedValues = opt.slice(0, -2); + const opt = (arraySchema['x-enumNames'] + ? arraySchema.enum.map((val, idx) => `${val} (${arraySchema['x-enumNames'][idx]})`) + : arraySchema.enum + ).join(', '); + info.allowedValues = opt; } } else if (schema.type === 'integer' || schema.type === 'number') { if (schema.minimum !== undefined && schema.maximum !== undefined) {