From ac26c16ca61f155167e6806ca712deccf642ab5e Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Tue, 23 Jan 2018 09:58:44 -0500 Subject: [PATCH] Make sure enum values always contain the default value --- libs/odmOptions.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libs/odmOptions.js b/libs/odmOptions.js index d4ff9bf..fb8b896 100644 --- a/libs/odmOptions.js +++ b/libs/odmOptions.js @@ -95,17 +95,21 @@ module.exports = { } } - if (Array.isArray(values.choices)){ - type = "enum"; - domain = values.choices; - } - - help = help.replace(/\%\(default\)s/g, value); - // In the end, all values must be converted back // to strings (per OpenAPI spec which doesn't allow mixed types) value = String(value); + if (Array.isArray(values.choices)){ + type = "enum"; + domain = values.choices; + + // Make sure that the default value + // is in the list of choices + if (domain.indexOf(value) === -1) domain.unshift(value); + } + + help = help.replace(/\%\(default\)s/g, value); + odmOptions.push({ name, type, value, domain, help });