From dc9650b80bb3f1ff029eebbe3316cc7440d1f3b9 Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Thu, 18 Apr 2024 14:35:50 +0200 Subject: [PATCH] fix(config): address getting configUrl from options (#9840) Refs #9819 --- src/core/config/defaults.js | 1 + src/core/config/sources/query.js | 5 ++++- src/core/config/type-cast/mappings.js | 2 +- src/core/index.js | 3 +-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/config/defaults.js b/src/core/config/defaults.js index 19c2a0a080b..ef2daf7db41 100644 --- a/src/core/config/defaults.js +++ b/src/core/config/defaults.js @@ -9,6 +9,7 @@ const defaultOptions = Object.freeze({ spec: {}, url: "", urls: null, + configUrl: null, layout: "BaseLayout", docExpansion: "list", maxDisplayedTags: -1, diff --git a/src/core/config/sources/query.js b/src/core/config/sources/query.js index 805c745c194..6ed14ba3d69 100644 --- a/src/core/config/sources/query.js +++ b/src/core/config/sources/query.js @@ -13,7 +13,10 @@ const optionsFromQuery = () => (options) => { const urlSearchParams = options.queryConfigEnabled ? parseSearch() : {} return Object.entries(urlSearchParams).reduce((acc, [key, value]) => { - if (key === "urls.primaryName") { + // TODO(oliwia.rogala@smartbear.com): drop support for `config` in the next major release + if (key === "config") { + acc["configUrl"] = value + } else if (key === "urls.primaryName") { acc[key] = value } else { acc = set(acc, key, value) diff --git a/src/core/config/type-cast/mappings.js b/src/core/config/type-cast/mappings.js index 30ef5e3dfd5..8ece1d2f994 100644 --- a/src/core/config/type-cast/mappings.js +++ b/src/core/config/type-cast/mappings.js @@ -15,7 +15,7 @@ import undefinedStringTypeCaster from "./type-casters/undefined-string" import defaultOptions from "../defaults" const typeCasters = { - configUrl: { typeCaster: stringTypeCaster }, + configUrl: { typeCaster: nullableStringTypeCaster }, deepLinking: { typeCaster: booleanTypeCaster, defaultValue: defaultOptions.deepLinking, diff --git a/src/core/index.js b/src/core/index.js index a46ec629799..1cc4ac493f1 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -51,10 +51,9 @@ export default function SwaggerUI(userOptions) { store.register([mergedOptions.plugins, InlinePlugin]) const system = store.getSystem() - const configURL = queryOptions.config ?? mergedOptions.configUrl const systemOptions = optionsFromSystem({ system })(mergedOptions) - optionsFromURL({ url: configURL, system })(mergedOptions) + optionsFromURL({ url: mergedOptions.configUrl, system })(mergedOptions) .then((urlOptions) => { const urlOptionsFailedToFetch = urlOptions === null