vitepress-openapi 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/types/src/client.d.ts +2 -0
- package/dist/types/src/components/Common/OACodeValue.vue.d.ts +9 -9
- package/dist/types/src/components/Parameter/OAParameterExamples.vue.d.ts +13 -3
- package/dist/types/src/components/index.d.ts +6 -1
- package/dist/types/src/components/ui/input/Input.vue.d.ts +1 -0
- package/dist/types/src/composables/usePlayground.d.ts +1 -0
- package/dist/types/src/composables/useTheme.d.ts +4 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/lib/operation/operationData.d.ts +1 -0
- package/dist/types/src/lib/utils/minifyHtml.d.ts +5 -0
- package/dist/{useOpenapi-D3Fw1qI0.js → useOpenapi-B4Uu-BLL.js} +1070 -1057
- package/dist/{useOpenapi-DkEO8B6A.cjs → useOpenapi-CcNxVvye.cjs} +57 -55
- package/dist/vitepress-openapi.client.cjs.js +142 -142
- package/dist/vitepress-openapi.client.es.js +15525 -15434
- package/dist/vitepress-openapi.css +1 -1
- package/dist/vitepress-openapi.node.cjs.js +1 -1
- package/dist/vitepress-openapi.node.es.js +6 -5
- package/package.json +1 -1
- package/src/client.ts +2 -0
- package/src/components/Common/OACodeValue.vue +9 -10
- package/src/components/Parameter/OAParameter.vue +3 -1
- package/src/components/Parameter/OAParameterExamples.vue +30 -10
- package/src/components/Playground/OAPlaygroundParameterInput.vue +1 -0
- package/src/components/Playground/OAPlaygroundParameters.vue +20 -3
- package/src/components/Playground/OAPlaygroundSecurityInput.vue +2 -1
- package/src/components/Security/OASecurityContent.vue +1 -1
- package/src/components/index.ts +10 -0
- package/src/components/ui/input/Input.vue +27 -0
- package/src/components/ui/select-with-custom-option/SelectWithCustomOption.vue +1 -0
- package/src/composables/usePlayground.ts +14 -0
- package/src/composables/useSidebar.ts +5 -2
- package/src/composables/useTheme.ts +12 -0
- package/src/index.ts +1 -0
- package/src/lib/operation/operationData.ts +2 -0
- package/src/lib/sidebar/ensureGroupTextSlashPrefix.ts +1 -1
- package/src/lib/utils/minifyHtml.ts +9 -0
|
@@ -197,6 +197,19 @@ export function usePlayground() {
|
|
|
197
197
|
operationData.playground.parameterValues.value[parameterName] = parsedValue
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
function setSecurityValue(schemeId: string, value: any) {
|
|
201
|
+
if (!operationData || !schemeId) {
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Replace the object reference so the watcher always fires,
|
|
206
|
+
// even when the value for this key hasn't changed.
|
|
207
|
+
operationData.security.securityValues.value = {
|
|
208
|
+
...operationData.security.securityValues.value,
|
|
209
|
+
[schemeId]: value,
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
200
213
|
return {
|
|
201
214
|
loading,
|
|
202
215
|
response,
|
|
@@ -206,6 +219,7 @@ export function usePlayground() {
|
|
|
206
219
|
submitRequest,
|
|
207
220
|
cleanupImageUrls,
|
|
208
221
|
setParameterValue,
|
|
222
|
+
setSecurityValue,
|
|
209
223
|
hasOperationData: !!operationData,
|
|
210
224
|
}
|
|
211
225
|
}
|
|
@@ -6,6 +6,7 @@ import { parseOpenapi } from '../lib/parser/parseOpenapi'
|
|
|
6
6
|
import { cleanSidebarItems } from '../lib/sidebar/cleanSidebarItems'
|
|
7
7
|
import { generateSidebarItemsByPaths } from '../lib/sidebar/generateSidebarItemsByPaths'
|
|
8
8
|
import { createOpenApiSpec } from '../lib/spec/createOpenApiSpec'
|
|
9
|
+
import { minifyHtml } from '../lib/utils/minifyHtml'
|
|
9
10
|
|
|
10
11
|
type MethodAliases = Record<string, string>
|
|
11
12
|
|
|
@@ -111,10 +112,12 @@ export function useSidebar({
|
|
|
111
112
|
const _globalItemTemplate: SidebarItemTemplateFn = sidebarItemTemplate || (({ method, path, title }) => {
|
|
112
113
|
const resolvedMethod = methodAliases[method] || method.toUpperCase()
|
|
113
114
|
const displayText = title || path
|
|
114
|
-
return
|
|
115
|
+
return minifyHtml(`
|
|
116
|
+
<span class="OASidebarItem group/oaOperationLink">
|
|
115
117
|
<span class="OASidebarItem-badge OAMethodBadge--${method.toLowerCase()}">${resolvedMethod}</span>
|
|
116
118
|
<span class="OASidebarItem-text text">${displayText}</span>
|
|
117
|
-
</span
|
|
119
|
+
</span>
|
|
120
|
+
`)
|
|
118
121
|
})
|
|
119
122
|
|
|
120
123
|
const _globalGroupTemplate: SidebarGroupTemplateFn = sidebarGroupTemplate || defaultGroupTemplate
|
|
@@ -153,6 +153,7 @@ export interface ServerConfig {
|
|
|
153
153
|
|
|
154
154
|
export interface StorageConfig {
|
|
155
155
|
prefix?: string
|
|
156
|
+
persistAuth?: boolean
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
export interface OperationLinkConfig {
|
|
@@ -235,6 +236,7 @@ export const DEFAULT_OPERATION_SLOTS: OperationSlot[] = [
|
|
|
235
236
|
|
|
236
237
|
export const DEFAULT_BASE_URL = 'http://localhost'
|
|
237
238
|
export const DEFAULT_STORAGE_PREFIX = '--oa'
|
|
239
|
+
export const DEFAULT_STORAGE_PERSIST_AUTH = true
|
|
238
240
|
|
|
239
241
|
export const availableLanguages: LanguageConfig[] = [
|
|
240
242
|
{
|
|
@@ -385,6 +387,7 @@ const defaultValues = {
|
|
|
385
387
|
},
|
|
386
388
|
storage: {
|
|
387
389
|
prefix: DEFAULT_STORAGE_PREFIX,
|
|
390
|
+
persistAuth: DEFAULT_STORAGE_PERSIST_AUTH,
|
|
388
391
|
},
|
|
389
392
|
markdown: {
|
|
390
393
|
operationLink: {
|
|
@@ -481,6 +484,7 @@ const themeConfig: UseThemeConfig = {
|
|
|
481
484
|
},
|
|
482
485
|
storage: {
|
|
483
486
|
prefix: defaultValues.storage.prefix,
|
|
487
|
+
persistAuth: defaultValues.storage.persistAuth,
|
|
484
488
|
},
|
|
485
489
|
markdown: {
|
|
486
490
|
operationLink: {
|
|
@@ -1099,6 +1103,13 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
1099
1103
|
if (config.prefix !== undefined) {
|
|
1100
1104
|
storage.prefix = config.prefix
|
|
1101
1105
|
}
|
|
1106
|
+
if (config.persistAuth !== undefined) {
|
|
1107
|
+
storage.persistAuth = config.persistAuth
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
function getStoragePersistAuth(): boolean {
|
|
1112
|
+
return themeConfig?.storage?.persistAuth ?? DEFAULT_STORAGE_PERSIST_AUTH
|
|
1102
1113
|
}
|
|
1103
1114
|
|
|
1104
1115
|
return {
|
|
@@ -1179,6 +1190,7 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
1179
1190
|
setMarkdownConfig,
|
|
1180
1191
|
getOperationLinkConfig,
|
|
1181
1192
|
getStoragePrefix,
|
|
1193
|
+
getStoragePersistAuth,
|
|
1182
1194
|
setStorageConfig,
|
|
1183
1195
|
}
|
|
1184
1196
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ export {
|
|
|
9
9
|
export { usePaths } from './composables/usePaths'
|
|
10
10
|
export { useSidebar } from './composables/useSidebar'
|
|
11
11
|
export { createOpenApiSpec, type OpenApiSpecInstance } from './lib/spec/createOpenApiSpec'
|
|
12
|
+
export { minifyHtml } from './lib/utils/minifyHtml'
|
|
12
13
|
export { parseSpec } from './lib/utils/parseSpec'
|
|
13
14
|
|
|
14
15
|
export const httpVerbs: readonly OpenAPIV3.HttpMethods[] = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const
|
|
@@ -10,6 +10,7 @@ export interface OperationData {
|
|
|
10
10
|
operationId: string
|
|
11
11
|
security: {
|
|
12
12
|
selectedSchemeId: Ref<string>
|
|
13
|
+
securityValues: Ref<Record<string, any>>
|
|
13
14
|
}
|
|
14
15
|
playground: {
|
|
15
16
|
request: Ref<OARequest>
|
|
@@ -44,6 +45,7 @@ export function initOperationData({
|
|
|
44
45
|
operationId: operation.operationId,
|
|
45
46
|
security: {
|
|
46
47
|
selectedSchemeId: ref(operation.securityUi?.some(s => s.id === defaultSecurityScheme) ? defaultSecurityScheme : firstSecurityScheme),
|
|
48
|
+
securityValues: ref({}),
|
|
47
49
|
},
|
|
48
50
|
playground: {
|
|
49
51
|
request: ref(request || {} as OARequest),
|
|
@@ -9,7 +9,7 @@ export function ensureGroupTextSlashPrefix(items: OASidebarItem[]): OASidebarIte
|
|
|
9
9
|
item.items = ensureGroupTextSlashPrefix(item.items)
|
|
10
10
|
|
|
11
11
|
item.text = item.text?.startsWith('/') ? item.text : `/${item.text}`
|
|
12
|
-
} else if (item.text && !item.isOperation && !item.text.startsWith('/') && !item.text.includes('<
|
|
12
|
+
} else if (item.text && !item.isOperation && !item.text.startsWith('/') && !item.text.includes('<')) {
|
|
13
13
|
item.text = `/${item.text}`
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const WHITESPACE_REGEX = /\s+/g
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minifies a string of HTML by replacing multiple whitespace characters with a single space
|
|
5
|
+
* and trimming the result. This helps prevent hydration mismatches in VitePress.
|
|
6
|
+
*/
|
|
7
|
+
export function minifyHtml(html: string): string {
|
|
8
|
+
return html.replace(WHITESPACE_REGEX, ' ').trim()
|
|
9
|
+
}
|