@datagouv/components-next 1.0.2-dev.44 → 1.0.2-dev.46
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/{Datafair.client-BAokThtJ.js → Datafair.client-hLoIoNbP.js} +1 -1
- package/dist/{JsonPreview.client-DGiaDxVv.js → JsonPreview.client-BUCeeFKz.js} +2 -2
- package/dist/{MapContainer.client-BKGsAP0Y.js → MapContainer.client-DrQRSrq_.js} +2 -2
- package/dist/{PdfPreview.client-CGjP5ZYb.js → PdfPreview.client-vQ4bfJx3.js} +2 -2
- package/dist/{Pmtiles.client-C1I7pwT5.js → Pmtiles.client-DWtu_UNl.js} +1 -1
- package/dist/{PreviewWrapper.vue_vue_type_script_setup_true_lang-BlcvVwW8.js → PreviewWrapper.vue_vue_type_script_setup_true_lang-4Ufr2Kmw.js} +1 -1
- package/dist/{XmlPreview.client-CHUVVEH6.js → XmlPreview.client-CEEHnAFF.js} +3 -3
- package/dist/components-next.css +1 -1
- package/dist/components-next.js +54 -54
- package/dist/components.css +1 -1
- package/dist/{index-CzClB3i0.js → index-CsOZmih1.js} +1 -1
- package/dist/main-7DRSPyNj.js +71033 -0
- package/dist/{vue3-xml-viewer.common-CAwAbUJl.js → vue3-xml-viewer.common-DOIGuzsk.js} +1 -1
- package/package.json +4 -3
- package/src/components/OpenApiViewer/ContentTypeSelect.vue +48 -0
- package/src/components/OpenApiViewer/EndpointRequest.vue +164 -0
- package/src/components/OpenApiViewer/EndpointResponses.vue +149 -0
- package/src/components/OpenApiViewer/OpenApiViewer.vue +308 -0
- package/src/components/OpenApiViewer/SchemaPanel.vue +53 -0
- package/src/components/OpenApiViewer/SchemaTree.vue +77 -0
- package/src/components/OpenApiViewer/openapi.ts +150 -0
- package/src/components/ResourceAccordion/ResourceAccordion.vue +3 -4
- package/src/components/ResourceExplorer/ResourceExplorerViewer.vue +3 -6
- package/src/main.ts +2 -2
- package/assets/swagger-themes/newspaper.css +0 -1670
- package/dist/Swagger.client-U7ZDVUHL.js +0 -4
- package/dist/main-CF7lWk6R.js +0 -106591
- package/src/components/ResourceAccordion/Swagger.client.vue +0 -48
|
@@ -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>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<div class="flex items-center gap-2 mb-2">
|
|
4
|
+
<button
|
|
5
|
+
type="button"
|
|
6
|
+
class="text-xs font-medium px-2 py-0.5 rounded"
|
|
7
|
+
:class="view === 'schema' ? 'bg-gray-200 text-gray-title' : 'text-gray-medium hover:text-gray-title'"
|
|
8
|
+
@click="view = 'schema'"
|
|
9
|
+
>
|
|
10
|
+
{{ t("Schéma") }}
|
|
11
|
+
</button>
|
|
12
|
+
<button
|
|
13
|
+
type="button"
|
|
14
|
+
class="text-xs font-medium px-2 py-0.5 rounded"
|
|
15
|
+
:class="view === 'example' ? 'bg-gray-200 text-gray-title' : 'text-gray-medium hover:text-gray-title'"
|
|
16
|
+
@click="view = 'example'"
|
|
17
|
+
>
|
|
18
|
+
{{ t("Exemple") }}
|
|
19
|
+
</button>
|
|
20
|
+
</div>
|
|
21
|
+
<SchemaTree
|
|
22
|
+
v-if="view === 'schema'"
|
|
23
|
+
:spec="spec"
|
|
24
|
+
:schema="schema"
|
|
25
|
+
/>
|
|
26
|
+
<pre
|
|
27
|
+
v-else
|
|
28
|
+
class="text-xs font-mono bg-gray-50 rounded p-3 overflow-x-auto m-0 text-gray-title"
|
|
29
|
+
>{{ exampleJson }}</pre>
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<script setup lang="ts">
|
|
34
|
+
import { ref, computed } from 'vue'
|
|
35
|
+
import SchemaTree from './SchemaTree.vue'
|
|
36
|
+
import { useTranslation } from '../../composables/useTranslation'
|
|
37
|
+
import { generateExample } from './openapi'
|
|
38
|
+
import type { OpenAPIV3 } from 'openapi-types'
|
|
39
|
+
|
|
40
|
+
const props = defineProps<{
|
|
41
|
+
spec: OpenAPIV3.Document
|
|
42
|
+
schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject
|
|
43
|
+
}>()
|
|
44
|
+
|
|
45
|
+
const { t } = useTranslation()
|
|
46
|
+
|
|
47
|
+
const view = ref<'schema' | 'example'>('schema')
|
|
48
|
+
|
|
49
|
+
const exampleJson = computed(() => {
|
|
50
|
+
const example = generateExample(props.spec, props.schema)
|
|
51
|
+
return JSON.stringify(example, null, 2)
|
|
52
|
+
})
|
|
53
|
+
</script>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="text-xs overflow-hidden">
|
|
3
|
+
<div
|
|
4
|
+
v-for="prop in properties"
|
|
5
|
+
:key="prop.name"
|
|
6
|
+
class="border-b border-gray-100 last:border-0"
|
|
7
|
+
>
|
|
8
|
+
<div class="flex items-baseline gap-2 py-1.5 min-w-0">
|
|
9
|
+
<button
|
|
10
|
+
v-if="hasNestedProperties(spec, prop.schema)"
|
|
11
|
+
type="button"
|
|
12
|
+
class="shrink-0 flex items-center gap-1 font-mono text-gray-title hover:text-gray-800"
|
|
13
|
+
@click="toggle(prop.name)"
|
|
14
|
+
>
|
|
15
|
+
<RiArrowRightSLine
|
|
16
|
+
class="size-3 text-gray-medium transition-transform"
|
|
17
|
+
:class="{ 'rotate-90': expanded.has(prop.name) }"
|
|
18
|
+
/>
|
|
19
|
+
{{ prop.name }}
|
|
20
|
+
<span
|
|
21
|
+
v-if="prop.required"
|
|
22
|
+
class="text-red-600"
|
|
23
|
+
>*</span>
|
|
24
|
+
</button>
|
|
25
|
+
<span
|
|
26
|
+
v-else
|
|
27
|
+
class="font-mono text-gray-title pl-4"
|
|
28
|
+
>
|
|
29
|
+
{{ prop.name }}
|
|
30
|
+
<span
|
|
31
|
+
v-if="prop.required"
|
|
32
|
+
class="text-red-600"
|
|
33
|
+
>*</span>
|
|
34
|
+
</span>
|
|
35
|
+
<span class="font-mono text-gray-medium whitespace-nowrap">{{ prop.type }}</span>
|
|
36
|
+
<span
|
|
37
|
+
v-if="prop.description"
|
|
38
|
+
class="text-gray-medium truncate"
|
|
39
|
+
>{{ prop.description }}</span>
|
|
40
|
+
</div>
|
|
41
|
+
<div
|
|
42
|
+
v-if="expanded.has(prop.name) && hasNestedProperties(spec, prop.schema)"
|
|
43
|
+
class="pl-4 ml-1.5 border-l border-gray-200"
|
|
44
|
+
>
|
|
45
|
+
<SchemaTree
|
|
46
|
+
:spec="spec"
|
|
47
|
+
:schema="getNestedSchema(spec, prop.schema)!"
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
</template>
|
|
53
|
+
|
|
54
|
+
<script setup lang="ts">
|
|
55
|
+
import { computed, reactive } from 'vue'
|
|
56
|
+
import { RiArrowRightSLine } from '@remixicon/vue'
|
|
57
|
+
import { getSchemaProperties, hasNestedProperties, getNestedSchema } from './openapi'
|
|
58
|
+
import type { OpenAPIV3 } from 'openapi-types'
|
|
59
|
+
|
|
60
|
+
const props = defineProps<{
|
|
61
|
+
spec: OpenAPIV3.Document
|
|
62
|
+
schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject
|
|
63
|
+
}>()
|
|
64
|
+
|
|
65
|
+
const properties = computed(() => getSchemaProperties(props.spec, props.schema))
|
|
66
|
+
|
|
67
|
+
const expanded = reactive(new Set<string>())
|
|
68
|
+
|
|
69
|
+
function toggle(name: string) {
|
|
70
|
+
if (expanded.has(name)) {
|
|
71
|
+
expanded.delete(name)
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
expanded.add(name)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from 'openapi-types'
|
|
2
|
+
|
|
3
|
+
export interface Endpoint {
|
|
4
|
+
method: string
|
|
5
|
+
path: string
|
|
6
|
+
summary: string
|
|
7
|
+
tags: string[]
|
|
8
|
+
parameters: OpenAPIV3.ParameterObject[]
|
|
9
|
+
requestBody: OpenAPIV3.RequestBodyObject | null
|
|
10
|
+
responses: Record<string, OpenAPIV3.ResponseObject>
|
|
11
|
+
spec: OpenAPIV3.Document
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function resolveRef<T>(spec: OpenAPIV3.Document, obj: T | OpenAPIV3.ReferenceObject): T | null {
|
|
15
|
+
if (!obj || typeof obj !== 'object') return obj as T | null
|
|
16
|
+
if (!('$ref' in obj)) return obj as T
|
|
17
|
+
const path = (obj as OpenAPIV3.ReferenceObject).$ref.replace('#/', '').split('/')
|
|
18
|
+
let resolved: unknown = spec
|
|
19
|
+
for (const segment of path) {
|
|
20
|
+
if (resolved && typeof resolved === 'object') {
|
|
21
|
+
resolved = (resolved as Record<string, unknown>)[segment]
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return resolved as T
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getSchemaType(spec: OpenAPIV3.Document, schema?: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject): string {
|
|
31
|
+
if (!schema) return ''
|
|
32
|
+
const resolved = resolveRef<OpenAPIV3.SchemaObject>(spec, schema)
|
|
33
|
+
if (!resolved) return ''
|
|
34
|
+
if (resolved.type === 'array' && resolved.items) {
|
|
35
|
+
const itemType = getSchemaType(spec, resolved.items)
|
|
36
|
+
return `${itemType}[]`
|
|
37
|
+
}
|
|
38
|
+
if (resolved.format) return `${resolved.type} (${resolved.format})`
|
|
39
|
+
return resolved.type || ''
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const CONTENT_TYPE_LABELS: Record<string, string> = {
|
|
43
|
+
'application/json': 'JSON',
|
|
44
|
+
'application/xml': 'XML',
|
|
45
|
+
'application/x-www-form-urlencoded': 'Form',
|
|
46
|
+
'multipart/form-data': 'Multipart',
|
|
47
|
+
'text/plain': 'Text',
|
|
48
|
+
'text/html': 'HTML',
|
|
49
|
+
'text/csv': 'CSV',
|
|
50
|
+
'application/octet-stream': 'Binary',
|
|
51
|
+
'application/pdf': 'PDF',
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function contentTypeLabel(raw: string): string {
|
|
55
|
+
const base = raw.split(';')[0]!.trim()
|
|
56
|
+
return CONTENT_TYPE_LABELS[base] || base
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface SchemaProperty {
|
|
60
|
+
name: string
|
|
61
|
+
type: string
|
|
62
|
+
description: string
|
|
63
|
+
required: boolean
|
|
64
|
+
schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function getSchemaProperties(spec: OpenAPIV3.Document, schema?: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject): SchemaProperty[] {
|
|
68
|
+
if (!schema) return []
|
|
69
|
+
const resolved = resolveRef<OpenAPIV3.SchemaObject>(spec, schema)
|
|
70
|
+
if (!resolved?.properties) return []
|
|
71
|
+
const requiredFields = resolved.required || []
|
|
72
|
+
return Object.entries(resolved.properties).map(([name, propSchema]) => {
|
|
73
|
+
const prop = resolveRef<OpenAPIV3.SchemaObject>(spec, propSchema)
|
|
74
|
+
return {
|
|
75
|
+
name,
|
|
76
|
+
type: getSchemaType(spec, propSchema),
|
|
77
|
+
description: prop?.description || '',
|
|
78
|
+
required: requiredFields.includes(name),
|
|
79
|
+
schema: propSchema,
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function hasNestedProperties(spec: OpenAPIV3.Document, schema?: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject): boolean {
|
|
85
|
+
if (!schema) return false
|
|
86
|
+
const resolved = resolveRef<OpenAPIV3.SchemaObject>(spec, schema)
|
|
87
|
+
if (!resolved) return false
|
|
88
|
+
if (resolved.properties) return true
|
|
89
|
+
if (resolved.type === 'array' && resolved.items) {
|
|
90
|
+
return hasNestedProperties(spec, resolved.items)
|
|
91
|
+
}
|
|
92
|
+
return false
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function getNestedSchema(spec: OpenAPIV3.Document, schema?: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject): OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined {
|
|
96
|
+
if (!schema) return undefined
|
|
97
|
+
const resolved = resolveRef<OpenAPIV3.SchemaObject>(spec, schema)
|
|
98
|
+
if (!resolved) return undefined
|
|
99
|
+
if (resolved.properties) return schema
|
|
100
|
+
if (resolved.type === 'array' && resolved.items) return resolved.items
|
|
101
|
+
return undefined
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const MAX_EXAMPLE_DEPTH = 4
|
|
105
|
+
|
|
106
|
+
function defaultForType(type?: string, format?: string): unknown {
|
|
107
|
+
switch (type) {
|
|
108
|
+
case 'string':
|
|
109
|
+
if (format === 'date') return '2024-01-01'
|
|
110
|
+
if (format === 'date-time') return '2024-01-01T00:00:00Z'
|
|
111
|
+
if (format === 'email') return 'user@example.com'
|
|
112
|
+
if (format === 'uri' || format === 'url') return 'https://example.com'
|
|
113
|
+
return 'string'
|
|
114
|
+
case 'integer': return 0
|
|
115
|
+
case 'number': return 0.0
|
|
116
|
+
case 'boolean': return true
|
|
117
|
+
case 'null': return null
|
|
118
|
+
default: return {}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function generateExample(spec: OpenAPIV3.Document, schema?: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject, depth = 0): unknown {
|
|
123
|
+
if (!schema || depth > MAX_EXAMPLE_DEPTH) return undefined
|
|
124
|
+
const resolved = resolveRef<OpenAPIV3.SchemaObject>(spec, schema)
|
|
125
|
+
if (!resolved) return undefined
|
|
126
|
+
|
|
127
|
+
if (resolved.example !== undefined) return resolved.example
|
|
128
|
+
|
|
129
|
+
if (resolved.type === 'array' && resolved.items) {
|
|
130
|
+
const item = generateExample(spec, resolved.items, depth + 1)
|
|
131
|
+
return item !== undefined ? [item] : []
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (resolved.properties) {
|
|
135
|
+
const obj: Record<string, unknown> = {}
|
|
136
|
+
for (const [name, propSchema] of Object.entries(resolved.properties)) {
|
|
137
|
+
const prop = resolveRef<OpenAPIV3.SchemaObject>(spec, propSchema)
|
|
138
|
+
if (prop?.example !== undefined) {
|
|
139
|
+
obj[name] = prop.example
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
const val = generateExample(spec, propSchema, depth + 1)
|
|
143
|
+
if (val !== undefined) obj[name] = val
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return obj
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return defaultForType(resolved.type as string, resolved.format)
|
|
150
|
+
}
|
|
@@ -231,7 +231,7 @@
|
|
|
231
231
|
:dataset="dataset"
|
|
232
232
|
/>
|
|
233
233
|
<!-- Show Datafair embedded preview (koumoul) -->
|
|
234
|
-
<
|
|
234
|
+
<OpenApiViewer
|
|
235
235
|
v-else-if="hasOpenAPIPreview"
|
|
236
236
|
:url="resource.extras['apidocUrl'] as string"
|
|
237
237
|
/>
|
|
@@ -357,7 +357,7 @@
|
|
|
357
357
|
<p>{{ t("- Si le fichier est supprimé, l'API sera également supprimée.") }}</p>
|
|
358
358
|
<p>{{ t("Pour des usages pérennes, prévoyez que cette API dépend directement du fichier source.") }}</p>
|
|
359
359
|
</div>
|
|
360
|
-
<
|
|
360
|
+
<OpenApiViewer
|
|
361
361
|
v-if="hasTabularData"
|
|
362
362
|
:url="`${config.tabularApiUrl}/api/resources/${props.resource.id}/swagger/`"
|
|
363
363
|
/>
|
|
@@ -398,7 +398,7 @@ import EditButton from './EditButton.vue'
|
|
|
398
398
|
import DataStructure from './DataStructure.vue'
|
|
399
399
|
import Preview from './Preview.vue'
|
|
400
400
|
import { isOrganizationCertified } from '../../functions/organizations'
|
|
401
|
-
import
|
|
401
|
+
import OpenApiViewer from '../OpenApiViewer/OpenApiViewer.vue'
|
|
402
402
|
|
|
403
403
|
const GENERATED_FORMATS = ['parquet', 'pmtiles', 'geojson']
|
|
404
404
|
const URL_FORMATS = ['url', 'doi', 'www:link', ' www:link-1.0-http--link', 'www:link-1.0-http--partners', 'www:link-1.0-http--related', 'www:link-1.0-http--samples']
|
|
@@ -417,7 +417,6 @@ const props = withDefaults(defineProps<{
|
|
|
417
417
|
|
|
418
418
|
const config = useComponentsConfig()
|
|
419
419
|
|
|
420
|
-
const Swagger = defineAsyncComponent(() => import('./Swagger.client.vue'))
|
|
421
420
|
const MapContainer = defineAsyncComponent(() => import('./MapContainer.client.vue'))
|
|
422
421
|
const Pmtiles = defineAsyncComponent(() => import('./Pmtiles.client.vue'))
|
|
423
422
|
const JsonPreview = defineAsyncComponent(() => import('./JsonPreview.client.vue'))
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
:resource="resource"
|
|
135
135
|
:dataset="dataset"
|
|
136
136
|
/>
|
|
137
|
-
<
|
|
137
|
+
<OpenApiViewer
|
|
138
138
|
v-else-if="hasOpenAPIPreview"
|
|
139
139
|
:url="resource.extras['apidocUrl'] as string"
|
|
140
140
|
/>
|
|
@@ -303,7 +303,7 @@
|
|
|
303
303
|
<p>{{ t("- Si le fichier est supprimé, l'API sera également supprimée.") }}</p>
|
|
304
304
|
<p>{{ t("Pour des usages pérennes, prévoyez que cette API dépend directement du fichier source.") }}</p>
|
|
305
305
|
</div>
|
|
306
|
-
<
|
|
306
|
+
<OpenApiViewer
|
|
307
307
|
v-if="hasTabularData"
|
|
308
308
|
:url="`${config.tabularApiUrl}/api/resources/${resource.id}/swagger/`"
|
|
309
309
|
/>
|
|
@@ -324,7 +324,7 @@ import BrandedButton from '../BrandedButton.vue'
|
|
|
324
324
|
import CopyButton from '../CopyButton.vue'
|
|
325
325
|
import MarkdownViewer from '../MarkdownViewer.vue'
|
|
326
326
|
import ResourceIcon from '../ResourceAccordion/ResourceIcon.vue'
|
|
327
|
-
import
|
|
327
|
+
import OpenApiViewer from '../OpenApiViewer/OpenApiViewer.vue'
|
|
328
328
|
import TabGroup from '../Tabs/TabGroup.vue'
|
|
329
329
|
import TabList from '../Tabs/TabList.vue'
|
|
330
330
|
import Tab from '../Tabs/Tab.vue'
|
|
@@ -363,9 +363,6 @@ const MapContainer = defineAsyncComponent(() =>
|
|
|
363
363
|
const Pmtiles = defineAsyncComponent(() =>
|
|
364
364
|
import('../ResourceAccordion/Pmtiles.client.vue'),
|
|
365
365
|
)
|
|
366
|
-
const SwaggerClient = defineAsyncComponent(() =>
|
|
367
|
-
import('../ResourceAccordion/Swagger.client.vue'),
|
|
368
|
-
)
|
|
369
366
|
|
|
370
367
|
const props = defineProps<{
|
|
371
368
|
dataset: Dataset | DatasetV2
|
package/src/main.ts
CHANGED
|
@@ -73,7 +73,7 @@ import ResourceIcon from './components/ResourceAccordion/ResourceIcon.vue'
|
|
|
73
73
|
import ResourceExplorer from './components/ResourceExplorer/ResourceExplorer.vue'
|
|
74
74
|
import ResourceExplorerSidebar from './components/ResourceExplorer/ResourceExplorerSidebar.vue'
|
|
75
75
|
import ResourceExplorerViewer from './components/ResourceExplorer/ResourceExplorerViewer.vue'
|
|
76
|
-
import
|
|
76
|
+
import OpenApiViewer from './components/OpenApiViewer/OpenApiViewer.vue'
|
|
77
77
|
import ReuseCard from './components/ReuseCard.vue'
|
|
78
78
|
import ReuseHorizontalCard from './components/ReuseHorizontalCard.vue'
|
|
79
79
|
import ReuseDetails from './components/ReuseDetails.vue'
|
|
@@ -302,7 +302,7 @@ export {
|
|
|
302
302
|
SimpleBanner,
|
|
303
303
|
SmallChart,
|
|
304
304
|
StatBox,
|
|
305
|
-
|
|
305
|
+
OpenApiViewer,
|
|
306
306
|
Tab,
|
|
307
307
|
TabGroup,
|
|
308
308
|
TabList,
|