@datagouv/components-next 1.0.2-dev.9 → 1.1.1

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 (83) hide show
  1. package/assets/main.css +4 -0
  2. package/dist/Datafair.client-BzW-ctDf.js +30 -0
  3. package/dist/JsonPreview.client-BfMSzR07.js +40 -0
  4. package/dist/{MapContainer.client-CUmKyByc.js → MapContainer.client-CLs-im9i.js} +34 -39
  5. package/dist/{PdfPreview.client-BVjPxlPu.js → PdfPreview.client-C13PQCU_.js} +822 -865
  6. package/dist/{Pmtiles.client-CRJ56yX2.js → Pmtiles.client-CL7PXXDl.js} +574 -579
  7. package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-C6XnsZ-7.js +61 -0
  8. package/dist/XmlPreview.client-KaENrbbG.js +34 -0
  9. package/dist/components-next.css +3 -3
  10. package/dist/components-next.js +166 -148
  11. package/dist/components.css +1 -1
  12. package/dist/{index-BZsAZ7iw.js → index-C7WVVGgD.js} +1 -1
  13. package/dist/{main-qc4CO9Kn.js → main-K-42Oe8-.js} +91315 -75834
  14. package/dist/{vue3-xml-viewer.common-CCOV_ohP.js → vue3-xml-viewer.common-sHPSE-jD.js} +1 -1
  15. package/package.json +17 -10
  16. package/src/components/ActivityList/ActivityList.vue +0 -2
  17. package/src/components/Chart/ChartViewer.vue +226 -0
  18. package/src/components/Chart/ChartViewerWrapper.vue +170 -0
  19. package/src/components/Form/Listbox.vue +101 -0
  20. package/src/components/Form/SearchableSelect.vue +2 -1
  21. package/src/components/InfiniteLoader.vue +53 -0
  22. package/src/components/OpenApiViewer/ContentTypeSelect.vue +48 -0
  23. package/src/components/OpenApiViewer/EndpointRequest.vue +164 -0
  24. package/src/components/OpenApiViewer/EndpointResponses.vue +149 -0
  25. package/src/components/OpenApiViewer/OpenApiViewer.vue +308 -0
  26. package/src/components/OpenApiViewer/SchemaPanel.vue +53 -0
  27. package/src/components/OpenApiViewer/SchemaTree.vue +77 -0
  28. package/src/components/OpenApiViewer/openapi.ts +150 -0
  29. package/src/components/OrganizationNameWithCertificate.vue +3 -2
  30. package/src/components/Pagination.vue +8 -5
  31. package/src/components/ReadMore.vue +1 -1
  32. package/src/components/ResourceAccordion/Datafair.client.vue +4 -10
  33. package/src/components/ResourceAccordion/JsonPreview.client.vue +23 -121
  34. package/src/components/ResourceAccordion/MapContainer.client.vue +4 -11
  35. package/src/components/ResourceAccordion/Metadata.vue +1 -2
  36. package/src/components/ResourceAccordion/PdfPreview.client.vue +24 -103
  37. package/src/components/ResourceAccordion/Pmtiles.client.vue +5 -10
  38. package/src/components/ResourceAccordion/Preview.vue +16 -21
  39. package/src/components/ResourceAccordion/PreviewLoader.vue +1 -2
  40. package/src/components/ResourceAccordion/PreviewUnavailable.vue +22 -0
  41. package/src/components/ResourceAccordion/PreviewWrapper.vue +82 -0
  42. package/src/components/ResourceAccordion/ResourceAccordion.vue +5 -7
  43. package/src/components/ResourceAccordion/XmlPreview.client.vue +16 -115
  44. package/src/components/ResourceExplorer/ResourceExplorer.vue +81 -13
  45. package/src/components/ResourceExplorer/ResourceExplorerSidebar.vue +2 -2
  46. package/src/components/ResourceExplorer/ResourceExplorerViewer.vue +30 -11
  47. package/src/components/Search/GlobalSearch.vue +173 -108
  48. package/src/components/Search/SearchInput.vue +3 -3
  49. package/src/components/TabularExplorer/TabularCell.vue +51 -0
  50. package/src/components/TabularExplorer/TabularCellPopover.vue +170 -0
  51. package/src/components/TabularExplorer/TabularExplorer.vue +870 -0
  52. package/src/components/TabularExplorer/TabularFilterContent.vue +351 -0
  53. package/src/components/TabularExplorer/TabularFilterPopover.vue +111 -0
  54. package/src/components/TabularExplorer/types.ts +83 -0
  55. package/src/composables/useHasTabularData.ts +6 -0
  56. package/src/composables/useResourceCapabilities.ts +1 -1
  57. package/src/composables/useSearchFilter.ts +118 -0
  58. package/src/composables/useStableQueryParams.ts +31 -3
  59. package/src/config.ts +3 -0
  60. package/src/functions/api.ts +34 -33
  61. package/src/functions/api.types.ts +1 -0
  62. package/src/functions/charts.ts +68 -0
  63. package/src/functions/datasets.ts +0 -17
  64. package/src/functions/resources.ts +56 -1
  65. package/src/functions/tabular.ts +60 -0
  66. package/src/functions/tabularApi.ts +138 -11
  67. package/src/main.ts +55 -7
  68. package/src/types/dataservices.ts +2 -0
  69. package/src/types/pages.ts +0 -5
  70. package/src/types/posts.ts +2 -2
  71. package/src/types/reports.ts +5 -1
  72. package/src/types/search.ts +52 -1
  73. package/src/types/site.ts +5 -3
  74. package/src/types/users.ts +2 -1
  75. package/src/types/visualizations.ts +89 -0
  76. package/assets/swagger-themes/newspaper.css +0 -1670
  77. package/dist/Datafair.client-0UYUu5yf.js +0 -35
  78. package/dist/JsonPreview.client-BrTMBWHZ.js +0 -87
  79. package/dist/Swagger.client-2Yn7iF0A.js +0 -4
  80. package/dist/XmlPreview.client-DxqlVnKu.js +0 -79
  81. package/src/components/ResourceAccordion/Swagger.client.vue +0 -48
  82. package/src/functions/pagination.ts +0 -9
  83. /package/assets/illustrations/{_microscope.svg → microscope.svg} +0 -0
@@ -0,0 +1,48 @@
1
+ <template>
2
+ <Tooltip v-if="contentTypes.length > 1">
3
+ <div class="relative shrink-0">
4
+ <select
5
+ :value="modelValue"
6
+ class="appearance-none text-xs font-mono bg-white border border-gray-default rounded pl-2 pr-6 py-1 text-gray-medium cursor-pointer hover:border-gray-400 transition-colors"
7
+ @change="$emit('update:modelValue', ($event.target as HTMLSelectElement).value)"
8
+ >
9
+ <option
10
+ v-for="ct in contentTypes"
11
+ :key="ct"
12
+ :value="ct"
13
+ >
14
+ {{ contentTypeLabel(ct) }}
15
+ </option>
16
+ </select>
17
+ <RiArrowDownSLine class="pointer-events-none absolute right-1 top-1/2 -translate-y-1/2 size-3.5 text-gray-medium" />
18
+ </div>
19
+ <template #tooltip>
20
+ {{ modelValue }}
21
+ </template>
22
+ </Tooltip>
23
+ <Tooltip v-else-if="contentTypes.length === 1">
24
+ <span
25
+ class="text-xs font-mono bg-white border border-gray-default rounded px-2 py-1 text-gray-medium shrink-0"
26
+ >
27
+ {{ contentTypeLabel(contentTypes[0]!) }}
28
+ </span>
29
+ <template #tooltip>
30
+ {{ contentTypes[0] }}
31
+ </template>
32
+ </Tooltip>
33
+ </template>
34
+
35
+ <script setup lang="ts">
36
+ import { RiArrowDownSLine } from '@remixicon/vue'
37
+ import Tooltip from '../Tooltip.vue'
38
+ import { contentTypeLabel } from './openapi'
39
+
40
+ defineProps<{
41
+ contentTypes: string[]
42
+ modelValue: string
43
+ }>()
44
+
45
+ defineEmits<{
46
+ 'update:modelValue': [value: string]
47
+ }>()
48
+ </script>
@@ -0,0 +1,164 @@
1
+ <template>
2
+ <div class="border border-gray-default rounded">
3
+ <div
4
+ v-if="!tabs.length"
5
+ class="p-3 text-xs text-gray-medium"
6
+ >
7
+ {{ t("Aucun paramètre de requête") }}
8
+ </div>
9
+ <TabGroup
10
+ v-else
11
+ size="sm"
12
+ @change="onTabChange"
13
+ >
14
+ <div class="bg-gray-100 px-3 py-2 border-b border-gray-default flex items-center justify-between gap-2">
15
+ <TabList>
16
+ <Tab
17
+ v-for="tab in tabs"
18
+ :key="tab.key"
19
+ >
20
+ {{ tab.label }}
21
+ </Tab>
22
+ </TabList>
23
+ <ContentTypeSelect
24
+ v-if="activeTab === 'body' && bodyContentTypes.length"
25
+ :content-types="bodyContentTypes"
26
+ :model-value="selectedBodyContentType"
27
+ @update:model-value="selectedBodyContentType = $event"
28
+ />
29
+ </div>
30
+ <TabPanels>
31
+ <TabPanel
32
+ v-for="tab in tabs"
33
+ :key="tab.key"
34
+ >
35
+ <div
36
+ v-if="tab.key === 'query'"
37
+ class="p-3"
38
+ >
39
+ <div class="space-y-0 divide-y divide-gray-100">
40
+ <div
41
+ v-for="param in queryParams"
42
+ :key="param.name"
43
+ class="py-2"
44
+ >
45
+ <div class="flex items-baseline gap-2">
46
+ <span class="font-mono text-xs text-gray-title">
47
+ {{ param.name }}
48
+ <span
49
+ v-if="param.required"
50
+ class="text-red-600"
51
+ >*</span>
52
+ </span>
53
+ <span class="font-mono text-xs text-gray-medium">{{ getSchemaType(endpoint.spec, param.schema) }}</span>
54
+ </div>
55
+ <p
56
+ v-if="param.description"
57
+ class="text-xs text-gray-medium mt-0.5 mb-0"
58
+ >
59
+ {{ param.description }}
60
+ </p>
61
+ </div>
62
+ </div>
63
+ </div>
64
+ <div
65
+ v-if="tab.key === 'path'"
66
+ class="p-3"
67
+ >
68
+ <div class="space-y-0 divide-y divide-gray-100">
69
+ <div
70
+ v-for="param in pathParams"
71
+ :key="param.name"
72
+ class="py-2"
73
+ >
74
+ <div class="flex items-baseline gap-2">
75
+ <span class="font-mono text-xs text-gray-title">
76
+ {{ param.name }}
77
+ <span class="text-red-600">*</span>
78
+ </span>
79
+ <span class="font-mono text-xs text-gray-medium">{{ getSchemaType(endpoint.spec, param.schema) }}</span>
80
+ </div>
81
+ <p
82
+ v-if="param.description"
83
+ class="text-xs text-gray-medium mt-0.5 mb-0"
84
+ >
85
+ {{ param.description }}
86
+ </p>
87
+ </div>
88
+ </div>
89
+ </div>
90
+ <div
91
+ v-if="tab.key === 'body'"
92
+ class="p-3"
93
+ >
94
+ <SchemaPanel
95
+ v-if="currentBodyMediaType?.schema"
96
+ :spec="endpoint.spec"
97
+ :schema="currentBodyMediaType.schema"
98
+ />
99
+ </div>
100
+ </TabPanel>
101
+ </TabPanels>
102
+ </TabGroup>
103
+ </div>
104
+ </template>
105
+
106
+ <script setup lang="ts">
107
+ import { computed, ref, watch } from 'vue'
108
+ import TabGroup from '../Tabs/TabGroup.vue'
109
+ import TabList from '../Tabs/TabList.vue'
110
+ import Tab from '../Tabs/Tab.vue'
111
+ import TabPanels from '../Tabs/TabPanels.vue'
112
+ import TabPanel from '../Tabs/TabPanel.vue'
113
+ import ContentTypeSelect from './ContentTypeSelect.vue'
114
+ import { useTranslation } from '../../composables/useTranslation'
115
+ import SchemaPanel from './SchemaPanel.vue'
116
+ import { getSchemaType, type Endpoint } from './openapi'
117
+
118
+ const props = defineProps<{
119
+ endpoint: Endpoint
120
+ }>()
121
+
122
+ const { t } = useTranslation()
123
+
124
+ const queryParams = computed(() => props.endpoint.parameters.filter(p => p.in === 'query'))
125
+ const pathParams = computed(() => props.endpoint.parameters.filter(p => p.in === 'path'))
126
+
127
+ const tabs = computed(() => {
128
+ const result: { key: string, label: string }[] = []
129
+ if (pathParams.value.length) {
130
+ result.push({ key: 'path', label: t('Path') })
131
+ }
132
+ if (queryParams.value.length) {
133
+ result.push({ key: 'query', label: t('Query') })
134
+ }
135
+ if (props.endpoint.requestBody) {
136
+ result.push({ key: 'body', label: t('Body') })
137
+ }
138
+ return result
139
+ })
140
+
141
+ const activeTabIndex = ref(0)
142
+ const activeTab = computed(() => tabs.value[activeTabIndex.value]?.key || '')
143
+ const selectedBodyContentType = ref('')
144
+
145
+ const bodyContentTypes = computed(() => {
146
+ if (!props.endpoint.requestBody?.content) return []
147
+ return Object.keys(props.endpoint.requestBody.content)
148
+ })
149
+
150
+ const currentBodyMediaType = computed(() => {
151
+ if (!props.endpoint.requestBody?.content) return null
152
+ const ct = selectedBodyContentType.value || bodyContentTypes.value[0]
153
+ if (!ct) return null
154
+ return props.endpoint.requestBody.content[ct] || null
155
+ })
156
+
157
+ watch(bodyContentTypes, (types) => {
158
+ selectedBodyContentType.value = types[0] || ''
159
+ }, { immediate: true })
160
+
161
+ function onTabChange(index: number) {
162
+ activeTabIndex.value = index
163
+ }
164
+ </script>
@@ -0,0 +1,149 @@
1
+ <template>
2
+ <div class="border border-gray-default rounded">
3
+ <TabGroup
4
+ size="sm"
5
+ @change="onTabChange"
6
+ >
7
+ <div class="bg-gray-100 px-3 py-2 border-b border-gray-default flex items-center gap-4">
8
+ <div
9
+ ref="tabListContainer"
10
+ class="overflow-x-auto flex-1 min-w-0"
11
+ :class="{ 'scroll-fade': canScrollRight }"
12
+ @scroll="onScroll"
13
+ >
14
+ <TabList>
15
+ <Tab
16
+ v-for="tab in tabs"
17
+ :key="tab.code"
18
+ >
19
+ <span
20
+ class="inline-block w-2 h-2 rounded-full mr-1.5"
21
+ :class="statusDotColor(tab.code)"
22
+ />
23
+ {{ tab.code }}
24
+ </Tab>
25
+ </TabList>
26
+ </div>
27
+ <ContentTypeSelect
28
+ v-if="currentContentTypes.length"
29
+ :content-types="currentContentTypes"
30
+ :model-value="selectedContentType"
31
+ @update:model-value="selectedContentType = $event"
32
+ />
33
+ </div>
34
+ <TabPanels>
35
+ <TabPanel
36
+ v-for="tab in tabs"
37
+ :key="tab.code"
38
+ >
39
+ <div class="p-3 space-y-3">
40
+ <p
41
+ v-if="tab.response.description"
42
+ class="text-xs text-gray-medium mb-0 pb-3 border-b border-gray-100"
43
+ >
44
+ {{ tab.response.description }}
45
+ </p>
46
+ <template v-if="currentMediaType?.schema">
47
+ <SchemaPanel
48
+ :spec="spec"
49
+ :schema="currentMediaType.schema"
50
+ />
51
+ </template>
52
+ <p
53
+ v-else-if="!tab.response.content"
54
+ class="text-xs text-gray-medium mb-0"
55
+ >
56
+ {{ t("Pas de contenu") }}
57
+ </p>
58
+ </div>
59
+ </TabPanel>
60
+ </TabPanels>
61
+ </TabGroup>
62
+ </div>
63
+ </template>
64
+
65
+ <script setup lang="ts">
66
+ import { computed, ref, watch, useTemplateRef, onMounted, nextTick } from 'vue'
67
+ import TabGroup from '../Tabs/TabGroup.vue'
68
+ import TabList from '../Tabs/TabList.vue'
69
+ import Tab from '../Tabs/Tab.vue'
70
+ import TabPanels from '../Tabs/TabPanels.vue'
71
+ import TabPanel from '../Tabs/TabPanel.vue'
72
+ import ContentTypeSelect from './ContentTypeSelect.vue'
73
+ import { useTranslation } from '../../composables/useTranslation'
74
+ import SchemaPanel from './SchemaPanel.vue'
75
+ import type { OpenAPIV3 } from 'openapi-types'
76
+
77
+ const props = defineProps<{
78
+ responses: Record<string, OpenAPIV3.ResponseObject>
79
+ spec: OpenAPIV3.Document
80
+ }>()
81
+
82
+ const { t } = useTranslation()
83
+
84
+ const tabListContainer = useTemplateRef('tabListContainer')
85
+ const canScrollRight = ref(false)
86
+
87
+ function checkOverflow() {
88
+ const el = tabListContainer.value
89
+ if (!el) return
90
+ canScrollRight.value = el.scrollLeft + el.clientWidth < el.scrollWidth - 1
91
+ }
92
+
93
+ function onScroll() {
94
+ checkOverflow()
95
+ }
96
+
97
+ onMounted(checkOverflow)
98
+
99
+ const tabs = computed(() =>
100
+ Object.entries(props.responses).map(([code, response]) => ({ code, response })),
101
+ )
102
+
103
+ watch(tabs, () => {
104
+ nextTick(checkOverflow)
105
+ })
106
+
107
+ const activeTabIndex = ref(0)
108
+ const selectedContentType = ref('')
109
+
110
+ const currentContentTypes = computed(() => {
111
+ const tab = tabs.value[activeTabIndex.value]
112
+ if (!tab?.response.content) return []
113
+ return Object.keys(tab.response.content)
114
+ })
115
+
116
+ const currentMediaType = computed(() => {
117
+ const tab = tabs.value[activeTabIndex.value]
118
+ if (!tab?.response.content) return null
119
+ const ct = selectedContentType.value || currentContentTypes.value[0]
120
+ if (!ct) return null
121
+ return tab.response.content[ct] || null
122
+ })
123
+
124
+ watch(currentContentTypes, (types) => {
125
+ selectedContentType.value = types[0] || ''
126
+ }, { immediate: true })
127
+
128
+ function onTabChange(index: number) {
129
+ activeTabIndex.value = index
130
+ }
131
+
132
+ function statusDotColor(code: string): string {
133
+ if (code.startsWith('2')) return 'bg-green-600'
134
+ if (code.startsWith('3')) return 'bg-blue-600'
135
+ if (code.startsWith('4')) return 'bg-orange-500'
136
+ if (code.startsWith('5')) return 'bg-red-600'
137
+ return 'bg-gray-400'
138
+ }
139
+ </script>
140
+
141
+ <style scoped>
142
+ .scroll-fade {
143
+ mask-image: linear-gradient(to right, black calc(100% - 60px), transparent);
144
+ mask-size: 100% 100%;
145
+ mask-position: center;
146
+ padding-block: 4px;
147
+ margin-block: -4px;
148
+ }
149
+ </style>
@@ -0,0 +1,308 @@
1
+ <template>
2
+ <div>
3
+ <div
4
+ v-if="loading"
5
+ class="flex items-center justify-center py-8"
6
+ >
7
+ <AnimatedLoader />
8
+ </div>
9
+ <div
10
+ v-else-if="error"
11
+ class="text-new-error text-sm py-4"
12
+ >
13
+ {{ t("Impossible de charger la documentation OpenAPI.") }}
14
+ </div>
15
+ <div
16
+ v-else-if="spec"
17
+ class="space-y-4"
18
+ >
19
+ <div class="flex flex-wrap items-center justify-between gap-x-4 gap-y-1 text-sm text-gray-medium">
20
+ <div class="flex flex-wrap gap-x-4 gap-y-1">
21
+ <span v-if="spec.info?.version">
22
+ {{ t("Version") }} <span class="font-mono">{{ spec.info.version }}</span>
23
+ </span>
24
+ <div
25
+ v-if="baseUrl"
26
+ class="flex flex-col md:flex-row md:items-center gap-0.5 md:gap-0"
27
+ >
28
+ <span>{{ t("Base URL") }}</span>
29
+ <span class="inline-flex items-center">
30
+ <span class="font-mono break-all md:ml-1">{{ baseUrl }}</span>
31
+ <CopyButton
32
+ :label="t('Copier le lien')"
33
+ :copied-label="t('Lien copié !')"
34
+ :text="baseUrl"
35
+ class="shrink-0 hidden md:inline-flex"
36
+ />
37
+ </span>
38
+ </div>
39
+ </div>
40
+ <a
41
+ :href="swaggerUiUrl"
42
+ target="_blank"
43
+ rel="noopener noreferrer"
44
+ class="text-xs text-gray-medium hover:text-gray-title"
45
+ >
46
+ {{ t("Ouvrir dans Swagger UI") }}
47
+ </a>
48
+ </div>
49
+ <div
50
+ v-for="group in groupedEndpoints"
51
+ :key="group.tag"
52
+ >
53
+ <Disclosure
54
+ v-slot="{ open }"
55
+ as="div"
56
+ default-open
57
+ >
58
+ <DisclosureButton class="flex w-full items-center justify-between py-2 border-b border-gray-default text-left">
59
+ <span class="font-bold text-gray-title">
60
+ {{ group.tag }}
61
+ <span class="ml-1 text-xs font-normal text-gray-medium">{{ group.endpoints.length }}</span>
62
+ </span>
63
+ <RiArrowDownSLine
64
+ class="size-5 text-gray-medium transition-transform"
65
+ :class="{ 'rotate-180': open }"
66
+ />
67
+ </DisclosureButton>
68
+ <DisclosurePanel class="divide-y divide-gray-100">
69
+ <Disclosure
70
+ v-for="endpoint in group.endpoints"
71
+ :key="endpoint.method + endpoint.path"
72
+ v-slot="{ open: endpointOpen }"
73
+ as="div"
74
+ >
75
+ <DisclosureButton class="flex items-baseline gap-2 md:gap-3 py-3 px-1 w-full text-left">
76
+ <span
77
+ class="shrink-0 w-12 md:w-16 inline-flex items-center justify-center rounded px-1.5 py-0.5 text-xs font-bold uppercase font-mono leading-none"
78
+ :class="methodColor(endpoint.method)"
79
+ >
80
+ {{ endpoint.method }}
81
+ </span>
82
+ <div class="min-w-0 flex-1">
83
+ <span class="inline-flex items-center gap-2">
84
+ <span class="font-mono text-sm text-gray-title break-all">{{ endpoint.path }}</span>
85
+ <CopyButton
86
+ :label="t('Copier le lien')"
87
+ :copied-label="t('Lien copié !')"
88
+ :text="endpointFullUrl(endpoint)"
89
+ class="shrink-0 hidden md:inline-flex"
90
+ @click.stop
91
+ />
92
+ </span>
93
+ <p
94
+ v-if="endpoint.summary"
95
+ class="hidden md:block text-sm text-gray-medium mt-0.5 mb-0"
96
+ >
97
+ {{ endpoint.summary }}
98
+ </p>
99
+ </div>
100
+ <RiArrowDownSLine
101
+ class="size-4 shrink-0 text-gray-medium transition-transform"
102
+ :class="{ 'rotate-180': endpointOpen }"
103
+ />
104
+ </DisclosureButton>
105
+ <DisclosurePanel class="pb-4 px-1">
106
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
107
+ <EndpointRequest
108
+ :endpoint="endpoint"
109
+ />
110
+ <EndpointResponses
111
+ :responses="endpoint.responses"
112
+ :spec="endpoint.spec"
113
+ />
114
+ </div>
115
+ </DisclosurePanel>
116
+ </Disclosure>
117
+ </DisclosurePanel>
118
+ </Disclosure>
119
+ </div>
120
+ <div v-if="schemas.length">
121
+ <Disclosure
122
+ v-slot="{ open }"
123
+ default-open
124
+ as="div"
125
+ >
126
+ <DisclosureButton class="flex w-full items-center justify-between py-2 border-b border-gray-default text-left">
127
+ <span class="font-bold text-gray-title">
128
+ {{ t("Modèles") }}
129
+ <span class="ml-1 text-xs font-normal text-gray-medium">{{ schemas.length }}</span>
130
+ </span>
131
+ <RiArrowDownSLine
132
+ class="size-5 text-gray-medium transition-transform"
133
+ :class="{ 'rotate-180': open }"
134
+ />
135
+ </DisclosureButton>
136
+ <DisclosurePanel class="divide-y divide-gray-100">
137
+ <Disclosure
138
+ v-for="model in schemas"
139
+ :key="model.name"
140
+ v-slot="{ open: modelOpen }"
141
+ as="div"
142
+ >
143
+ <DisclosureButton class="flex items-center gap-2 py-3 px-1 w-full text-left">
144
+ <RiArrowDownSLine
145
+ class="size-4 shrink-0 text-gray-medium transition-transform"
146
+ :class="{ 'rotate-180': modelOpen }"
147
+ />
148
+ <span class="font-mono text-sm text-gray-title">{{ model.name }}</span>
149
+ <span
150
+ v-if="model.schema.description"
151
+ class="text-xs text-gray-medium truncate"
152
+ >{{ model.schema.description }}</span>
153
+ </DisclosureButton>
154
+ <DisclosurePanel class="pb-4 px-1">
155
+ <SchemaPanel
156
+ :spec="spec!"
157
+ :schema="model.schema"
158
+ />
159
+ </DisclosurePanel>
160
+ </Disclosure>
161
+ </DisclosurePanel>
162
+ </Disclosure>
163
+ </div>
164
+ </div>
165
+ </div>
166
+ </template>
167
+
168
+ <script setup lang="ts">
169
+ import { ref, computed, watchEffect } from 'vue'
170
+ import { Disclosure, DisclosureButton, DisclosurePanel } from '@headlessui/vue'
171
+ import { RiArrowDownSLine } from '@remixicon/vue'
172
+ import { useTranslation } from '../../composables/useTranslation'
173
+ import AnimatedLoader from '../AnimatedLoader.vue'
174
+ import CopyButton from '../CopyButton.vue'
175
+ import EndpointRequest from './EndpointRequest.vue'
176
+ import EndpointResponses from './EndpointResponses.vue'
177
+ import SchemaPanel from './SchemaPanel.vue'
178
+ import { parse as parseYaml } from 'yaml'
179
+ import type { OpenAPIV3 } from 'openapi-types'
180
+ import { resolveRef, type Endpoint } from './openapi'
181
+
182
+ const props = defineProps<{
183
+ url: string
184
+ }>()
185
+
186
+ const { t } = useTranslation()
187
+
188
+ const spec = ref<OpenAPIV3.Document | null>(null)
189
+ const loading = ref(true)
190
+ const error = ref(false)
191
+
192
+ const HTTP_METHODS = ['get', 'post', 'put', 'patch', 'delete', 'options', 'head'] as const
193
+
194
+ async function parseOpenApiResponse(response: Response): Promise<OpenAPIV3.Document> {
195
+ const text = await response.text()
196
+ try {
197
+ return JSON.parse(text)
198
+ }
199
+ catch {
200
+ return parseYaml(text) as OpenAPIV3.Document
201
+ }
202
+ }
203
+
204
+ watchEffect(async () => {
205
+ if (!props.url) return
206
+ loading.value = true
207
+ error.value = false
208
+ try {
209
+ const response = await fetch(props.url)
210
+ if (!response.ok) throw new Error(response.statusText)
211
+ spec.value = await parseOpenApiResponse(response)
212
+ }
213
+ catch {
214
+ error.value = true
215
+ spec.value = null
216
+ }
217
+ finally {
218
+ loading.value = false
219
+ }
220
+ })
221
+
222
+ const baseUrl = computed(() => {
223
+ if (!spec.value?.servers?.length) return null
224
+ return spec.value.servers[0]!.url
225
+ })
226
+
227
+ const swaggerUiUrl = computed(() => {
228
+ return `https://petstore.swagger.io/?url=${encodeURIComponent(props.url)}`
229
+ })
230
+
231
+ const endpoints = computed<Endpoint[]>(() => {
232
+ if (!spec.value?.paths) return []
233
+ const result: Endpoint[] = []
234
+ for (const [path, pathItem] of Object.entries(spec.value.paths)) {
235
+ if (!pathItem) continue
236
+ for (const method of HTTP_METHODS) {
237
+ const operation = (pathItem as Record<string, OpenAPIV3.OperationObject>)[method]
238
+ if (!operation) continue
239
+
240
+ const parameters = (operation.parameters || []).map((p) => {
241
+ return resolveRef<OpenAPIV3.ParameterObject>(spec.value!, p)
242
+ }).filter((p): p is OpenAPIV3.ParameterObject => p !== null)
243
+
244
+ const requestBody = operation.requestBody
245
+ ? resolveRef<OpenAPIV3.RequestBodyObject>(spec.value!, operation.requestBody)
246
+ : null
247
+
248
+ const responses: Record<string, OpenAPIV3.ResponseObject> = {}
249
+ if (operation.responses) {
250
+ for (const [code, resp] of Object.entries(operation.responses)) {
251
+ const resolved = resolveRef<OpenAPIV3.ResponseObject>(spec.value!, resp)
252
+ if (resolved) responses[code] = resolved
253
+ }
254
+ }
255
+
256
+ result.push({
257
+ method,
258
+ path,
259
+ summary: operation.summary || operation.description || '',
260
+ tags: operation.tags || [],
261
+ parameters,
262
+ requestBody: requestBody || null,
263
+ responses,
264
+ spec: spec.value!,
265
+ })
266
+ }
267
+ }
268
+ return result
269
+ })
270
+
271
+ const groupedEndpoints = computed(() => {
272
+ const groups = new Map<string, Endpoint[]>()
273
+ for (const endpoint of endpoints.value) {
274
+ const tags = endpoint.tags.length ? endpoint.tags : [t('Endpoints')]
275
+ for (const tag of tags) {
276
+ if (!groups.has(tag)) {
277
+ groups.set(tag, [])
278
+ }
279
+ groups.get(tag)!.push(endpoint)
280
+ }
281
+ }
282
+ return Array.from(groups.entries()).map(([tag, endpoints]) => ({ tag, endpoints }))
283
+ })
284
+
285
+ const schemas = computed(() => {
286
+ const components = spec.value?.components?.schemas
287
+ if (!components) return []
288
+ return Object.entries(components).map(([name, schema]) => ({
289
+ name,
290
+ schema: schema as OpenAPIV3.SchemaObject,
291
+ }))
292
+ })
293
+
294
+ function endpointFullUrl(endpoint: Endpoint): string {
295
+ return (baseUrl.value || '') + endpoint.path
296
+ }
297
+
298
+ function methodColor(method: string): string {
299
+ switch (method) {
300
+ case 'get': return 'bg-blue-100 text-blue-800'
301
+ case 'post': return 'bg-green-100 text-green-800'
302
+ case 'put': return 'bg-orange-100 text-orange-800'
303
+ case 'patch': return 'bg-yellow-100 text-yellow-800'
304
+ case 'delete': return 'bg-red-100 text-red-800'
305
+ default: return 'bg-gray-100 text-gray-800'
306
+ }
307
+ }
308
+ </script>