diff --git a/src/core/index.js b/src/core/index.js index 5ff03fd71d6..50365d43d8b 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -26,9 +26,9 @@ import ViewPlugin from "./plugins/view" import ViewLegacyPlugin from "core/plugins/view-legacy" import DownloadUrlPlugin from "./plugins/download-url" import SyntaxHighlightingPlugin from "core/plugins/syntax-highlighting" +import VersionsPlugin from "core/plugins/versions" import SafeRenderPlugin from "./plugins/safe-render" -import win from "./window" import { defaultOptions, optionsFromQuery, @@ -39,18 +39,8 @@ import { storeOptionsFactorization } from "./config" -// eslint-disable-next-line no-undef -const { GIT_DIRTY, GIT_COMMIT, PACKAGE_VERSION, BUILD_TIME } = buildInfo export default function SwaggerUI(userOptions) { - win.versions = win.versions || {} - win.versions.swaggerUi = { - version: PACKAGE_VERSION, - gitRevision: GIT_COMMIT, - gitDirty: GIT_DIRTY, - buildTimestamp: BUILD_TIME, - } - const queryOptions = optionsFromQuery()(userOptions) let mergedOptions = mergeOptions({}, defaultOptions, userOptions, queryOptions) const storeOptions = storeOptionsFactorization(mergedOptions) @@ -130,5 +120,6 @@ SwaggerUI.plugins = { ViewLegacy: ViewLegacyPlugin, DownloadUrl: DownloadUrlPlugin, SyntaxHighlighting: SyntaxHighlightingPlugin, + Versions: VersionsPlugin, SafeRender: SafeRenderPlugin, } diff --git a/src/core/plugins/versions/after-load.js b/src/core/plugins/versions/after-load.js new file mode 100644 index 00000000000..3a20a3a6292 --- /dev/null +++ b/src/core/plugins/versions/after-load.js @@ -0,0 +1,19 @@ +/** + * @prettier + */ +import win from "core/window" + +const afterLoad = () => { + // eslint-disable-next-line no-undef + const { GIT_DIRTY, GIT_COMMIT, PACKAGE_VERSION, BUILD_TIME } = buildInfo + + win.versions = win.versions || {} + win.versions.swaggerUI = { + version: PACKAGE_VERSION, + gitRevision: GIT_COMMIT, + gitDirty: GIT_DIRTY, + buildTimestamp: BUILD_TIME, + } +} + +export default afterLoad diff --git a/src/core/plugins/versions/index.js b/src/core/plugins/versions/index.js new file mode 100644 index 00000000000..36413d82e86 --- /dev/null +++ b/src/core/plugins/versions/index.js @@ -0,0 +1,10 @@ +/** + * @prettier + */ +import afterLoad from "./after-load.js" + +const VersionsPlugin = () => ({ + afterLoad, +}) + +export default VersionsPlugin diff --git a/src/core/presets/base/index.js b/src/core/presets/base/index.js index b220c5949fd..15b7f6acd24 100644 --- a/src/core/presets/base/index.js +++ b/src/core/presets/base/index.js @@ -20,6 +20,7 @@ import ViewPlugin from "core/plugins/view" import ViewLegacyPlugin from "core/plugins/view-legacy" import DownloadUrlPlugin from "core/plugins/download-url" import SyntaxHighlightingPlugin from "core/plugins/syntax-highlighting" +import VersionsPlugin from "core/plugins/versions" import SafeRenderPlugin from "core/plugins/safe-render" // ad-hoc plugins import CoreComponentsPlugin from "core/presets/base/plugins/core-components" @@ -47,6 +48,7 @@ const BasePreset = () => [ OnCompletePlugin, RequestSnippetsPlugin, SyntaxHighlightingPlugin, + VersionsPlugin, SafeRenderPlugin(), ]