Skip to content

Commit

Permalink
style(core): apply prettier formatting (#9848)
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n authored Apr 19, 2024
1 parent 3a671c6 commit 12d6685
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions src/core/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @prettier
*/
import System from "./system"
// presets
import BasePreset from "./presets/base"
Expand Down Expand Up @@ -37,55 +40,81 @@ import {
optionsFromRuntime,
mergeOptions,
inlinePluginOptionsFactorization,
storeOptionsFactorization
storeOptionsFactorization,
} from "./config"


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


const store = new System(storeOptions)
store.register([mergedOptions.plugins, InlinePlugin])
const system = store.getSystem()

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

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

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

if (!urlOptionsFailedToFetch) {
if (!queryOptions.url && typeof mergedOptions.spec === "object" && Object.keys(mergedOptions.spec).length > 0) {
if (
!queryOptions.url &&
typeof mergedOptions.spec === "object" &&
Object.keys(mergedOptions.spec).length > 0
) {
system.specActions.updateUrl("")
system.specActions.updateLoadingStatus("success")
system.specActions.updateSpec(JSON.stringify(mergedOptions.spec))
} else if (typeof system.specActions.download === "function" && mergedOptions.url && !mergedOptions.urls) {
} else if (
typeof system.specActions.download === "function" &&
mergedOptions.url &&
!mergedOptions.urls
) {
system.specActions.updateUrl(mergedOptions.url)
system.specActions.download(mergedOptions.url)
}
}

if (mergedOptions.domNode) {
system.render(mergedOptions.domNode, "App")
} else if(mergedOptions.dom_id) {
} else if (mergedOptions.dom_id) {
let domNode = document.querySelector(mergedOptions.dom_id)
system.render(domNode, "App")
} else if(mergedOptions.dom_id === null || mergedOptions.domNode === null) {
} else if (
mergedOptions.dom_id === null ||
mergedOptions.domNode === null
) {
// do nothing
// this is useful for testing that does not need to do any rendering
} else {
console.error("Skipped rendering: no `dom_id` or `domNode` was specified")
console.error(
"Skipped rendering: no `dom_id` or `domNode` was specified"
)
}
})
}
)

return system
}
Expand Down

0 comments on commit 12d6685

Please sign in to comment.