Skip to content

Commit 05bf15e

Browse files
Serhii BohoslavskyiSerhii Bohoslavskyi
authored andcommitted
Add deep search in request body
1 parent 9205a06 commit 05bf15e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/utils/common-utils.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ export function pathIsInSearch(searchVal, path) {
5353
return stringToSearch.includes(searchVal);
5454
}
5555

56+
export function joinObjectKeys(obj, resultStr = '') {
57+
if (!obj.properties) {
58+
return '';
59+
}
60+
61+
// We should use a separated string variable in order to exclude next error 'Uncaught RangeError: Invalid string length'
62+
let recursiveresultStr = '';
63+
resultStr = `${resultStr} ${Object.keys(obj.properties || '').join(' ')}`;
64+
65+
Object.keys(obj.properties).forEach((propertyName) => {
66+
if (obj.properties[propertyName].properties) {
67+
recursiveresultStr = `${recursiveresultStr} ${joinObjectKeys(obj.properties[propertyName], resultStr)}`;
68+
}
69+
if (obj.properties[propertyName].type === 'array') {
70+
recursiveresultStr = `${recursiveresultStr} ${joinObjectKeys(obj.properties[propertyName].items, resultStr)}`;
71+
}
72+
});
73+
74+
return `${resultStr} ${recursiveresultStr}`;
75+
}
76+
5677
export function advanceSearch(searchVal, allSpecTags, searchOptions = []) {
5778
if (!searchVal.trim() || searchOptions.length === 0) {
5879
return;
@@ -74,7 +95,7 @@ export function advanceSearch(searchVal, allSpecTags, searchOptions = []) {
7495

7596
if (searchOptions.includes('search-api-request-body') && path.requestBody) {
7697
for (const contentType in path.requestBody.content) {
77-
stringToSearch = `${stringToSearch} ${Object.keys(path.requestBody.content[contentType].schema?.properties || '').join(' ')}`;
98+
stringToSearch = `${stringToSearch} ${joinObjectKeys(path.requestBody.content[contentType].schema, stringToSearch)}`;
7899
}
79100
}
80101

0 commit comments

Comments
 (0)