vitepress-openapi 0.1.14 → 0.1.16
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/dist/types/src/components/Playground/OAPlaygroundBodyInput.vue.d.ts +3 -0
- package/dist/types/src/components/Playground/OAPlaygroundParameterInput.vue.d.ts +19 -0
- package/dist/types/src/components/Playground/OAPlaygroundParameters.vue.d.ts +19 -0
- package/dist/types/src/components/ui/select-with-custom-option/SelectWithCustomOption.vue.d.ts +1 -1
- package/dist/types/src/composables/useTheme.d.ts +23 -0
- package/dist/types/src/lib/examples/getPropertyExample.d.ts +2 -0
- package/dist/types/src/lib/playground/playgroundExampleBehavior.d.ts +5 -0
- package/dist/{useOpenapi-DjUt0cr5.js → useOpenapi-BCJnxIc0.js} +1576 -1530
- package/dist/{useOpenapi-DEPZ2jCp.cjs → useOpenapi-DDAB-v6S.cjs} +52 -52
- package/dist/vitepress-openapi.client.cjs.js +146 -146
- package/dist/vitepress-openapi.client.es.js +10249 -10190
- package/dist/vitepress-openapi.css +1 -1
- package/dist/vitepress-openapi.node.cjs.js +1 -1
- package/dist/vitepress-openapi.node.es.js +1 -1
- package/package.json +1 -1
- package/src/components/Feature/OAOperationContext.vue +3 -1
- package/src/components/Playground/OAPlayground.vue +7 -1
- package/src/components/Playground/OAPlaygroundBodyInput.vue +10 -2
- package/src/components/Playground/OAPlaygroundParameterInput.vue +20 -5
- package/src/components/Playground/OAPlaygroundParameters.vue +28 -11
- package/src/composables/useTheme.ts +71 -0
- package/src/lib/examples/getPropertyExample.ts +9 -1
- package/src/lib/operation/operationData.ts +4 -2
- package/src/lib/parser/getSchemaUi.ts +9 -6
- package/src/lib/playground/playgroundExampleBehavior.ts +48 -0
|
@@ -92,6 +92,8 @@ export interface ResponseConfig {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
export type PlaygroundExampleBehavior = 'placeholder' | 'value' | 'ignore'
|
|
96
|
+
|
|
95
97
|
export interface PlaygroundConfig {
|
|
96
98
|
jsonEditor?: {
|
|
97
99
|
mode?: Ref<PlaygroundJsonEditorMode>
|
|
@@ -99,6 +101,11 @@ export interface PlaygroundConfig {
|
|
|
99
101
|
navigationBar?: Ref<boolean>
|
|
100
102
|
statusBar?: Ref<boolean>
|
|
101
103
|
}
|
|
104
|
+
|
|
105
|
+
examples?: {
|
|
106
|
+
behavior?: Ref<PlaygroundExampleBehavior>
|
|
107
|
+
playgroundExampleBehavior?: Ref<PlaygroundExampleBehavior>
|
|
108
|
+
}
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
export interface SecurityConfig {
|
|
@@ -144,6 +151,10 @@ export interface ServerConfig {
|
|
|
144
151
|
getServers?: GetServersFunction | null
|
|
145
152
|
}
|
|
146
153
|
|
|
154
|
+
export interface StorageConfig {
|
|
155
|
+
prefix?: string
|
|
156
|
+
}
|
|
157
|
+
|
|
147
158
|
export interface OperationLinkConfig {
|
|
148
159
|
linkPrefix?: string
|
|
149
160
|
transformHref?: (href: string) => string
|
|
@@ -171,6 +182,7 @@ export interface UseThemeConfig {
|
|
|
171
182
|
codeSamples?: Partial<CodeSamplesConfig>
|
|
172
183
|
linksPrefixes?: Partial<LinksPrefixesConfig>
|
|
173
184
|
server?: Partial<ServerConfig>
|
|
185
|
+
storage?: Partial<StorageConfig>
|
|
174
186
|
markdown?: Partial<MarkdownConfig>
|
|
175
187
|
}
|
|
176
188
|
|
|
@@ -222,6 +234,7 @@ export const DEFAULT_OPERATION_SLOTS: OperationSlot[] = [
|
|
|
222
234
|
]
|
|
223
235
|
|
|
224
236
|
export const DEFAULT_BASE_URL = 'http://localhost'
|
|
237
|
+
export const DEFAULT_STORAGE_PREFIX = '--oa'
|
|
225
238
|
|
|
226
239
|
export const availableLanguages: LanguageConfig[] = [
|
|
227
240
|
{
|
|
@@ -302,6 +315,10 @@ const defaultValues = {
|
|
|
302
315
|
navigationBar: false,
|
|
303
316
|
statusBar: false,
|
|
304
317
|
},
|
|
318
|
+
examples: {
|
|
319
|
+
behavior: 'value' as PlaygroundExampleBehavior,
|
|
320
|
+
playgroundExampleBehavior: 'value' as PlaygroundExampleBehavior,
|
|
321
|
+
},
|
|
305
322
|
},
|
|
306
323
|
security: {
|
|
307
324
|
defaultScheme: null as string | null,
|
|
@@ -366,6 +383,9 @@ const defaultValues = {
|
|
|
366
383
|
allowCustomServer: false,
|
|
367
384
|
getServers: null,
|
|
368
385
|
},
|
|
386
|
+
storage: {
|
|
387
|
+
prefix: DEFAULT_STORAGE_PREFIX,
|
|
388
|
+
},
|
|
369
389
|
markdown: {
|
|
370
390
|
operationLink: {
|
|
371
391
|
linkPrefix: DEFAULT_OPERATIONS_PREFIX,
|
|
@@ -412,6 +432,10 @@ const themeConfig: UseThemeConfig = {
|
|
|
412
432
|
navigationBar: ref(defaultValues.playground.jsonEditor.navigationBar),
|
|
413
433
|
statusBar: ref(defaultValues.playground.jsonEditor.statusBar),
|
|
414
434
|
},
|
|
435
|
+
examples: {
|
|
436
|
+
behavior: ref(defaultValues.playground.examples?.behavior ?? 'value'),
|
|
437
|
+
playgroundExampleBehavior: ref(defaultValues.playground.examples?.playgroundExampleBehavior ?? 'value'),
|
|
438
|
+
},
|
|
415
439
|
},
|
|
416
440
|
security: {
|
|
417
441
|
defaultScheme: ref(defaultValues.security.defaultScheme),
|
|
@@ -455,6 +479,9 @@ const themeConfig: UseThemeConfig = {
|
|
|
455
479
|
allowCustomServer: defaultValues.server.allowCustomServer,
|
|
456
480
|
getServers: defaultValues.server.getServers,
|
|
457
481
|
},
|
|
482
|
+
storage: {
|
|
483
|
+
prefix: defaultValues.storage.prefix,
|
|
484
|
+
},
|
|
458
485
|
markdown: {
|
|
459
486
|
operationLink: {
|
|
460
487
|
linkPrefix: defaultValues.markdown.operationLink.linkPrefix,
|
|
@@ -533,6 +560,12 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
533
560
|
if (config.playground?.jsonEditor?.statusBar !== undefined) {
|
|
534
561
|
ensureNestedRefProperty(themeConfig, ['playground', 'jsonEditor'], 'statusBar', config.playground.jsonEditor.statusBar)
|
|
535
562
|
}
|
|
563
|
+
if (config.playground?.examples?.behavior !== undefined) {
|
|
564
|
+
ensureNestedRefProperty(themeConfig, ['playground', 'examples'], 'behavior', config.playground.examples.behavior)
|
|
565
|
+
}
|
|
566
|
+
if (config.playground?.examples?.playgroundExampleBehavior !== undefined) {
|
|
567
|
+
ensureNestedRefProperty(themeConfig, ['playground', 'examples'], 'playgroundExampleBehavior', config.playground.examples.playgroundExampleBehavior)
|
|
568
|
+
}
|
|
536
569
|
|
|
537
570
|
// Security
|
|
538
571
|
if (config.security?.defaultScheme !== undefined) {
|
|
@@ -584,6 +617,11 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
584
617
|
setServerConfig(config.server)
|
|
585
618
|
}
|
|
586
619
|
|
|
620
|
+
// Storage
|
|
621
|
+
if (config.storage !== undefined) {
|
|
622
|
+
setStorageConfig(config.storage)
|
|
623
|
+
}
|
|
624
|
+
|
|
587
625
|
// Markdown
|
|
588
626
|
if (config.markdown !== undefined) {
|
|
589
627
|
setMarkdownConfig(config.markdown)
|
|
@@ -753,6 +791,22 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
753
791
|
ensureNestedRefProperty(themeConfig, ['playground', 'jsonEditor'], 'statusBar', value)
|
|
754
792
|
}
|
|
755
793
|
|
|
794
|
+
function getPlaygroundExamplesBehavior(): PlaygroundExampleBehavior {
|
|
795
|
+
return themeConfig?.playground?.examples?.behavior?.value ?? 'value'
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function setPlaygroundExamplesBehavior(value: PlaygroundExampleBehavior) {
|
|
799
|
+
ensureNestedRefProperty(themeConfig, ['playground', 'examples'], 'behavior', value)
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
function getPlaygroundXExampleBehavior(): PlaygroundExampleBehavior {
|
|
803
|
+
return themeConfig?.playground?.examples?.playgroundExampleBehavior?.value ?? 'value'
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
function setPlaygroundXExampleBehavior(value: PlaygroundExampleBehavior) {
|
|
807
|
+
ensureNestedRefProperty(themeConfig, ['playground', 'examples'], 'playgroundExampleBehavior', value)
|
|
808
|
+
}
|
|
809
|
+
|
|
756
810
|
function getSecurityDefaultScheme(): string | null | undefined {
|
|
757
811
|
return themeConfig?.security?.defaultScheme?.value
|
|
758
812
|
}
|
|
@@ -1036,6 +1090,17 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
1036
1090
|
return themeConfig.markdown?.operationLink
|
|
1037
1091
|
}
|
|
1038
1092
|
|
|
1093
|
+
function getStoragePrefix(): string {
|
|
1094
|
+
return themeConfig?.storage?.prefix ?? DEFAULT_STORAGE_PREFIX
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
function setStorageConfig(config: Partial<StorageConfig>) {
|
|
1098
|
+
const storage = ensureNestedProperty(themeConfig, 'storage')
|
|
1099
|
+
if (config.prefix !== undefined) {
|
|
1100
|
+
storage.prefix = config.prefix
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1039
1104
|
return {
|
|
1040
1105
|
isDark,
|
|
1041
1106
|
schemaConfig: themeConfig.requestBody,
|
|
@@ -1075,6 +1140,10 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
1075
1140
|
setPlaygroundJsonEditorNavigationBar,
|
|
1076
1141
|
getPlaygroundJsonEditorStatusBar,
|
|
1077
1142
|
setPlaygroundJsonEditorStatusBar,
|
|
1143
|
+
getPlaygroundExamplesBehavior,
|
|
1144
|
+
setPlaygroundExamplesBehavior,
|
|
1145
|
+
getPlaygroundXExampleBehavior,
|
|
1146
|
+
setPlaygroundXExampleBehavior,
|
|
1078
1147
|
getSecurityDefaultScheme,
|
|
1079
1148
|
setSecurityDefaultScheme,
|
|
1080
1149
|
getOperationBadges,
|
|
@@ -1109,5 +1178,7 @@ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
|
|
|
1109
1178
|
getExternalLinksNewTab,
|
|
1110
1179
|
setMarkdownConfig,
|
|
1111
1180
|
getOperationLinkConfig,
|
|
1181
|
+
getStoragePrefix,
|
|
1182
|
+
setStorageConfig,
|
|
1112
1183
|
}
|
|
1113
1184
|
}
|
|
@@ -63,7 +63,7 @@ function firstFromExamples(
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export function
|
|
66
|
+
export function getPlaygroundSpecificExample(property: any): any {
|
|
67
67
|
if (property?.['x-playground-example'] !== undefined) {
|
|
68
68
|
return property['x-playground-example']
|
|
69
69
|
}
|
|
@@ -72,6 +72,10 @@ export function getPropertyExample(property: any): any {
|
|
|
72
72
|
return property.schema['x-playground-example']
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getStandardExample(property: any): any {
|
|
75
79
|
if (property?.example !== undefined) {
|
|
76
80
|
return property.example
|
|
77
81
|
}
|
|
@@ -104,3 +108,7 @@ export function getPropertyExample(property: any): any {
|
|
|
104
108
|
|
|
105
109
|
return null
|
|
106
110
|
}
|
|
111
|
+
|
|
112
|
+
export function getPropertyExample(property: any): any {
|
|
113
|
+
return getPlaygroundSpecificExample(property) ?? getStandardExample(property)
|
|
114
|
+
}
|
|
@@ -36,7 +36,9 @@ export function initOperationData({
|
|
|
36
36
|
}): OperationData {
|
|
37
37
|
const firstSecurityScheme = operation.securityUi?.[0]?.id || ''
|
|
38
38
|
|
|
39
|
-
const
|
|
39
|
+
const theme = useTheme()
|
|
40
|
+
const defaultSecurityScheme = theme.getSecurityDefaultScheme() || firstSecurityScheme
|
|
41
|
+
const storagePrefix = theme.getStoragePrefix()
|
|
40
42
|
|
|
41
43
|
return {
|
|
42
44
|
operationId: operation.operationId,
|
|
@@ -46,7 +48,7 @@ export function initOperationData({
|
|
|
46
48
|
playground: {
|
|
47
49
|
request: ref(request || {} as OARequest),
|
|
48
50
|
selectedServer: isLocalStorageAvailable()
|
|
49
|
-
? useStorage(
|
|
51
|
+
? useStorage(`${storagePrefix}-operation-${operation.operationId}-selectedServer`, selectedServer, localStorage, {
|
|
50
52
|
mergeDefaults: true,
|
|
51
53
|
})
|
|
52
54
|
: ref(selectedServer),
|
|
@@ -234,6 +234,7 @@ class UiPropertyFactory {
|
|
|
234
234
|
schema.items.properties,
|
|
235
235
|
schema.items.required || [],
|
|
236
236
|
schema.items.additionalProperties,
|
|
237
|
+
schema.items['x-additionalPropertiesName'],
|
|
237
238
|
)
|
|
238
239
|
: undefined
|
|
239
240
|
|
|
@@ -334,6 +335,7 @@ class UiPropertyFactory {
|
|
|
334
335
|
schema.properties,
|
|
335
336
|
schema.required || [],
|
|
336
337
|
schema.additionalProperties,
|
|
338
|
+
schema['x-additionalPropertiesName'],
|
|
337
339
|
)
|
|
338
340
|
} else if (schema.type === undefined) {
|
|
339
341
|
if (schema.properties || schema.additionalProperties) {
|
|
@@ -342,6 +344,7 @@ class UiPropertyFactory {
|
|
|
342
344
|
schema.properties,
|
|
343
345
|
schema.required || [],
|
|
344
346
|
schema.additionalProperties,
|
|
347
|
+
schema['x-additionalPropertiesName'],
|
|
345
348
|
)
|
|
346
349
|
}
|
|
347
350
|
}
|
|
@@ -353,6 +356,7 @@ class UiPropertyFactory {
|
|
|
353
356
|
propertiesNode?: Record<string, OpenAPI.SchemaObject>,
|
|
354
357
|
requiredProperties: string[] = [],
|
|
355
358
|
additionalPropertiesNode?: OpenAPI.SchemaObject | boolean,
|
|
359
|
+
additionalPropertiesName?: string,
|
|
356
360
|
): OAProperty[] {
|
|
357
361
|
const properties: OAProperty[] = []
|
|
358
362
|
|
|
@@ -368,12 +372,11 @@ class UiPropertyFactory {
|
|
|
368
372
|
? additionalPropertiesNode
|
|
369
373
|
: { type: 'string' }
|
|
370
374
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
})
|
|
375
|
+
const name = additionalPropertiesName || 'additionalProperties'
|
|
376
|
+
const property = UiPropertyFactory.schemaToUiProperty(name, additionalProps)
|
|
377
|
+
property.required = false
|
|
378
|
+
property.meta = { ...(property.meta || {}), isAdditionalProperties: true }
|
|
379
|
+
properties.push(property)
|
|
377
380
|
}
|
|
378
381
|
|
|
379
382
|
return properties
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { PlaygroundExampleBehavior } from '../../composables/useTheme'
|
|
2
|
+
import { getPlaygroundSpecificExample, getStandardExample } from '../examples/getPropertyExample'
|
|
3
|
+
|
|
4
|
+
export function useExampleForPlaceholder(behavior: PlaygroundExampleBehavior): boolean {
|
|
5
|
+
return behavior !== 'ignore'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function useExampleForValue(behavior: PlaygroundExampleBehavior): boolean {
|
|
9
|
+
return behavior === 'value'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function resolveExampleForValue(
|
|
13
|
+
property: any,
|
|
14
|
+
behavior: PlaygroundExampleBehavior,
|
|
15
|
+
xExampleBehavior: PlaygroundExampleBehavior = 'value',
|
|
16
|
+
): any {
|
|
17
|
+
if (useExampleForValue(xExampleBehavior)) {
|
|
18
|
+
const specific = getPlaygroundSpecificExample(property)
|
|
19
|
+
if (specific !== null) {
|
|
20
|
+
return specific
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (useExampleForValue(behavior)) {
|
|
25
|
+
return getStandardExample(property)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function resolveExampleForPlaceholder(
|
|
32
|
+
property: any,
|
|
33
|
+
behavior: PlaygroundExampleBehavior,
|
|
34
|
+
xExampleBehavior: PlaygroundExampleBehavior = 'value',
|
|
35
|
+
): any {
|
|
36
|
+
if (useExampleForPlaceholder(xExampleBehavior)) {
|
|
37
|
+
const specific = getPlaygroundSpecificExample(property)
|
|
38
|
+
if (specific !== null) {
|
|
39
|
+
return specific
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (useExampleForPlaceholder(behavior)) {
|
|
44
|
+
return getStandardExample(property)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return null
|
|
48
|
+
}
|