Skip to content

Commit

Permalink
add general enum and example support for requestBody as well
Browse files Browse the repository at this point in the history
  • Loading branch information
NickOvt committed Nov 27, 2023
1 parent 977bfc1 commit 4cdac2c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 4cdac2c

Please sign in to comment.