Skip to content

Commit 38cb222

Browse files
committed
fix: Fix descrition complex examples render
1 parent 9694680 commit 38cb222

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/includer/traverse/description.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,20 @@ function concatConstraint(
111111
return `${description}\n\n*${constraintLabel}*{.openapi-description-annotation} ${constraint}\n`;
112112
}
113113

114+
function isPrimitive(value: unknown) {
115+
return !value || ['boolean', 'string', 'number'].includes(typeof value);
116+
}
117+
114118
function prepareConstraintValue(value: unknown, notWrapValueIntoCode: boolean) {
115-
return notWrapValueIntoCode ? value : `\`${value}\``;
119+
if (notWrapValueIntoCode) {
120+
return value;
121+
}
122+
123+
if (isPrimitive(value)) {
124+
return '`' + value + '`';
125+
}
126+
127+
return '\n' + ['```', JSON.stringify(value, null, 2), '```'].join('\n');
116128
}
117129

118130
export {fields, prepareComplexDescription};

0 commit comments

Comments
 (0)