diff --git a/lib/tools.js b/lib/tools.js index fb96ce57..f71aafcc 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -767,6 +767,24 @@ function parseJoiObject(path, joiObject, requestBodyProperties) { data.format = format; } + // enum check + if (joiObject._valids) { + const enumValues = []; + for (const validEnumValue of joiObject._valids._values) { + enumValues.push(validEnumValue); + } + if (enumValues.length > 0) { + data.enum = enumValues; + } + } + + // example check + if (joiObject.$_terms && joiObject.$_terms.examples && joiObject.$_terms.examples.length > 0) { + const example = joiObject.$_terms.examples[0]; + + data.example = example; + } + if (path) { requestBodyProperties[path] = data; } else if (Array.isArray(requestBodyProperties)) { @@ -997,6 +1015,25 @@ module.exports = { obj.description = paramKeyData._flags.description; obj.required = paramKeyData._flags.presence === 'required'; obj.schema = { type: paramKeyData.type }; + + // enum check + if (paramKeyData._valids) { + const enumValues = []; + for (const validEnumValue of paramKeyData._valids._values) { + enumValues.push(validEnumValue); + } + if (enumValues.length > 0) { + obj.schema.enum = enumValues; + } + } + + // example check + if (paramKeyData.$_terms && paramKeyData.$_terms.examples && paramKeyData.$_terms.examples.length > 0) { + const example = paramKeyData.$_terms.examples[0]; + + obj.schema.example = example; + } + operationObj.parameters.push(obj); }