Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): add options defined during runtime #9845

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const defaultOptions = Object.freeze({
maxDisplayedTags: -1,
filter: false,
validatorUrl: "https://validator.swagger.io/validator",
oauth2RedirectUrl: `${window.location.protocol}//${window.location.host}${window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"))}/oauth2-redirect.html`,
oauth2RedirectUrl: undefined,
persistAuthorization: false,
configs: {},
custom: {},
Expand Down
1 change: 1 addition & 0 deletions src/core/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export { default as storeOptionsFactorization } from "./factorization/store"
export { default as optionsFromQuery } from "./sources/query"
export { default as optionsFromURL } from "./sources/url"
export { default as optionsFromSystem } from "./sources/system"
export { default as optionsFromRuntime } from "./sources/runtime"
export { default as defaultOptions } from "./defaults"
export { default as mergeOptions } from "./merge"
15 changes: 15 additions & 0 deletions src/core/config/sources/runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @prettier
*
* Receives options at runtime.
*/

const optionsFromRuntime = () => () => {
const options = {
char0n marked this conversation as resolved.
Show resolved Hide resolved
oauth2RedirectUrl: `${window.location.protocol}//${window.location.host}${window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"))}/oauth2-redirect.html`,
}

return options
}

export default optionsFromRuntime
6 changes: 4 additions & 2 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
optionsFromQuery,
optionsFromURL,
optionsFromSystem,
optionsFromRuntime,
mergeOptions,
inlinePluginOptionsFactorization,
storeOptionsFactorization
Expand All @@ -42,7 +43,8 @@ import {

export default function SwaggerUI(userOptions) {
const queryOptions = optionsFromQuery()(userOptions)
let mergedOptions = mergeOptions({}, defaultOptions, userOptions, queryOptions)
const runtimeOptions = optionsFromRuntime()()
let mergedOptions = mergeOptions({}, defaultOptions, runtimeOptions, userOptions, queryOptions)
const storeOptions = storeOptionsFactorization(mergedOptions)
const InlinePlugin = inlinePluginOptionsFactorization(mergedOptions)

Expand All @@ -57,7 +59,7 @@ export default function SwaggerUI(userOptions) {
.then((urlOptions) => {
const urlOptionsFailedToFetch = urlOptions === null

mergedOptions = mergeOptions({}, defaultOptions, systemOptions, userOptions, urlOptions, queryOptions)
mergedOptions = mergeOptions({}, defaultOptions, runtimeOptions, systemOptions, userOptions, urlOptions, queryOptions)
store.setConfigs(mergedOptions)
system.configsActions.loaded()

Expand Down