feat(config): expose config and make it overridable (#9862)
This commit is contained in:
@@ -10,3 +10,4 @@ export { default as optionsFromRuntime } from "./sources/runtime"
|
||||
export { default as defaultOptions } from "./defaults"
|
||||
export { default as mergeOptions } from "./merge"
|
||||
export { default as typeCastOptions } from "./type-cast"
|
||||
export { default as typeCastMappings } from "./type-cast/mappings"
|
||||
|
||||
@@ -5,10 +5,10 @@ import has from "lodash/has"
|
||||
import get from "lodash/get"
|
||||
import set from "lodash/fp/set"
|
||||
|
||||
import typeCasters from "./mappings"
|
||||
import mappings from "./mappings"
|
||||
|
||||
const typeCast = (options) => {
|
||||
return Object.entries(typeCasters).reduce(
|
||||
return Object.entries(mappings).reduce(
|
||||
(acc, [optionPath, { typeCaster, defaultValue }]) => {
|
||||
if (has(acc, optionPath)) {
|
||||
const uncasted = get(acc, optionPath)
|
||||
|
||||
@@ -14,7 +14,7 @@ import syntaxHighlightTypeCaster from "./type-casters/syntax-highlight"
|
||||
import undefinedStringTypeCaster from "./type-casters/undefined-string"
|
||||
import defaultOptions from "../defaults"
|
||||
|
||||
const typeCasters = {
|
||||
const mappings = {
|
||||
configUrl: { typeCaster: nullableStringTypeCaster },
|
||||
deepLinking: {
|
||||
typeCaster: booleanTypeCaster,
|
||||
@@ -112,4 +112,4 @@ const typeCasters = {
|
||||
},
|
||||
}
|
||||
|
||||
export default typeCasters
|
||||
export default mappings
|
||||
|
||||
@@ -41,14 +41,16 @@ import {
|
||||
mergeOptions,
|
||||
inlinePluginOptionsFactorization,
|
||||
storeOptionsFactorization,
|
||||
typeCastOptions,
|
||||
typeCastMappings,
|
||||
} from "./config"
|
||||
|
||||
export default function SwaggerUI(userOptions) {
|
||||
function SwaggerUI(userOptions) {
|
||||
const queryOptions = optionsFromQuery()(userOptions)
|
||||
const runtimeOptions = optionsFromRuntime()()
|
||||
let mergedOptions = mergeOptions(
|
||||
let mergedOptions = SwaggerUI.config.merge(
|
||||
{},
|
||||
defaultOptions,
|
||||
SwaggerUI.config.defaults,
|
||||
runtimeOptions,
|
||||
userOptions,
|
||||
queryOptions
|
||||
@@ -66,9 +68,9 @@ export default function SwaggerUI(userOptions) {
|
||||
(urlOptions) => {
|
||||
const urlOptionsFailedToFetch = urlOptions === null
|
||||
|
||||
mergedOptions = mergeOptions(
|
||||
mergedOptions = SwaggerUI.config.merge(
|
||||
{},
|
||||
defaultOptions,
|
||||
SwaggerUI.config.defaults,
|
||||
runtimeOptions,
|
||||
systemOptions,
|
||||
userOptions,
|
||||
@@ -121,7 +123,12 @@ export default function SwaggerUI(userOptions) {
|
||||
|
||||
SwaggerUI.System = System
|
||||
|
||||
SwaggerUI.defaultOptions = defaultOptions
|
||||
SwaggerUI.config = {
|
||||
defaults: defaultOptions,
|
||||
merge: mergeOptions,
|
||||
typeCast: typeCastOptions,
|
||||
typeCastMappings,
|
||||
}
|
||||
|
||||
SwaggerUI.presets = {
|
||||
base: BasePreset,
|
||||
@@ -155,3 +162,5 @@ SwaggerUI.plugins = {
|
||||
Versions: VersionsPlugin,
|
||||
SafeRender: SafeRenderPlugin,
|
||||
}
|
||||
|
||||
export default SwaggerUI
|
||||
|
||||
Reference in New Issue
Block a user