Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose build info via new versions plugin #9820

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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