vitepress-openapi 0.0.3-alpha.49 → 0.0.3-alpha.50

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitepress-openapi",
3
3
  "type": "module",
4
- "version": "0.0.3-alpha.49",
4
+ "version": "0.0.3-alpha.50",
5
5
  "homepage": "https://vitepress-openapi.vercel.app/",
6
6
  "repository": {
7
7
  "type": "git",
@@ -3,6 +3,7 @@ import { computed, inject, useSlots } from 'vue'
3
3
  import { getOpenApiInstance } from '../../lib/getOpenApiInstance'
4
4
  import OAHeaderBadges from '../Common/OAHeaderBadges.vue'
5
5
  import type { OperationSlot } from '../../types'
6
+ import OAOperationTags from './OAOperationTags.vue'
6
7
 
7
8
  const props = defineProps({
8
9
  operationId: {
@@ -110,6 +111,24 @@ function hasSlot(name: OperationSlot): boolean {
110
111
  </div>
111
112
  </template>
112
113
 
114
+ <template
115
+ v-if="hasSlot('tags')"
116
+ #tags="tags"
117
+ >
118
+ <slot
119
+ name="tags"
120
+ v-bind="tags"
121
+ />
122
+ </template>
123
+ <template
124
+ v-else
125
+ #tags="tags"
126
+ >
127
+ <OAOperationTags
128
+ :tags="tags.operation.tags"
129
+ />
130
+ </template>
131
+
113
132
  <template
114
133
  v-if="hasSlot('description')"
115
134
  #description="description"
@@ -0,0 +1,30 @@
1
+ <script setup lang="ts">
2
+ import { Badge } from '../ui/badge'
3
+ import { useTheme } from '../../composables/useTheme'
4
+
5
+ const props = defineProps({
6
+ tags: {
7
+ type: Array,
8
+ required: true,
9
+ },
10
+ })
11
+
12
+ const themeConfig = useTheme()
13
+
14
+ const prefix = themeConfig.getTagsLinkPrefix()
15
+ </script>
16
+
17
+ <template>
18
+ <div class="flex flex-wrap gap-2">
19
+ <a
20
+ v-for="(tag, index) in props.tags"
21
+ :key="index"
22
+ :href="`${prefix}${tag}`"
23
+ :aria-label="$t('tags.goTo', { tag })"
24
+ >
25
+ <Badge variant="outline">
26
+ {{ tag }}
27
+ </Badge>
28
+ </a>
29
+ </div>
30
+ </template>
@@ -70,7 +70,7 @@ function updateRequest(newRequest) {
70
70
  <div>
71
71
  <div
72
72
  v-if="operation"
73
- class="OAPath flex flex-col space-y-8"
73
+ class="OAPath flex flex-col space-y-4"
74
74
  >
75
75
  <template v-if="operationSlots.includes('header')">
76
76
  <slot
@@ -83,6 +83,17 @@ function updateRequest(newRequest) {
83
83
  />
84
84
  </template>
85
85
 
86
+ <template v-if="operationSlots.includes('tags')">
87
+ <slot
88
+ name="tags"
89
+ :operation="operation"
90
+ :method="operationMethod"
91
+ :base-url="baseUrl"
92
+ :path="operationPath"
93
+ :tags="operation.tags"
94
+ />
95
+ </template>
96
+
86
97
  <div
87
98
  :class="{
88
99
  'sm:grid-cols-1': operationCols === 1,
@@ -86,7 +86,17 @@ const selectedSchemeName = computed(() => {
86
86
  })
87
87
 
88
88
  const selectedScheme = computed(() => {
89
- return props.securitySchemes[selectedSchemeName.value]
89
+ const scheme = props.securitySchemes[selectedSchemeName.value]
90
+
91
+ if (!scheme) {
92
+ if (!Object.keys(props.securitySchemes).length) {
93
+ return null
94
+ }
95
+
96
+ return props.securitySchemes[Object.keys(props.securitySchemes)[0]]
97
+ }
98
+
99
+ return scheme
90
100
  })
91
101
 
92
102
  const authScheme = ref<PlaygroundSecurityScheme | null>(null)
@@ -103,6 +103,7 @@ export interface UseThemeConfig {
103
103
  i18n?: Partial<I18nConfig>
104
104
  spec?: Partial<SpecConfig>
105
105
  codeSamples?: Partial<CodeSamplesConfig>
106
+ linksPrefixes?: Partial<LinksPrefixesConfig>
106
107
  }
107
108
 
108
109
  export interface UseThemeConfigUnref {
@@ -144,6 +145,7 @@ export interface UseThemeConfigUnref {
144
145
  i18n?: Partial<I18nConfig>
145
146
  spec?: Partial<SpecConfig>
146
147
  codeSamples?: Partial<CodeSamplesConfig>
148
+ linksPrefixes?: Partial<LinksPrefixesConfig>
147
149
  }
148
150
 
149
151
  export interface CodeSamplesConfig {
@@ -154,6 +156,11 @@ export interface CodeSamplesConfig {
154
156
  defaultHeaders: Record<string, string>
155
157
  }
156
158
 
159
+ export interface LinksPrefixesConfig {
160
+ tags: string
161
+ operations: string
162
+ }
163
+
157
164
  interface LanguageConfig {
158
165
  lang: string
159
166
  label: string
@@ -275,12 +282,18 @@ const themeConfig: UseThemeConfig = {
275
282
  'Content-Type': 'application/json',
276
283
  },
277
284
  },
285
+ linksPrefixes: {
286
+ tags: '/tags/',
287
+ operations: '/operations/',
288
+ },
278
289
  }
279
290
 
280
291
  const defaultThemeConfig: UseThemeConfigUnref = { ...deepUnref(themeConfig) } as UseThemeConfigUnref
281
292
 
282
- export function useTheme(config: Partial<UseThemeConfigUnref> = {}) {
283
- if (Object.keys(config).length) {
293
+ export function useTheme(initialConfig: Partial<UseThemeConfigUnref> = {}) {
294
+ setConfig(initialConfig)
295
+
296
+ function setConfig(config: Partial<UseThemeConfigUnref>) {
284
297
  if (config?.theme?.highlighterTheme) {
285
298
  // @ts-expect-error: This is a valid expression.
286
299
  themeConfig.theme.highlighterTheme = {
@@ -364,10 +377,14 @@ export function useTheme(config: Partial<UseThemeConfigUnref> = {}) {
364
377
  if (config?.codeSamples !== undefined) {
365
378
  setCodeSamplesConfig(config.codeSamples)
366
379
  }
380
+
381
+ if (config?.linksPrefixes !== undefined) {
382
+ setLinksPrefixesConfig(config.linksPrefixes)
383
+ }
367
384
  }
368
385
 
369
386
  function reset() {
370
- useTheme({ ...defaultThemeConfig })
387
+ setConfig(defaultThemeConfig)
371
388
  }
372
389
 
373
390
  function getState() {
@@ -671,6 +688,28 @@ export function useTheme(config: Partial<UseThemeConfigUnref> = {}) {
671
688
  }
672
689
  }
673
690
 
691
+ function getLinksPrefixesConfig() {
692
+ return themeConfig.linksPrefixes
693
+ }
694
+
695
+ function setLinksPrefixesConfig(config: Partial<LinksPrefixesConfig>) {
696
+ if (config.tags) {
697
+ (themeConfig.linksPrefixes as LinksPrefixesConfig).tags = config.tags
698
+ }
699
+
700
+ if (config.operations) {
701
+ (themeConfig.linksPrefixes as LinksPrefixesConfig).operations = config.operations
702
+ }
703
+ }
704
+
705
+ function getTagsLinkPrefix() {
706
+ return themeConfig?.linksPrefixes?.tags
707
+ }
708
+
709
+ function getOperationsLinkPrefix() {
710
+ return themeConfig?.linksPrefixes?.operations
711
+ }
712
+
674
713
  return {
675
714
  schemaConfig: themeConfig.requestBody,
676
715
  reset,
@@ -721,5 +760,9 @@ export function useTheme(config: Partial<UseThemeConfigUnref> = {}) {
721
760
  getCodeSamplesGenerator,
722
761
  getCodeSamplesDefaultHeaders,
723
762
  setCodeSamplesConfig,
763
+ getLinksPrefixesConfig,
764
+ setLinksPrefixesConfig,
765
+ getTagsLinkPrefix,
766
+ getOperationsLinkPrefix,
724
767
  }
725
768
  }
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import * as VueI18n from 'vue-i18n'
2
2
  import type { EnhanceAppContext, Theme } from 'vitepress/client'
3
3
  import type { Component } from 'vue'
4
4
  import type { Awaitable } from 'vitepress'
5
- import { useTheme } from './composables/useTheme'
5
+ import { DEFAULT_OPERATION_SLOTS, useTheme } from './composables/useTheme'
6
6
  import { useShiki } from './composables/useShiki'
7
7
  import * as components from './components'
8
8
 
@@ -12,6 +12,7 @@ import 'tailwindcss/tailwind.css'
12
12
  import './style.css'
13
13
  import './json.css'
14
14
 
15
+ export { DEFAULT_OPERATION_SLOTS }
15
16
  export { useSidebar } from './composables/useSidebar'
16
17
  export { useOpenapi } from './composables/useOpenapi'
17
18
  export { useTheme } from './composables/useTheme'
@@ -40,5 +40,6 @@
40
40
  "Show operations": "Show operations",
41
41
  "Operations": "Operations",
42
42
  "Default": "Default",
43
- "Example": "Example"
43
+ "Example": "Example",
44
+ "tags.goTo": "View {tag} operations"
44
45
  }
@@ -40,5 +40,6 @@
40
40
  "Show operations": "Mostrar operaciones",
41
41
  "Operations": "Operaciones",
42
42
  "Default": "Por defecto",
43
- "Example": "Ejemplo"
43
+ "Example": "Ejemplo",
44
+ "tags.goTo": "Ver operaciones de {tag}"
44
45
  }
package/src/types.ts CHANGED
@@ -6,6 +6,7 @@ import type { RemovableRef } from '@vueuse/core'
6
6
  */
7
7
  export type OperationSlot =
8
8
  | 'header'
9
+ | 'tags'
9
10
  | 'path'
10
11
  | 'description'
11
12
  | 'security'
@@ -18,7 +19,6 @@ export type OperationSlot =
18
19
  | 'footer'
19
20
  // TODO: Implement these slots.
20
21
  // | 'summary'
21
- // | 'tags'
22
22
  // | 'servers'
23
23
 
24
24
  export type ParsedOpenAPI = OpenAPI.Document & {