mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-09 14:44:51 +03:00
Also added sub fields to search index
This commit is contained in:
parent
afc7e36cf8
commit
e041095102
|
@ -1,3 +1,4 @@
|
||||||
|
import { chain } from 'lodash';
|
||||||
import { IS_BROWSER } from '../utils/';
|
import { IS_BROWSER } from '../utils/';
|
||||||
import { IMenuItem } from './MenuStore';
|
import { IMenuItem } from './MenuStore';
|
||||||
import { OperationModel } from './models';
|
import { OperationModel } from './models';
|
||||||
|
@ -25,6 +26,38 @@ export class SearchStore<T> {
|
||||||
items.forEach(group => {
|
items.forEach(group => {
|
||||||
if (group.type !== 'group') {
|
if (group.type !== 'group') {
|
||||||
this.add(group.name, group.description || '', group.id);
|
this.add(group.name, group.description || '', group.id);
|
||||||
|
if (group.type === 'operation') {
|
||||||
|
const addDeepFields = (arr, duplicates) => {
|
||||||
|
arr.forEach(field => {
|
||||||
|
if (field.schema.fields !== undefined) { addDeepFields(field.schema.fields, duplicates); }
|
||||||
|
if (field.schema.items !== undefined && field.schema.items.fields !== undefined) { addDeepFields(field.schema.items.fields, duplicates); }
|
||||||
|
if (!duplicates.includes(field.name)) {
|
||||||
|
this.add(field.name, field.description || '', group.id);
|
||||||
|
duplicates.push(field.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (group.responses !== undefined) {
|
||||||
|
let responses = group.responses;
|
||||||
|
const headers = chain(responses).flatMap('headers').compact().value();
|
||||||
|
addDeepFields(headers, []);
|
||||||
|
responses = chain(responses).flatMap('content').flatMap('mediaTypes').flatMap('schema').flatMap('fields').compact().value();
|
||||||
|
addDeepFields(responses, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (group.parameters !== undefined) {
|
||||||
|
const parameters = group.parameters;
|
||||||
|
addDeepFields(parameters, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (group.requestBody !== undefined) {
|
||||||
|
const body = group.requestBody;
|
||||||
|
let bodies = chain(body.content.mediaTypes).flatMap('schema').flatMap('fields').value();
|
||||||
|
if (bodies[0] === undefined) { bodies = chain(body.content.mediaTypes).flatMap('schema').flatMap('oneOf').flatMap('fields').compact().value(); }
|
||||||
|
addDeepFields(bodies, []);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
recurse(group.items);
|
recurse(group.items);
|
||||||
});
|
});
|
||||||
|
|
|
@ -49,7 +49,7 @@ builder.pipeline.add(lunr.trimmer, lunr.stopWordFilter, lunr.stemmer);
|
||||||
const expandTerm = term => '*' + lunr.stemmer(new lunr.Token(term, {})) + '*';
|
const expandTerm = term => '*' + lunr.stemmer(new lunr.Token(term, {})) + '*';
|
||||||
|
|
||||||
export function add<T>(title: string, description: string, meta?: T) {
|
export function add<T>(title: string, description: string, meta?: T) {
|
||||||
const ref = store.push(meta) - 1;
|
const ref = store.indexOf(meta) === -1 ? store.push(meta) - 1 : store.indexOf(meta);
|
||||||
const item = { title: title.toLowerCase(), description: description.toLowerCase(), ref };
|
const item = { title: title.toLowerCase(), description: description.toLowerCase(), ref };
|
||||||
builder.add(item);
|
builder.add(item);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user