Skip to content

Commit

Permalink
Aff API filter
Browse files Browse the repository at this point in the history
  • Loading branch information
fdaugan committed Feb 24, 2024
1 parent 415f3f5 commit 38043a7
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions src/main/resources/META-INF/resources/webjars/api/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,64 @@
* Licensed under MIT (https://github.com/ligoj/ligoj/blob/master/LICENSE)
*/
define(["../../../rest/swagger-ui-bundle.js","../../../rest/swagger-ui-standalone-preset.js"], function(SwaggerUIBundle,SwaggerUIStandalonePreset) {
return {
const AdvancedFilterPlugin = function (system) {
return {
fn: {
opsFilter: function (taggedOps, phrase) {
phrase = phrase.toLowerCase()
//first filter out all actions that don't meet the search criteria
var filteredActions = taggedOps.map((tagObj) => {
tagObj._root.entries[1][1] = tagObj._root.entries[1][1].filter((operationObj) => {
var op = JSON.parse(JSON.stringify(operationObj));
var summary = "";
var description = "";
if (typeof op.operation.summary !== 'undefined') {
summary = JSON.stringify(op.operation.summary).toLowerCase();
}
if (typeof op.operation.description !== 'undefined') {
description = JSON.stringify(op.operation.description).toLowerCase();
}
if ((op.path.toLowerCase().indexOf(phrase) === -1)
&& (summary.indexOf(phrase) === -1)
&& (description.indexOf(phrase) === -1)
) {
return false;
} else {
return true;
}
});
return tagObj;
});
//then filter any Tags with no actions remaining
return filteredActions.filter((tagObj) => {
return (tagObj._root.entries[1][1].size > 0);
});
}
}
};
};
return {

initialize: function () {
window.SwaggerTranslator;
$(function(){
// Build a system
const ui = SwaggerUIBundle({
url: "rest/openapi.json",
dom_id: '#swagger-ui',
defaultModelsExpandDepth: -1,
displayRequestDuration: true,
deepLinking: false,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
SwaggerUIBundle.plugins.FiltrePreset,
AdvancedFilterPlugin
],
layout: "StandaloneLayout"
filter: true,
layout: "StandaloneLayout",
validatorUrl: "https://validator.swagger.io/validator",
})
window.ui = ui
})
Expand Down

0 comments on commit 38043a7

Please sign in to comment.