From 53986d60bc7123c2fa9ed436a525cb82cb2ba528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Mendiara=20Ca=C3=B1ardo?= Date: Tue, 9 May 2017 15:06:15 +0200 Subject: [PATCH] Move filterConfigs to core Fixes #3056 --- src/core/index.js | 9 ++++++--- src/core/utils.js | 12 ++++++++++++ src/plugins/configs/index.js | 17 ----------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/core/index.js b/src/core/index.js index daef011106d..913078e6b2f 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -4,8 +4,11 @@ import System from "core/system" import win from "core/window" import ApisPreset from "core/presets/apis" import * as AllPlugins from "core/plugins/all" -import { filterConfigs } from "plugins/configs" -import { parseSeach } from "core/utils" +import { parseSeach, filterConfigs } from "core/utils" + +const CONFIGS = [ "url", "spec", "validatorUrl", "onComplete", "onFailure", "authorizations", "docExpansion", + "apisSorter", "operationsSorter", "supportedSubmitMethods", "highlightSizeThreshold", "dom_id", + "defaultModelRendering", "oauth2RedirectUrl", "showRequestHeaders" ] // eslint-disable-next-line no-undef const { GIT_DIRTY, GIT_COMMIT, PACKAGE_VERSION } = buildInfo @@ -82,7 +85,7 @@ module.exports = function SwaggerUI(opts) { let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {} let mergedConfig = deepExtend({}, localConfig, constructorConfig, fetchedConfig || {}, queryConfig) - store.setConfigs(filterConfigs(mergedConfig)) + store.setConfigs(filterConfigs(mergedConfig, CONFIGS)) if (fetchedConfig !== null) { if (!queryConfig.url && typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) { diff --git a/src/core/utils.js b/src/core/utils.js index 7b98d037565..ecb53ad7c22 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -577,3 +577,15 @@ export const buildFormData = (data) => { } return formArr.join("&") } + +export const filterConfigs = (configs, allowed) => { + let i, filteredConfigs = {} + + for (i in configs) { + if (allowed.indexOf(i) !== -1) { + filteredConfigs[i] = configs[i] + } + } + + return filteredConfigs +} diff --git a/src/plugins/configs/index.js b/src/plugins/configs/index.js index a3560be1335..2269d873ee1 100644 --- a/src/plugins/configs/index.js +++ b/src/plugins/configs/index.js @@ -1,10 +1,6 @@ import YAML from "js-yaml" import yamlConfig from "../../../swagger-config.yaml" -const CONFIGS = [ "url", "spec", "validatorUrl", "onComplete", "onFailure", "authorizations", "docExpansion", - "apisSorter", "operationsSorter", "supportedSubmitMethods", "highlightSizeThreshold", "dom_id", - "defaultModelRendering", "oauth2RedirectUrl", "showRequestHeaders" ] - const parseYamlConfig = (yaml, system) => { try { return YAML.safeLoad(yaml) @@ -58,16 +54,3 @@ export default function configPlugin (toolbox) { } } } - - -export function filterConfigs (configs) { - let i, filteredConfigs = {} - - for (i in configs) { - if (CONFIGS.indexOf(i) !== -1) { - filteredConfigs[i] = configs[i] - } - } - - return filteredConfigs -}