Skip to content

Commit b631564

Browse files
committed
advance search - schema keys generated using set() to avoid duplicates
1 parent 9dbeefa commit b631564

File tree

8 files changed

+43
-35
lines changed

8 files changed

+43
-35
lines changed

dist/rapidoc-min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rapidoc-min.js.gz

114 Bytes
Binary file not shown.

dist/rapidoc-min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rapidoc-min.js.map.gz

0 Bytes
Binary file not shown.

dist/report.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/rapidoc-min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/specs/data-types.yaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ info:
44
version: 1.0.0
55
title: Testing different data-types
66
paths:
7+
/nested-object-in-request-body:
8+
post:
9+
summary: Request body accepting a JSON
10+
requestBody:
11+
content:
12+
application/json:
13+
schema:
14+
$ref: "#/components/schemas/Person"
715
/nested-object:
816
get:
917
summary: Response schema made of nested objects.
@@ -173,7 +181,7 @@ components:
173181
Category:
174182
type: object
175183
properties:
176-
id:
184+
catId:
177185
description: Category ID
178186
allOf:
179187
- $ref: '#/components/schemas/Id'
@@ -199,7 +207,7 @@ components:
199207
description: Categories this person belongs to
200208
allOf:
201209
- $ref: '#/components/schemas/Category'
202-
DependentIds:
210+
dependentIds:
203211
type: array
204212
description: IDs of Dependents .
205213
items:
@@ -250,4 +258,6 @@ components:
250258
name:
251259
description: Tag name
252260
type: string
253-
minLength: 1
261+
minLength: 1
262+
fff:
263+
type: string

src/utils/common-utils.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,30 @@ export function pathIsInSearch(searchVal, path) {
5353
return stringToSearch.includes(searchVal);
5454
}
5555

56-
export function joinObjectKeys(obj, resultStr = '') {
57-
if (!obj.properties) {
58-
return '';
56+
export function schemaKeys(schemaProps, result = new Set()) {
57+
if (!schemaProps) {
58+
return result;
5959
}
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)}`;
60+
Object.keys(schemaProps).forEach((key) => {
61+
result.add(key);
62+
if (schemaProps[key].properties) {
63+
schemaKeys(schemaProps[key].properties, result);
64+
} else if (schemaProps[key].items?.properties) {
65+
schemaKeys(schemaProps[key].items?.properties, result);
7166
}
7267
});
73-
74-
return `${resultStr} ${recursiveresultStr}`;
68+
return result;
7569
}
7670

7771
export function advanceSearch(searchVal, allSpecTags, searchOptions = []) {
7872
if (!searchVal.trim() || searchOptions.length === 0) {
7973
return;
8074
}
8175

82-
let stringToSearch = '';
8376
const pathsMatched = [];
8477
allSpecTags.forEach((tag) => {
8578
tag.paths.forEach((path) => {
79+
let stringToSearch = '';
8680
if (searchOptions.includes('search-api-path')) {
8781
stringToSearch = path.path;
8882
}
@@ -94,8 +88,12 @@ export function advanceSearch(searchVal, allSpecTags, searchOptions = []) {
9488
}
9589

9690
if (searchOptions.includes('search-api-request-body') && path.requestBody) {
97-
for (const contentType in path.requestBody.content) {
98-
stringToSearch = `${stringToSearch} ${joinObjectKeys(path.requestBody.content[contentType].schema, stringToSearch)}`;
91+
let schemaKeySet = new Set();
92+
for (const contentType in path.requestBody?.content) {
93+
if (path.requestBody.content[contentType].schema?.properties) {
94+
schemaKeySet = schemaKeys(path.requestBody.content[contentType].schema?.properties);
95+
}
96+
stringToSearch = `${stringToSearch} ${[...schemaKeySet].join(' ')}`;
9997
}
10098
}
10199

0 commit comments

Comments
 (0)