Skip to content

Commit 473e784

Browse files
committed
Improve the header of the api doc
1 parent 7fc0732 commit 473e784

5 files changed

Lines changed: 70 additions & 7 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<script setup lang="ts">
2+
import { computed } from "vue";
3+
4+
const props = defineProps<{
5+
operation: { summary: string; operationId: string };
6+
method: string;
7+
path: string;
8+
}>();
9+
10+
const text = computed(() => {
11+
return `${props.method.toUpperCase()} ${props.path}`;
12+
});
13+
14+
const id = computed(() => {
15+
return props.operation.operationId;
16+
});
17+
18+
const summary = computed(() => {
19+
if (props.operation.summary.startsWith(props.method.toUpperCase())) {
20+
return undefined;
21+
}
22+
return props.operation.summary;
23+
});
24+
</script>
25+
26+
<template>
27+
<div class="flex flex-col">
28+
<h1 :id="id">
29+
<a
30+
class="header-anchor"
31+
:href="`#${id}`"
32+
:aria-label="`Permalink to ${text}`"
33+
>&#8203;</a
34+
>
35+
{{ text }}
36+
</h1>
37+
<p v-if="summary">{{ summary }}</p>
38+
</div>
39+
</template>
40+
41+
<style scoped>
42+
.oaspec-header {
43+
font-family: var(--vp-font-family-mono);
44+
font-size: 0.9rem;
45+
font-weight: 600;
46+
color: var(--vp-c-text-1);
47+
}
48+
</style>

.vitepress/theme/index.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import "./custom.css";
66
import { data } from "../data/openapi.data.mjs";
77
import ProContainer from "../components/Pro.vue";
88
import VideoContainer from "../components/Video.vue";
9+
import OASpecHeader from "../components/OASpecHeader.vue";
910
import type { Theme } from "vitepress";
1011

1112
export default {
1213
extends: DefaultTheme,
1314
enhanceApp(ctx) {
1415
ctx.app.component("ProContainer", ProContainer);
1516
ctx.app.component("VideoContainer", VideoContainer);
17+
ctx.app.component("OASpecHeader", OASpecHeader);
1618

1719
useOpenapi({
1820
spec: data,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"eslint": "9.28.0",
2929
"typescript": "5.6.2",
3030
"vitepress": "1.2.2",
31-
"vitepress-openapi": "0.0.3-alpha.83",
31+
"vitepress-openapi": "0.1.13",
3232
"vitepress-plugin-llms": "1.5.1",
3333
"vue": "3.5.16"
3434
}

pnpm-lock.yaml

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/reference/api.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ outline: [1, 1]
44
title: API
55
---
66

7-
<OASpec hide-branding />
7+
<OASpec
8+
:tags='["api"]'
9+
hide-branding
10+
>
11+
<template #header="header">
12+
<OASpecHeader :operation="header.operation" :method="header.method" :path="header.path" />
13+
</template>
14+
</OASpec>

0 commit comments

Comments
 (0)