Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,670 changes: 0 additions & 1,670 deletions datagouv-components/assets/swagger-themes/newspaper.css

This file was deleted.

5 changes: 3 additions & 2 deletions datagouv-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@
"remark-rehype": "^11.1.2",
"strip-markdown": "^6.0.0",
"stylefire": "^7.0.3",
"swagger-ui-dist": "^5.27.1",
"unified": "^11.0.5",
"unist-util-visit": "^5.0.0",
"vue-content-loader": "^2.0.1",
"vue-sonner": "^2.0.9",
"vue3-json-viewer": "^2.4.1",
"vue3-text-clamp": "^0.1.2",
"vue3-xml-viewer": "^0.0.14"
"vue3-xml-viewer": "^0.0.14",
"yaml": "^2.8.2"
},
"devDependencies": {
"@intlify/cli": "^0.13.1",
Expand All @@ -90,6 +90,7 @@
"eslint-plugin-vue": "^10.0",
"jiti": "^2.4.2",
"npm-run-all2": "^8.0",
"openapi-types": "^12.1.3",
"prettier": "^3.0.0",
"tailwindcss": "^4.0.8",
"typescript": "^5.7.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<Tooltip v-if="contentTypes.length > 1">
<div class="relative shrink-0">
<select
:value="modelValue"
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"
@change="$emit('update:modelValue', ($event.target as HTMLSelectElement).value)"
>
<option
v-for="ct in contentTypes"
:key="ct"
:value="ct"
>
{{ contentTypeLabel(ct) }}
</option>
</select>
<RiArrowDownSLine class="pointer-events-none absolute right-1 top-1/2 -translate-y-1/2 size-3.5 text-gray-medium" />
</div>
<template #tooltip>
{{ modelValue }}
</template>
</Tooltip>
<Tooltip v-else-if="contentTypes.length === 1">
<span
class="text-xs font-mono bg-white border border-gray-default rounded px-2 py-1 text-gray-medium shrink-0"
>
{{ contentTypeLabel(contentTypes[0]!) }}
</span>
<template #tooltip>
{{ contentTypes[0] }}
</template>
</Tooltip>
</template>

<script setup lang="ts">
import { RiArrowDownSLine } from '@remixicon/vue'
import Tooltip from '../Tooltip.vue'
import { contentTypeLabel } from './openapi'
defineProps<{
contentTypes: string[]
modelValue: string
}>()
defineEmits<{
'update:modelValue': [value: string]
}>()
</script>
164 changes: 164 additions & 0 deletions datagouv-components/src/components/OpenApiViewer/EndpointRequest.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<template>
<div class="border border-gray-default rounded">
<div
v-if="!tabs.length"
class="p-3 text-xs text-gray-medium"
>
{{ t("Aucun paramètre de requête") }}
</div>
<TabGroup
v-else
size="sm"
@change="onTabChange"
>
<div class="bg-gray-100 px-3 py-2 border-b border-gray-default flex items-center justify-between gap-2">
<TabList>
<Tab
v-for="tab in tabs"
:key="tab.key"
>
{{ tab.label }}
</Tab>
</TabList>
<ContentTypeSelect
v-if="activeTab === 'body' && bodyContentTypes.length"
:content-types="bodyContentTypes"
:model-value="selectedBodyContentType"
@update:model-value="selectedBodyContentType = $event"
/>
</div>
<TabPanels>
<TabPanel
v-for="tab in tabs"
:key="tab.key"
>
<div
v-if="tab.key === 'query'"
class="p-3"
>
<div class="space-y-0 divide-y divide-gray-100">
<div
v-for="param in queryParams"
:key="param.name"
class="py-2"
>
<div class="flex items-baseline gap-2">
<span class="font-mono text-xs text-gray-title">
{{ param.name }}
<span
v-if="param.required"
class="text-red-600"
>*</span>
</span>
<span class="font-mono text-xs text-gray-medium">{{ getSchemaType(endpoint.spec, param.schema) }}</span>
</div>
<p
v-if="param.description"
class="text-xs text-gray-medium mt-0.5 mb-0"
>
{{ param.description }}
</p>
</div>
</div>
</div>
<div
v-if="tab.key === 'path'"
class="p-3"
>
<div class="space-y-0 divide-y divide-gray-100">
<div
v-for="param in pathParams"
:key="param.name"
class="py-2"
>
<div class="flex items-baseline gap-2">
<span class="font-mono text-xs text-gray-title">
{{ param.name }}
<span class="text-red-600">*</span>
</span>
<span class="font-mono text-xs text-gray-medium">{{ getSchemaType(endpoint.spec, param.schema) }}</span>
</div>
<p
v-if="param.description"
class="text-xs text-gray-medium mt-0.5 mb-0"
>
{{ param.description }}
</p>
</div>
</div>
</div>
<div
v-if="tab.key === 'body'"
class="p-3"
>
<SchemaPanel
v-if="currentBodyMediaType?.schema"
:spec="endpoint.spec"
:schema="currentBodyMediaType.schema"
/>
</div>
</TabPanel>
</TabPanels>
</TabGroup>
</div>
</template>

<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import TabGroup from '../Tabs/TabGroup.vue'
import TabList from '../Tabs/TabList.vue'
import Tab from '../Tabs/Tab.vue'
import TabPanels from '../Tabs/TabPanels.vue'
import TabPanel from '../Tabs/TabPanel.vue'
import ContentTypeSelect from './ContentTypeSelect.vue'
import { useTranslation } from '../../composables/useTranslation'
import SchemaPanel from './SchemaPanel.vue'
import { getSchemaType, type Endpoint } from './openapi'

const props = defineProps<{
endpoint: Endpoint
}>()

const { t } = useTranslation()

const queryParams = computed(() => props.endpoint.parameters.filter(p => p.in === 'query'))
const pathParams = computed(() => props.endpoint.parameters.filter(p => p.in === 'path'))

const tabs = computed(() => {
const result: { key: string, label: string }[] = []
if (pathParams.value.length) {
result.push({ key: 'path', label: t('Path') })
}
if (queryParams.value.length) {
result.push({ key: 'query', label: t('Query') })
}
if (props.endpoint.requestBody) {
result.push({ key: 'body', label: t('Body') })
}
return result
})

const activeTabIndex = ref(0)
const activeTab = computed(() => tabs.value[activeTabIndex.value]?.key || '')
const selectedBodyContentType = ref('')

const bodyContentTypes = computed(() => {
if (!props.endpoint.requestBody?.content) return []
return Object.keys(props.endpoint.requestBody.content)
})

const currentBodyMediaType = computed(() => {
if (!props.endpoint.requestBody?.content) return null
const ct = selectedBodyContentType.value || bodyContentTypes.value[0]
if (!ct) return null
return props.endpoint.requestBody.content[ct] || null
})

watch(bodyContentTypes, (types) => {
selectedBodyContentType.value = types[0] || ''
}, { immediate: true })

function onTabChange(index: number) {
activeTabIndex.value = index
}
</script>
149 changes: 149 additions & 0 deletions datagouv-components/src/components/OpenApiViewer/EndpointResponses.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<template>
<div class="border border-gray-default rounded">
<TabGroup
size="sm"
@change="onTabChange"
>
<div class="bg-gray-100 px-3 py-2 border-b border-gray-default flex items-center gap-4">
<div
ref="tabListContainer"
class="overflow-x-auto flex-1 min-w-0"
:class="{ 'scroll-fade': canScrollRight }"
@scroll="onScroll"
>
<TabList>
<Tab
v-for="tab in tabs"
:key="tab.code"
>
<span
class="inline-block w-2 h-2 rounded-full mr-1.5"
:class="statusDotColor(tab.code)"
/>
{{ tab.code }}
</Tab>
</TabList>
</div>
<ContentTypeSelect
v-if="currentContentTypes.length"
:content-types="currentContentTypes"
:model-value="selectedContentType"
@update:model-value="selectedContentType = $event"
/>
</div>
<TabPanels>
<TabPanel
v-for="tab in tabs"
:key="tab.code"
>
<div class="p-3 space-y-3">
<p
v-if="tab.response.description"
class="text-xs text-gray-medium mb-0 pb-3 border-b border-gray-100"
>
{{ tab.response.description }}
</p>
<template v-if="currentMediaType?.schema">
<SchemaPanel
:spec="spec"
:schema="currentMediaType.schema"
/>
</template>
<p
v-else-if="!tab.response.content"
class="text-xs text-gray-medium mb-0"
>
{{ t("Pas de contenu") }}
</p>
</div>
</TabPanel>
</TabPanels>
</TabGroup>
</div>
</template>

<script setup lang="ts">
import { computed, ref, watch, useTemplateRef, onMounted, nextTick } from 'vue'
import TabGroup from '../Tabs/TabGroup.vue'
import TabList from '../Tabs/TabList.vue'
import Tab from '../Tabs/Tab.vue'
import TabPanels from '../Tabs/TabPanels.vue'
import TabPanel from '../Tabs/TabPanel.vue'
import ContentTypeSelect from './ContentTypeSelect.vue'
import { useTranslation } from '../../composables/useTranslation'
import SchemaPanel from './SchemaPanel.vue'
import type { OpenAPIV3 } from 'openapi-types'

const props = defineProps<{
responses: Record<string, OpenAPIV3.ResponseObject>
spec: OpenAPIV3.Document
}>()

const { t } = useTranslation()

const tabListContainer = useTemplateRef('tabListContainer')
const canScrollRight = ref(false)

function checkOverflow() {
const el = tabListContainer.value
if (!el) return
canScrollRight.value = el.scrollLeft + el.clientWidth < el.scrollWidth - 1
}

function onScroll() {
checkOverflow()
}

onMounted(checkOverflow)

const tabs = computed(() =>
Object.entries(props.responses).map(([code, response]) => ({ code, response })),
)

watch(tabs, () => {
nextTick(checkOverflow)
})

const activeTabIndex = ref(0)
const selectedContentType = ref('')

const currentContentTypes = computed(() => {
const tab = tabs.value[activeTabIndex.value]
if (!tab?.response.content) return []
return Object.keys(tab.response.content)
})

const currentMediaType = computed(() => {
const tab = tabs.value[activeTabIndex.value]
if (!tab?.response.content) return null
const ct = selectedContentType.value || currentContentTypes.value[0]
if (!ct) return null
return tab.response.content[ct] || null
})

watch(currentContentTypes, (types) => {
selectedContentType.value = types[0] || ''
}, { immediate: true })

function onTabChange(index: number) {
activeTabIndex.value = index
}

function statusDotColor(code: string): string {
if (code.startsWith('2')) return 'bg-green-600'
if (code.startsWith('3')) return 'bg-blue-600'
if (code.startsWith('4')) return 'bg-orange-500'
if (code.startsWith('5')) return 'bg-red-600'
return 'bg-gray-400'
}
</script>

<style scoped>
.scroll-fade {
mask-image: linear-gradient(to right, black calc(100% - 60px), transparent);
mask-size: 100% 100%;
mask-position: center;
padding-block: 4px;
margin-block: -4px;
}
</style>
Loading
Loading