Skip to content

Commit

Permalink
fix(config): remove system config source (#9875)
Browse files Browse the repository at this point in the history
Refs #5148
  • Loading branch information
glowcloud authored Apr 25, 2024
1 parent 636c352 commit 333e5e3
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 77 deletions.
3 changes: 1 addition & 2 deletions docs/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

### How to configure

Swagger UI accepts configuration parameters in four locations.
Swagger UI accepts configuration parameters in three locations.

From lowest to highest precedence:
- The `swagger-config.yaml` in the project root directory, if it exists, is baked into the application
- configuration object passed as an argument to Swagger UI (`SwaggerUI({ ... })`)
- configuration document fetched from a specified `configUrl`
- configuration items passed as key/value pairs in the URL query string
Expand Down
2 changes: 0 additions & 2 deletions flavors/swagger-ui-react/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ const SwaggerUI = ({
plugins,
spec,
url,
dom_id: null,
domNode: null,
layout,
defaultModelsExpandDepth,
defaultModelRendering,
Expand Down
1 change: 0 additions & 1 deletion src/core/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export { default as inlinePluginOptionsFactorization } from "./factorization/inl
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"
Expand Down
16 changes: 0 additions & 16 deletions src/core/config/sources/system.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/core/config/sources/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const optionsFromURL =
({ url, system }) =>
async (options) => {
if (!url) return {}
if (typeof system.specActions?.getConfigByUrl !== "function") return {}
if (typeof system.configsActions?.getConfigByUrl !== "function") return {}
let resolve
const deferred = new Promise((res) => {
resolve = res
Expand All @@ -17,7 +17,7 @@ const optionsFromURL =
resolve(fetchedOptions)
}

system.specActions.getConfigByUrl(
system.configsActions.getConfigByUrl(
{
url,
loadRemoteConfig: true,
Expand Down
8 changes: 1 addition & 7 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
defaultOptions,
optionsFromQuery,
optionsFromURL,
optionsFromSystem,
optionsFromRuntime,
mergeOptions,
inlinePluginOptionsFactorization,
Expand All @@ -62,18 +61,13 @@ function SwaggerUI(userOptions) {
store.register([mergedOptions.plugins, InlinePlugin])
const system = store.getSystem()

const systemOptions = optionsFromSystem({ system })(mergedOptions)

optionsFromURL({ url: mergedOptions.configUrl, system })(mergedOptions).then(
(urlOptions) => {
const urlOptionsFailedToFetch = urlOptions === null

mergedOptions = SwaggerUI.config.merge(
{},
SwaggerUI.config.defaults,
runtimeOptions,
systemOptions,
userOptions,
mergedOptions,
urlOptions,
queryOptions
)
Expand Down
36 changes: 34 additions & 2 deletions src/core/plugins/configs/actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @prettier
*/
import { parseConfig } from "./fn"

export const UPDATE_CONFIGS = "configs_update"
export const TOGGLE_CONFIGS = "configs_toggle"

Expand All @@ -6,7 +11,7 @@ export function update(configName, configValue) {
return {
type: UPDATE_CONFIGS,
payload: {
[configName]: configValue
[configName]: configValue,
},
}
}
Expand All @@ -19,8 +24,35 @@ export function toggle(configName) {
}
}


// Hook
export const loaded = () => () => {
// noop
}

export const downloadConfig = (req) => (system) => {
const {
fn: { fetch },
} = system

return fetch(req)
}

export const getConfigByUrl = (req, cb) => (system) => {
const { specActions, configsActions } = system

if (req) {
return configsActions.downloadConfig(req).then(next, next)
}

function next(res) {
if (res instanceof Error || res.status >= 400) {
specActions.updateLoadingStatus("failedConfig")
specActions.updateLoadingStatus("failedConfig")
specActions.updateUrl("")
console.error(res.statusText + " " + req.url)
cb(null)
} else {
cb(parseConfig(res.text, system))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import YAML from "js-yaml"

export const parseYamlConfig = (yaml, system) => {
export const parseConfig = (yaml, system) => {
try {
return YAML.load(yaml)
} catch(e) {
Expand Down
14 changes: 0 additions & 14 deletions src/core/plugins/configs/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import yamlConfig from "root/swagger-config.yaml"
import { parseYamlConfig } from "./helpers"
import * as actions from "./actions"
import * as specActions from "./spec-actions"
import * as selectors from "./selectors"
import reducers from "./reducers"

const specSelectors = {
getLocalConfig: () => {
return parseYamlConfig(yamlConfig)
}
}


export default function configsPlugin() {

return {
statePlugins: {
spec: {
actions: specActions,
selectors: specSelectors,
},
configs: {
reducers,
actions,
Expand Down
25 changes: 0 additions & 25 deletions src/core/plugins/configs/spec-actions.js

This file was deleted.

4 changes: 0 additions & 4 deletions swagger-config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/core/plugins/configs/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { downloadConfig } from "core/plugins/configs/spec-actions"
import { downloadConfig } from "core/plugins/configs/actions"

describe("configs plugin - actions", () => {

Expand Down

0 comments on commit 333e5e3

Please sign in to comment.