1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42import type {
OpenAPIObject,
OperationObject,
} from 'openapi3-ts/oas30';
import type { ContentNavigationItem } from '@nuxt/content';
import { METHODS } from '@/constants';
import slugify from '~/utils/slugify';
export default function (spec: OpenAPIObject): ContentNavigationItem[] {
const byTag: Record<string, ContentNavigationItem[]> = {};
for (const [path, pathItemObject] of Object.entries(spec.paths)) {
for (const method of METHODS) {
if (pathItemObject[method]) {
const operationObject: OperationObject = pathItemObject[method];
for (const tag of operationObject.tags ?? []) {
if (!byTag[tag]) {
byTag[tag] = [];
}
byTag[tag].push({
title: operationObject.summary ?? path,
path: `/api/${tag.toLowerCase()}#${slugify(operationObject.summary!)}`,
exact: true,
exactHash: true,
});
}
}
}
}
return Object.entries(byTag).map(([tag, links]) => {
return {
title: tag,
to: `/api/${tag.toLowerCase()}`,
path: `/api/${tag.toLowerCase()}`,
children: links,
};
});
}