@dv.net/docs-vitepress-openapi 1.0.7

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.
Files changed (135) hide show
  1. package/README.md +52 -0
  2. package/dist/docs-vitepress-openapi.client.cjs.js +1 -0
  3. package/dist/docs-vitepress-openapi.client.es.js +16 -0
  4. package/dist/docs-vitepress-openapi.css +1 -0
  5. package/dist/docs-vitepress-openapi.node.cjs.js +4102 -0
  6. package/dist/docs-vitepress-openapi.node.es.js +72981 -0
  7. package/dist/vanilla-picker-BAEwS4Fy.js +536 -0
  8. package/dist/vanilla-picker-m653iADl.cjs +8 -0
  9. package/package.json +80 -0
  10. package/src/client.ts +73 -0
  11. package/src/components/Common/Lazy/OALazy.vue +49 -0
  12. package/src/components/Common/Lazy/lazyBus.ts +8 -0
  13. package/src/components/Common/OACodeBlock.vue +91 -0
  14. package/src/components/Common/OACodeValue.vue +22 -0
  15. package/src/components/Common/OAHeaderBadges.vue +44 -0
  16. package/src/components/Common/OAHeading.vue +84 -0
  17. package/src/components/Common/OAInfo.vue +106 -0
  18. package/src/components/Common/OAIntroduction.vue +25 -0
  19. package/src/components/Common/OAJSONEditor.vue +41 -0
  20. package/src/components/Common/OAMarkdown.vue +28 -0
  21. package/src/components/Common/OAMethodBadge.vue +20 -0
  22. package/src/components/Common/OAServers.vue +42 -0
  23. package/src/components/Operation/OAOperation.vue +345 -0
  24. package/src/components/Operation/OAOperationTags.vue +30 -0
  25. package/src/components/Parameter/OAParameter.vue +80 -0
  26. package/src/components/Parameter/OAParameterAttribute.vue +44 -0
  27. package/src/components/Parameter/OAParameterExamples.vue +52 -0
  28. package/src/components/Parameter/OAParameters.vue +69 -0
  29. package/src/components/Path/OAPath.vue +347 -0
  30. package/src/components/Path/OAPathEndpoint.vue +99 -0
  31. package/src/components/Path/OAPaths.vue +62 -0
  32. package/src/components/Path/OAPathsByTag.vue +118 -0
  33. package/src/components/Path/OAPathsByTags.vue +99 -0
  34. package/src/components/Path/OAPathsSummary.vue +52 -0
  35. package/src/components/Playground/OAPlaygroundParameterInput.vue +97 -0
  36. package/src/components/Playground/OAPlaygroundParameters.vue +262 -0
  37. package/src/components/Playground/OAPlaygroundResponse.vue +74 -0
  38. package/src/components/Playground/OAPlaygroundSecurityInput.vue +44 -0
  39. package/src/components/Remote/OARemoteContext.vue +42 -0
  40. package/src/components/Remote/OARemoteOperation.vue +30 -0
  41. package/src/components/Remote/OARemoteRoot.vue +29 -0
  42. package/src/components/Remote/OARemoteSpec.vue +23 -0
  43. package/src/components/Request/OARequestBody.vue +24 -0
  44. package/src/components/Response/OAResponse.vue +81 -0
  45. package/src/components/Response/OAResponses.vue +119 -0
  46. package/src/components/Sample/OACodeSamples.vue +71 -0
  47. package/src/components/Schema/OASchemaPropertyAttributes.vue +44 -0
  48. package/src/components/Schema/OASchemaTabs.vue +90 -0
  49. package/src/components/Schema/OASchemaUI.vue +151 -0
  50. package/src/components/Security/OASecurity.vue +79 -0
  51. package/src/components/Security/OASecurityContent.vue +100 -0
  52. package/src/components/Spec/OASpec.vue +127 -0
  53. package/src/components/Spec/OASpecSkeleton.vue +26 -0
  54. package/src/components/Try/OATryItButton.vue +171 -0
  55. package/src/components/Try/OATryWithVariables.vue +105 -0
  56. package/src/components/index.ts +55 -0
  57. package/src/components/ui/badge/Badge.vue +18 -0
  58. package/src/components/ui/badge/index.ts +32 -0
  59. package/src/components/ui/button/Button.vue +28 -0
  60. package/src/components/ui/button/index.ts +37 -0
  61. package/src/components/ui/checkbox/Checkbox.vue +33 -0
  62. package/src/components/ui/checkbox/index.ts +1 -0
  63. package/src/components/ui/collapsible/Collapsible.vue +18 -0
  64. package/src/components/ui/collapsible/CollapsibleContent.vue +15 -0
  65. package/src/components/ui/collapsible/CollapsibleTrigger.vue +12 -0
  66. package/src/components/ui/collapsible/index.ts +3 -0
  67. package/src/components/ui/input/Input.vue +29 -0
  68. package/src/components/ui/input/index.ts +1 -0
  69. package/src/components/ui/label/Label.vue +29 -0
  70. package/src/components/ui/label/index.ts +1 -0
  71. package/src/components/ui/multiselect/Multiselect.vue +104 -0
  72. package/src/components/ui/select/Select.vue +15 -0
  73. package/src/components/ui/select/SelectContent.vue +56 -0
  74. package/src/components/ui/select/SelectGroup.vue +24 -0
  75. package/src/components/ui/select/SelectItem.vue +40 -0
  76. package/src/components/ui/select/SelectItemText.vue +12 -0
  77. package/src/components/ui/select/SelectLabel.vue +14 -0
  78. package/src/components/ui/select/SelectScrollDownButton.vue +29 -0
  79. package/src/components/ui/select/SelectScrollUpButton.vue +29 -0
  80. package/src/components/ui/select/SelectSeparator.vue +22 -0
  81. package/src/components/ui/select/SelectTrigger.vue +33 -0
  82. package/src/components/ui/select/SelectValue.vue +12 -0
  83. package/src/components/ui/select/index.ts +11 -0
  84. package/src/components/ui/tabs/Tabs.vue +15 -0
  85. package/src/components/ui/tabs/TabsContent.vue +24 -0
  86. package/src/components/ui/tabs/TabsList.vue +27 -0
  87. package/src/components/ui/tabs/TabsTrigger.vue +33 -0
  88. package/src/components/ui/tabs/index.ts +21 -0
  89. package/src/composables/useOpenapi.ts +70 -0
  90. package/src/composables/usePaths.ts +31 -0
  91. package/src/composables/usePlayground.ts +49 -0
  92. package/src/composables/useShiki.ts +46 -0
  93. package/src/composables/useSidebar.ts +301 -0
  94. package/src/composables/useTheme.ts +799 -0
  95. package/src/index.ts +8 -0
  96. package/src/json.css +251 -0
  97. package/src/lib/OpenApi.ts +254 -0
  98. package/src/lib/codeSamples/buildRequest.ts +149 -0
  99. package/src/lib/codeSamples/generateCodeSample.ts +20 -0
  100. package/src/lib/codeSamples/generateCodeSampleCurl.ts +150 -0
  101. package/src/lib/codeSamples/generateCodeSampleJavaScript.ts +29 -0
  102. package/src/lib/codeSamples/generateCodeSamplePhp.ts +50 -0
  103. package/src/lib/codeSamples/generateCodeSamplePython.ts +32 -0
  104. package/src/lib/codeSamples/request.ts +25 -0
  105. package/src/lib/constraintsParser.ts +30 -0
  106. package/src/lib/createOpenApiInstance.ts +18 -0
  107. package/src/lib/deepUnref.ts +76 -0
  108. package/src/lib/examples/getPropertyExample.ts +31 -0
  109. package/src/lib/examples/getPropertyExamples.ts +27 -0
  110. package/src/lib/examples/getSchemaExample.ts +38 -0
  111. package/src/lib/examples/getSchemaUiJson.ts +150 -0
  112. package/src/lib/examples/getSchemaUiXml.ts +9 -0
  113. package/src/lib/examples/hasExample.ts +26 -0
  114. package/src/lib/getOpenApiInstance.ts +39 -0
  115. package/src/lib/getSchemaUi.ts +280 -0
  116. package/src/lib/getSecurityUi.ts +33 -0
  117. package/src/lib/operationData.ts +24 -0
  118. package/src/lib/prepareOpenAPI/generateMissingOperationIds.ts +19 -0
  119. package/src/lib/prepareOpenAPI/generateMissingSummary.ts +20 -0
  120. package/src/lib/prepareOpenAPI/generateMissingTags.ts +36 -0
  121. package/src/lib/prepareOpenAPI/prepareOpenAPI.ts +35 -0
  122. package/src/lib/processOpenAPI.ts +131 -0
  123. package/src/lib/resolveCircularRef.ts +66 -0
  124. package/src/lib/sidebar/cleanSidebarItems.ts +19 -0
  125. package/src/lib/sidebar/ensureGroupTextSlashPrefix.ts +18 -0
  126. package/src/lib/sidebar/flatSidebarItems.ts +58 -0
  127. package/src/lib/sidebar/generateSidebarItemsByPaths.ts +132 -0
  128. package/src/lib/sidebar/mergeAdjacentGroups.ts +56 -0
  129. package/src/lib/sidebar/setItemCollapsedState.ts +15 -0
  130. package/src/lib/utils.ts +7 -0
  131. package/src/locales/en.json +50 -0
  132. package/src/locales/index.ts +4 -0
  133. package/src/style.css +180 -0
  134. package/src/types.ts +73 -0
  135. package/src/vite-env.d.ts +8 -0
@@ -0,0 +1,799 @@
1
+ import type { Ref, UnwrapNestedRefs } from 'vue'
2
+ import type { IOARequest } from '../lib/codeSamples/request'
3
+ import type { OperationSlot, ParsedOperation } from '../types'
4
+ import { useDark } from '@vueuse/core'
5
+ import vitesseDark from 'shiki/themes/vitesse-dark.mjs'
6
+ import vitesseLight from 'shiki/themes/vitesse-light.mjs'
7
+ import { ref } from 'vue'
8
+ import { generateCodeSample } from '../lib/codeSamples/generateCodeSample'
9
+ import { deepUnref } from '../lib/deepUnref'
10
+ import { locales } from '../locales'
11
+
12
+ export interface ThemeConfig {
13
+ highlighterTheme: {
14
+ light: any
15
+ dark: any
16
+ }
17
+ }
18
+
19
+ export interface PathConfig {
20
+ showBaseURL: Ref<boolean>
21
+ }
22
+
23
+ export interface RequestConfig {
24
+ defaultView: Ref<'schema' | 'contentType' | 'autogenerated'>
25
+ }
26
+
27
+ export interface JsonViewerConfig {
28
+ deep: Ref<number>
29
+ }
30
+
31
+ export interface SchemaViewerConfig {
32
+ deep: Ref<number>
33
+ }
34
+
35
+ export interface HeadingLevels {
36
+ h1: number
37
+ h2: number
38
+ h3: number
39
+ h4: number
40
+ h5: number
41
+ h6: number
42
+ }
43
+
44
+ export interface ResponseConfig {
45
+ responseCodeSelector: Ref<'tabs' | 'select'>
46
+ maxTabs: Ref<number>
47
+ }
48
+
49
+ type PlaygroundJsonEditorMode = 'text' | 'tree' | 'table'
50
+
51
+ export interface PlaygroundConfig {
52
+ jsonEditor: {
53
+ mode: Ref<PlaygroundJsonEditorMode>
54
+ mainMenuBar: Ref<boolean>
55
+ navigationBar: Ref<boolean>
56
+ }
57
+ }
58
+
59
+ export interface SecurityConfig {
60
+ defaultScheme: Ref<string | null>
61
+ }
62
+
63
+ type OperationBadges = 'deprecated' | 'operationId'
64
+
65
+ export interface OperationConfig {
66
+ badges?: Ref<OperationBadges[]>
67
+ slots?: Ref<OperationSlot[]>
68
+ hiddenSlots?: Ref<OperationSlot[]>
69
+ cols?: Ref<1 | 2>
70
+ defaultBaseUrl?: string
71
+ getServers?: GetServersFunction | null
72
+ }
73
+
74
+ export type Messages = Record<string, Record<string, string>>
75
+
76
+ export interface AvailableLocale {
77
+ code: string
78
+ label: string
79
+ }
80
+
81
+ export interface I18nConfig {
82
+ locale: Ref<string>
83
+ fallbackLocale: Ref<string>
84
+ messages: Messages
85
+ availableLocales?: AvailableLocale[]
86
+ regions?: Array<{ slug: string, name: string }>
87
+ locales?: Messages
88
+ }
89
+
90
+ export interface SpecConfig {
91
+ groupByTags?: Ref<boolean>
92
+ collapsePaths?: Ref<boolean>
93
+ showPathsSummary?: Ref<boolean>
94
+ avoidCirculars?: Ref<boolean>
95
+ lazyRendering?: Ref<boolean>
96
+ defaultTag?: string
97
+ defaultTagDescription?: string
98
+ wrapExamples?: boolean
99
+ }
100
+
101
+ export interface UseThemeConfig {
102
+ theme?: Partial<ThemeConfig>
103
+ path?: Partial<PathConfig>
104
+ requestBody?: Partial<RequestConfig>
105
+ jsonViewer?: Partial<JsonViewerConfig>
106
+ schemaViewer?: Partial<SchemaViewerConfig>
107
+ headingLevels?: Partial<HeadingLevels>
108
+ response?: Partial<ResponseConfig>
109
+ playground?: Partial<PlaygroundConfig>
110
+ security?: Partial<SecurityConfig>
111
+ operation?: Partial<OperationConfig>
112
+ i18n?: Partial<I18nConfig>
113
+ spec?: Partial<SpecConfig>
114
+ codeSamples?: Partial<CodeSamplesConfig>
115
+ linksPrefixes?: Partial<LinksPrefixesConfig>
116
+ }
117
+
118
+ export interface CodeSamplesConfig {
119
+ langs: string[]
120
+ defaultLang: string
121
+ availableLanguages: LanguageConfig[]
122
+ generator: GeneratorFunction
123
+ defaultHeaders: Record<string, string>
124
+ }
125
+
126
+ export interface LinksPrefixesConfig {
127
+ tags: string
128
+ operations: string
129
+ }
130
+
131
+ interface LanguageConfig {
132
+ lang: string
133
+ label: string
134
+ highlighter: string
135
+ }
136
+
137
+ export type PartialUseThemeConfig = Partial<UnwrapNestedRefs<UseThemeConfig>>
138
+
139
+ type GeneratorFunction = (lang: string, request: IOARequest) => string
140
+
141
+ type GetServersFunction = ({ method, path, operation }: {
142
+ method: string
143
+ path: string
144
+ operation: ParsedOperation
145
+ }) => string[] | null
146
+
147
+ export const DEFAULT_OPERATION_SLOTS: OperationSlot[] = [
148
+ 'header',
149
+ 'path',
150
+ 'description',
151
+ 'security',
152
+ 'parameters',
153
+ 'request-body',
154
+ 'responses',
155
+ 'try-it',
156
+ 'code-samples',
157
+ 'branding',
158
+ 'footer',
159
+ ]
160
+
161
+ export const DEFAULT_BASE_URL = 'http://localhost'
162
+
163
+ const availableLanguages: LanguageConfig[] = [
164
+ {
165
+ lang: 'curl',
166
+ label: 'cURL',
167
+ highlighter: 'bash',
168
+ },
169
+ {
170
+ lang: 'javascript',
171
+ label: 'JavaScript',
172
+ highlighter: 'javascript',
173
+ },
174
+ {
175
+ lang: 'php',
176
+ label: 'PHP',
177
+ highlighter: 'php',
178
+ },
179
+ {
180
+ lang: 'python',
181
+ label: 'Python',
182
+ highlighter: 'python',
183
+ },
184
+ ]
185
+
186
+ const themeConfig: UseThemeConfig = {
187
+ theme: {
188
+ highlighterTheme: {
189
+ light: vitesseLight,
190
+ dark: vitesseDark,
191
+ },
192
+ },
193
+ path: {
194
+ showBaseURL: ref<boolean>(false),
195
+ },
196
+ requestBody: {
197
+ defaultView: ref<'schema' | 'contentType' | 'autogenerated'>('contentType'),
198
+ },
199
+ jsonViewer: {
200
+ deep: ref<number>(Number.POSITIVE_INFINITY),
201
+ },
202
+ schemaViewer: {
203
+ deep: ref<number>(Number.POSITIVE_INFINITY),
204
+ },
205
+ headingLevels: {
206
+ h1: 1,
207
+ h2: 2,
208
+ h3: 3,
209
+ h4: 4,
210
+ h5: 5,
211
+ h6: 6,
212
+ },
213
+ response: {
214
+ responseCodeSelector: ref<'tabs' | 'select'>('tabs'),
215
+ maxTabs: ref<number>(5),
216
+ },
217
+ playground: {
218
+ jsonEditor: {
219
+ mode: ref<PlaygroundJsonEditorMode>('tree'),
220
+ mainMenuBar: ref<boolean>(false),
221
+ navigationBar: ref<boolean>(false),
222
+ },
223
+ },
224
+ security: {
225
+ defaultScheme: ref<string | null>(null),
226
+ },
227
+ operation: {
228
+ badges: ref<OperationBadges[]>(['deprecated']),
229
+ slots: ref(DEFAULT_OPERATION_SLOTS),
230
+ hiddenSlots: ref([]),
231
+ cols: ref(2),
232
+ defaultBaseUrl: DEFAULT_BASE_URL,
233
+ getServers: null,
234
+ },
235
+ i18n: {
236
+ locale: ref<string>('en'),
237
+ fallbackLocale: ref<string>('en'),
238
+ availableLocales: [],
239
+ regions: [],
240
+ },
241
+ spec: {
242
+ groupByTags: ref(true),
243
+ collapsePaths: ref(false),
244
+ showPathsSummary: ref(true),
245
+ avoidCirculars: ref(false),
246
+ lazyRendering: ref(false),
247
+ defaultTag: 'Default',
248
+ defaultTagDescription: '',
249
+ wrapExamples: true,
250
+ },
251
+ codeSamples: {
252
+ langs: [
253
+ 'curl',
254
+ 'javascript',
255
+ 'php',
256
+ 'python',
257
+ ],
258
+ defaultLang: 'curl',
259
+ availableLanguages,
260
+ generator: (lang: string, request: IOARequest) => generateCodeSample(lang, request),
261
+ defaultHeaders: {
262
+ 'Content-Type': 'application/json',
263
+ },
264
+ },
265
+ linksPrefixes: {
266
+ tags: '/tags/',
267
+ operations: '/operations/',
268
+ },
269
+ }
270
+
271
+ if (!themeConfig.i18n?.locales && themeConfig.i18n) {
272
+ themeConfig.i18n.messages = locales
273
+ }
274
+
275
+ const defaultThemeConfig: UnwrapNestedRefs<UseThemeConfig> = { ...deepUnref(themeConfig) } as PartialUseThemeConfig
276
+
277
+ const isDark = useDark({
278
+ storageKey: 'vitepress-theme-appearance',
279
+ })
280
+
281
+ export function useTheme(initialConfig: PartialUseThemeConfig = {}) {
282
+ setConfig(initialConfig)
283
+
284
+ function setConfig(config: PartialUseThemeConfig) {
285
+ if (!config || !Object.keys(config).length) {
286
+ return
287
+ }
288
+
289
+ if (config?.theme?.highlighterTheme) {
290
+ setHighlighterTheme(config.theme.highlighterTheme)
291
+ }
292
+
293
+ if (config?.requestBody?.defaultView !== undefined) {
294
+ setSchemaDefaultView(config.requestBody.defaultView)
295
+ }
296
+
297
+ if (config?.path?.showBaseURL !== undefined) {
298
+ setShowBaseURL(config.path.showBaseURL)
299
+ }
300
+
301
+ if (config?.jsonViewer?.deep !== undefined) {
302
+ setJsonViewerDeep(config.jsonViewer.deep)
303
+ }
304
+
305
+ if (config?.schemaViewer?.deep !== undefined) {
306
+ setSchemaViewerDeep(config.schemaViewer.deep)
307
+ }
308
+
309
+ if (config?.headingLevels !== undefined) {
310
+ setHeadingLevels(config.headingLevels)
311
+ }
312
+
313
+ if (config?.response?.responseCodeSelector !== undefined) {
314
+ setResponseCodeSelector(config.response.responseCodeSelector)
315
+ }
316
+
317
+ if (config?.response?.maxTabs !== undefined) {
318
+ setResponseCodeMaxTabs(config.response.maxTabs)
319
+ }
320
+
321
+ if (config?.playground?.jsonEditor?.mode !== undefined) {
322
+ setPlaygroundJsonEditorMode(config.playground.jsonEditor.mode)
323
+ }
324
+
325
+ if (config?.playground?.jsonEditor?.mainMenuBar !== undefined) {
326
+ setPlaygroundJsonEditorMainMenuBar(config.playground.jsonEditor.mainMenuBar)
327
+ }
328
+
329
+ if (config?.playground?.jsonEditor?.navigationBar !== undefined) {
330
+ setPlaygroundJsonEditorNavigationBar(config.playground.jsonEditor.navigationBar)
331
+ }
332
+
333
+ if (config?.security?.defaultScheme !== undefined) {
334
+ setSecurityDefaultScheme(config.security.defaultScheme)
335
+ }
336
+
337
+ if (config?.operation?.badges !== undefined) {
338
+ setOperationBadges(config.operation.badges)
339
+ }
340
+
341
+ if (config?.operation?.slots !== undefined) {
342
+ setOperationSlots(config.operation.slots)
343
+ }
344
+
345
+ if (config?.operation?.hiddenSlots !== undefined) {
346
+ setOperationHiddenSlots(config.operation.hiddenSlots)
347
+ }
348
+
349
+ if (config?.operation?.cols !== undefined) {
350
+ setOperationCols(config.operation.cols)
351
+ }
352
+
353
+ if (config?.operation?.defaultBaseUrl !== undefined) {
354
+ setOperationDefaultBaseUrl(config.operation.defaultBaseUrl)
355
+ }
356
+
357
+ if (config?.operation?.getServers !== undefined) {
358
+ setOperationServers(config.operation.getServers)
359
+ }
360
+
361
+ if (config?.i18n !== undefined) {
362
+ setI18nConfig(config.i18n)
363
+ }
364
+
365
+ if (config?.spec !== undefined) {
366
+ setSpecConfig(config.spec)
367
+ }
368
+
369
+ if (config?.codeSamples !== undefined) {
370
+ setCodeSamplesConfig(config.codeSamples)
371
+ }
372
+
373
+ if (config?.linksPrefixes !== undefined) {
374
+ setLinksPrefixesConfig(config.linksPrefixes)
375
+ }
376
+ }
377
+
378
+ function reset() {
379
+ setConfig(defaultThemeConfig)
380
+ }
381
+
382
+ function getState() {
383
+ return deepUnref(themeConfig)
384
+ }
385
+
386
+ function getLocale(): string {
387
+ return themeConfig?.i18n?.locale?.value || 'en'
388
+ }
389
+
390
+ /**
391
+ * @deprecated Use `setI18nConfig({ locale: value })` instead.
392
+ */
393
+ function setLocale(value: string) {
394
+ console.warn('`setLocale` is deprecated. Use `setI18nConfig({ locale: value })` instead.')
395
+ // @ts-expect-error: This is a valid expression.
396
+ themeConfig.i18n.locale.value = value
397
+ }
398
+
399
+ function getHighlighterTheme() {
400
+ return themeConfig?.theme?.highlighterTheme
401
+ }
402
+
403
+ function setHighlighterTheme(value: ThemeConfig['highlighterTheme']) {
404
+ // @ts-expect-error: This is a valid expression.
405
+ themeConfig.theme.highlighterTheme = {
406
+ ...themeConfig?.theme?.highlighterTheme,
407
+ ...value,
408
+ }
409
+ }
410
+
411
+ function getSchemaDefaultView(): 'schema' | 'contentType' | 'autogenerated' | undefined {
412
+ return themeConfig?.requestBody?.defaultView?.value
413
+ }
414
+
415
+ function setSchemaDefaultView(value: 'schema' | 'contentType' | 'autogenerated') {
416
+ // @ts-expect-error: This is a valid expression.
417
+ themeConfig.requestBody.defaultView.value = value
418
+ }
419
+
420
+ function getShowBaseURL(): boolean | undefined {
421
+ return themeConfig?.path?.showBaseURL?.value
422
+ }
423
+
424
+ function setShowBaseURL(value: boolean) {
425
+ // @ts-expect-error: This is a valid expression.
426
+ themeConfig.path.showBaseURL.value = value
427
+ }
428
+
429
+ function getJsonViewerDeep(): number | undefined {
430
+ return themeConfig?.jsonViewer?.deep?.value
431
+ }
432
+
433
+ function setJsonViewerDeep(value: number) {
434
+ // @ts-expect-error: This is a valid expression.
435
+ themeConfig.jsonViewer.deep.value = value
436
+ }
437
+
438
+ function getSchemaViewerDeep(): number | undefined {
439
+ return themeConfig?.schemaViewer?.deep?.value
440
+ }
441
+
442
+ function setSchemaViewerDeep(value: number) {
443
+ // @ts-expect-error: This is a valid expression.
444
+ themeConfig.schemaViewer.deep.value = value
445
+ }
446
+
447
+ function getHeadingLevels() {
448
+ return themeConfig.headingLevels
449
+ }
450
+
451
+ function getHeadingLevel(level: keyof HeadingLevels): `h${1 | 2 | 3 | 4 | 5 | 6}` {
452
+ if (!themeConfig.headingLevels) {
453
+ return `h${level}` as 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
454
+ }
455
+
456
+ const headingLevel = themeConfig.headingLevels[level] as number
457
+
458
+ if (headingLevel < 1 || headingLevel > 6) {
459
+ throw new Error(`Heading level for ${level} must be between 1 and 6.`)
460
+ }
461
+
462
+ return `h${headingLevel}` as 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
463
+ }
464
+
465
+ function setHeadingLevels(levels: Partial<UnwrapNestedRefs<HeadingLevels>>) {
466
+ if (!themeConfig.headingLevels) {
467
+ themeConfig.headingLevels = {}
468
+ }
469
+
470
+ for (const key of Object.keys(levels)) {
471
+ const value = levels[key as keyof HeadingLevels] as number
472
+
473
+ if (value < 1 || value > 6) {
474
+ throw new Error(`Heading level for ${key} must be between 1 and 6.`)
475
+ }
476
+ }
477
+
478
+ Object.assign(themeConfig.headingLevels, levels)
479
+ }
480
+
481
+ function getResponseCodeSelector(): 'tabs' | 'select' | undefined {
482
+ return themeConfig?.response?.responseCodeSelector?.value
483
+ }
484
+
485
+ function setResponseCodeSelector(value: 'tabs' | 'select') {
486
+ // @ts-expect-error: This is a valid expression.
487
+ themeConfig.response.responseCodeSelector.value = value
488
+ }
489
+
490
+ function getResponseCodeMaxTabs(): number | undefined {
491
+ return themeConfig?.response?.maxTabs?.value
492
+ }
493
+
494
+ function setResponseCodeMaxTabs(value: number) {
495
+ // @ts-expect-error: This is a valid expression.
496
+ themeConfig.response.maxTabs.value = value
497
+ }
498
+
499
+ function getPlaygroundJsonEditorMode(): PlaygroundJsonEditorMode | undefined {
500
+ return themeConfig?.playground?.jsonEditor?.mode.value
501
+ }
502
+
503
+ function setPlaygroundJsonEditorMode(value: PlaygroundJsonEditorMode) {
504
+ // @ts-expect-error: This is a valid expression.
505
+ themeConfig.playground.jsonEditor.mode.value = value
506
+ }
507
+
508
+ function getPlaygroundJsonEditorMainMenuBar(): boolean | undefined {
509
+ return themeConfig?.playground?.jsonEditor?.mainMenuBar?.value
510
+ }
511
+
512
+ function setPlaygroundJsonEditorMainMenuBar(value: boolean) {
513
+ // @ts-expect-error: This is a valid expression.
514
+ themeConfig.playground.jsonEditor.mainMenuBar.value = value
515
+ }
516
+
517
+ function getPlaygroundJsonEditorNavigationBar(): boolean | undefined {
518
+ return themeConfig?.playground?.jsonEditor?.navigationBar.value
519
+ }
520
+
521
+ function setPlaygroundJsonEditorNavigationBar(value: boolean) {
522
+ // @ts-expect-error: This is a valid expression.
523
+ themeConfig.playground.jsonEditor.navigationBar.value = value
524
+ }
525
+
526
+ function getSecurityDefaultScheme(): string | null | undefined {
527
+ return themeConfig?.security?.defaultScheme?.value
528
+ }
529
+
530
+ function setSecurityDefaultScheme(value: string | null) {
531
+ // @ts-expect-error: This is a valid expression.
532
+ themeConfig.security.defaultScheme.value = value
533
+ }
534
+
535
+ function getOperationBadges(): OperationBadges[] {
536
+ return [...(themeConfig?.operation?.badges?.value || [])]
537
+ }
538
+
539
+ function setOperationBadges(value: OperationBadges[]) {
540
+ // @ts-expect-error: This is a valid expression.
541
+ themeConfig.operation.badges.value = value
542
+ }
543
+
544
+ function getOperationSlots(): OperationSlot[] | undefined {
545
+ return themeConfig?.operation?.slots?.value
546
+ }
547
+
548
+ function setOperationSlots(value: OperationSlot[]) {
549
+ // @ts-expect-error: This is a valid expression.
550
+ themeConfig.operation.slots.value = value
551
+ }
552
+
553
+ function getOperationHiddenSlots(): OperationSlot[] | undefined {
554
+ return themeConfig?.operation?.hiddenSlots?.value
555
+ }
556
+
557
+ function setOperationHiddenSlots(value: OperationSlot[]) {
558
+ // @ts-expect-error: This is a valid expression.
559
+ themeConfig.operation.hiddenSlots.value = value
560
+ }
561
+
562
+ function getOperationCols(): 1 | 2 | undefined {
563
+ return themeConfig?.operation?.cols?.value
564
+ }
565
+
566
+ function setOperationCols(value: number) {
567
+ // @ts-expect-error: This is a valid expression.
568
+ themeConfig.operation.cols.value = value
569
+ }
570
+
571
+ function getOperationDefaultBaseUrl(): string {
572
+ return themeConfig?.operation?.defaultBaseUrl || DEFAULT_BASE_URL
573
+ }
574
+
575
+ function setOperationDefaultBaseUrl(value: string) {
576
+ // @ts-expect-error: This is a valid expression.
577
+ themeConfig.operation.defaultBaseUrl = value
578
+ }
579
+
580
+ function getOperationServers(): GetServersFunction | null {
581
+ return themeConfig?.operation?.getServers || null
582
+ }
583
+
584
+ function setOperationServers(value: GetServersFunction | null) {
585
+ // @ts-expect-error: This is a valid expression.
586
+ themeConfig.operation.getServers = value
587
+ }
588
+
589
+ function getI18nConfig(): I18nConfig {
590
+ return themeConfig.i18n as I18nConfig
591
+ }
592
+
593
+ function setI18nConfig(config: Partial<UnwrapNestedRefs<I18nConfig>>) {
594
+ if (config.locale) {
595
+ // @ts-expect-error: This is a valid expression.
596
+ themeConfig.i18n.locale.value = config.locale
597
+ }
598
+
599
+ if (config.fallbackLocale) {
600
+ // @ts-expect-error: This is a valid expression.
601
+ themeConfig.i18n.fallbackLocale.value = config.fallbackLocale
602
+ }
603
+
604
+ if (config.messages) {
605
+ // @ts-expect-error: This is a valid expression.
606
+ themeConfig.i18n.messages = config.messages
607
+ }
608
+
609
+ if (config.availableLocales) {
610
+ // @ts-expect-error: This is a valid expression.
611
+ themeConfig.i18n.availableLocales = config.availableLocales
612
+ }
613
+
614
+ if (config.regions) {
615
+ // @ts-expect-error: This is a valid expression.
616
+ themeConfig.i18n.regions = config.regions
617
+ // @ts-expect-error: This is a valid expression.
618
+ themeConfig.i18n.availableLocales = config.regions.map(({ slug, name }) => ({ code: slug, label: name }))
619
+ }
620
+ }
621
+
622
+ function getSpecConfig() {
623
+ return themeConfig.spec
624
+ }
625
+
626
+ function getWrapExamples() {
627
+ return themeConfig?.spec?.wrapExamples
628
+ }
629
+
630
+ function setSpecConfig(config: Partial<UnwrapNestedRefs<SpecConfig>>) {
631
+ if (!themeConfig.spec) {
632
+ themeConfig.spec = {}
633
+ }
634
+
635
+ if (config.groupByTags !== undefined) {
636
+ // @ts-expect-error: This is a valid expression.
637
+ themeConfig.spec.groupByTags.value = config.groupByTags
638
+ }
639
+
640
+ if (config.collapsePaths !== undefined) {
641
+ // @ts-expect-error: This is a valid expression.
642
+ themeConfig.spec.collapsePaths.value = config.collapsePaths
643
+ }
644
+
645
+ if (config.showPathsSummary !== undefined) {
646
+ // @ts-expect-error: This is a valid expression.
647
+ themeConfig.spec.showPathsSummary.value = config.showPathsSummary
648
+ }
649
+
650
+ if (config.avoidCirculars !== undefined) {
651
+ // @ts-expect-error: This is a valid expression.
652
+ themeConfig.spec.avoidCirculars.value = config.avoidCirculars
653
+ }
654
+
655
+ if (config.lazyRendering !== undefined) {
656
+ // @ts-expect-error: This is a valid expression.
657
+ themeConfig.spec.lazyRendering.value = config.lazyRendering
658
+ }
659
+
660
+ if (config.defaultTag !== undefined) {
661
+ themeConfig.spec.defaultTag = config.defaultTag
662
+ }
663
+
664
+ if (config.defaultTagDescription !== undefined) {
665
+ themeConfig.spec.defaultTagDescription = config.defaultTagDescription
666
+ }
667
+
668
+ if (config.wrapExamples !== undefined) {
669
+ themeConfig.spec.wrapExamples = config.wrapExamples
670
+ }
671
+ }
672
+
673
+ function getCodeSamplesLangs() {
674
+ return themeConfig?.codeSamples?.langs
675
+ }
676
+
677
+ function getCodeSamplesDefaultLang() {
678
+ return themeConfig?.codeSamples?.defaultLang
679
+ }
680
+
681
+ function getCodeSamplesAvailableLanguages() {
682
+ return themeConfig?.codeSamples?.availableLanguages
683
+ }
684
+
685
+ function getCodeSamplesGenerator() {
686
+ return themeConfig?.codeSamples?.generator
687
+ }
688
+
689
+ function getCodeSamplesDefaultHeaders() {
690
+ return themeConfig?.codeSamples?.defaultHeaders
691
+ }
692
+
693
+ function setCodeSamplesConfig(config: Partial<UnwrapNestedRefs<CodeSamplesConfig>>) {
694
+ if (config.langs) {
695
+ // @ts-expect-error: This is a valid expression.
696
+ themeConfig.codeSamples.langs = config.langs
697
+ }
698
+
699
+ if (config.defaultLang) {
700
+ // @ts-expect-error: This is a valid expression.
701
+ themeConfig.codeSamples.defaultLang = config.defaultLang
702
+ }
703
+
704
+ if (config.availableLanguages) {
705
+ // @ts-expect-error: This is a valid expression.
706
+ themeConfig.codeSamples.availableLanguages = config.availableLanguages
707
+ }
708
+
709
+ if (config.generator) {
710
+ // @ts-expect-error: This is a valid expression.
711
+ themeConfig.codeSamples.generator = config.generator
712
+ }
713
+
714
+ if (config.defaultHeaders) {
715
+ // @ts-expect-error: This is a valid expression.
716
+ themeConfig.codeSamples.defaultHeaders = config.defaultHeaders
717
+ }
718
+ }
719
+
720
+ function getLinksPrefixesConfig() {
721
+ return themeConfig.linksPrefixes
722
+ }
723
+
724
+ function setLinksPrefixesConfig(config: Partial<UnwrapNestedRefs<LinksPrefixesConfig>>) {
725
+ if (config.tags) {
726
+ (themeConfig.linksPrefixes as LinksPrefixesConfig).tags = config.tags
727
+ }
728
+
729
+ if (config.operations) {
730
+ (themeConfig.linksPrefixes as LinksPrefixesConfig).operations = config.operations
731
+ }
732
+ }
733
+
734
+ function getTagsLinkPrefix() {
735
+ return themeConfig?.linksPrefixes?.tags
736
+ }
737
+
738
+ function getOperationsLinkPrefix() {
739
+ return themeConfig?.linksPrefixes?.operations
740
+ }
741
+
742
+ return {
743
+ schemaConfig: themeConfig.requestBody,
744
+ reset,
745
+ getState,
746
+ getLocale,
747
+ setLocale,
748
+ getHighlighterTheme,
749
+ getSchemaDefaultView,
750
+ setSchemaDefaultView,
751
+ getShowBaseURL,
752
+ setShowBaseURL,
753
+ getJsonViewerDeep,
754
+ setJsonViewerDeep,
755
+ getSchemaViewerDeep,
756
+ setSchemaViewerDeep,
757
+ getHeadingLevels,
758
+ getHeadingLevel,
759
+ setHeadingLevels,
760
+ getResponseCodeSelector,
761
+ setResponseCodeSelector,
762
+ getResponseCodeMaxTabs,
763
+ setResponseCodeMaxTabs,
764
+ getPlaygroundJsonEditorMode,
765
+ setPlaygroundJsonEditorMode,
766
+ getPlaygroundJsonEditorMainMenuBar,
767
+ setPlaygroundJsonEditorMainMenuBar,
768
+ getPlaygroundJsonEditorNavigationBar,
769
+ setPlaygroundJsonEditorNavigationBar,
770
+ getSecurityDefaultScheme,
771
+ setSecurityDefaultScheme,
772
+ getOperationBadges,
773
+ setOperationBadges,
774
+ getOperationSlots,
775
+ setOperationSlots,
776
+ getOperationHiddenSlots,
777
+ setOperationHiddenSlots,
778
+ getOperationCols,
779
+ setOperationCols,
780
+ getOperationDefaultBaseUrl,
781
+ getOperationServers,
782
+ getI18nConfig,
783
+ setI18nConfig,
784
+ getSpecConfig,
785
+ getWrapExamples,
786
+ setSpecConfig,
787
+ getCodeSamplesLangs,
788
+ getCodeSamplesDefaultLang,
789
+ getCodeSamplesAvailableLanguages,
790
+ getCodeSamplesGenerator,
791
+ getCodeSamplesDefaultHeaders,
792
+ setCodeSamplesConfig,
793
+ getLinksPrefixesConfig,
794
+ setLinksPrefixesConfig,
795
+ getTagsLinkPrefix,
796
+ getOperationsLinkPrefix,
797
+ isDark,
798
+ }
799
+ }