Skip to content

Commit

Permalink
feat: expose build info via new versions plugin (#9820)
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n authored Apr 15, 2024
1 parent 68eb346 commit 463cd35
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -130,5 +120,6 @@ SwaggerUI.plugins = {
ViewLegacy: ViewLegacyPlugin,
DownloadUrl: DownloadUrlPlugin,
SyntaxHighlighting: SyntaxHighlightingPlugin,
Versions: VersionsPlugin,
SafeRender: SafeRenderPlugin,
}
19 changes: 19 additions & 0 deletions src/core/plugins/versions/after-load.js
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions src/core/plugins/versions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @prettier
*/
import afterLoad from "./after-load.js"

const VersionsPlugin = () => ({
afterLoad,
})

export default VersionsPlugin
2 changes: 2 additions & 0 deletions src/core/presets/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -47,6 +48,7 @@ const BasePreset = () => [
OnCompletePlugin,
RequestSnippetsPlugin,
SyntaxHighlightingPlugin,
VersionsPlugin,
SafeRenderPlugin(),
]

Expand Down

0 comments on commit 463cd35

Please sign in to comment.