Skip to content

Commit

Permalink
fix(docs): Added support for enums ZMS-104 (#565)
Browse files Browse the repository at this point in the history
* query params add support for enums and example

* add general enum and example support for requestBody as well
  • Loading branch information
NickOvt authored Nov 30, 2023
1 parent 3c9e175 commit 28bdc76
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 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 Expand Up @@ -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);
}

Expand Down

0 comments on commit 28bdc76

Please sign in to comment.