@dv.net/docs-vitepress-openapi 1.0.7
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/README.md +52 -0
- package/dist/docs-vitepress-openapi.client.cjs.js +1 -0
- package/dist/docs-vitepress-openapi.client.es.js +16 -0
- package/dist/docs-vitepress-openapi.css +1 -0
- package/dist/docs-vitepress-openapi.node.cjs.js +4102 -0
- package/dist/docs-vitepress-openapi.node.es.js +72981 -0
- package/dist/vanilla-picker-BAEwS4Fy.js +536 -0
- package/dist/vanilla-picker-m653iADl.cjs +8 -0
- package/package.json +80 -0
- package/src/client.ts +73 -0
- package/src/components/Common/Lazy/OALazy.vue +49 -0
- package/src/components/Common/Lazy/lazyBus.ts +8 -0
- package/src/components/Common/OACodeBlock.vue +91 -0
- package/src/components/Common/OACodeValue.vue +22 -0
- package/src/components/Common/OAHeaderBadges.vue +44 -0
- package/src/components/Common/OAHeading.vue +84 -0
- package/src/components/Common/OAInfo.vue +106 -0
- package/src/components/Common/OAIntroduction.vue +25 -0
- package/src/components/Common/OAJSONEditor.vue +41 -0
- package/src/components/Common/OAMarkdown.vue +28 -0
- package/src/components/Common/OAMethodBadge.vue +20 -0
- package/src/components/Common/OAServers.vue +42 -0
- package/src/components/Operation/OAOperation.vue +345 -0
- package/src/components/Operation/OAOperationTags.vue +30 -0
- package/src/components/Parameter/OAParameter.vue +80 -0
- package/src/components/Parameter/OAParameterAttribute.vue +44 -0
- package/src/components/Parameter/OAParameterExamples.vue +52 -0
- package/src/components/Parameter/OAParameters.vue +69 -0
- package/src/components/Path/OAPath.vue +347 -0
- package/src/components/Path/OAPathEndpoint.vue +99 -0
- package/src/components/Path/OAPaths.vue +62 -0
- package/src/components/Path/OAPathsByTag.vue +118 -0
- package/src/components/Path/OAPathsByTags.vue +99 -0
- package/src/components/Path/OAPathsSummary.vue +52 -0
- package/src/components/Playground/OAPlaygroundParameterInput.vue +97 -0
- package/src/components/Playground/OAPlaygroundParameters.vue +262 -0
- package/src/components/Playground/OAPlaygroundResponse.vue +74 -0
- package/src/components/Playground/OAPlaygroundSecurityInput.vue +44 -0
- package/src/components/Remote/OARemoteContext.vue +42 -0
- package/src/components/Remote/OARemoteOperation.vue +30 -0
- package/src/components/Remote/OARemoteRoot.vue +29 -0
- package/src/components/Remote/OARemoteSpec.vue +23 -0
- package/src/components/Request/OARequestBody.vue +24 -0
- package/src/components/Response/OAResponse.vue +81 -0
- package/src/components/Response/OAResponses.vue +119 -0
- package/src/components/Sample/OACodeSamples.vue +71 -0
- package/src/components/Schema/OASchemaPropertyAttributes.vue +44 -0
- package/src/components/Schema/OASchemaTabs.vue +90 -0
- package/src/components/Schema/OASchemaUI.vue +151 -0
- package/src/components/Security/OASecurity.vue +79 -0
- package/src/components/Security/OASecurityContent.vue +100 -0
- package/src/components/Spec/OASpec.vue +127 -0
- package/src/components/Spec/OASpecSkeleton.vue +26 -0
- package/src/components/Try/OATryItButton.vue +171 -0
- package/src/components/Try/OATryWithVariables.vue +105 -0
- package/src/components/index.ts +55 -0
- package/src/components/ui/badge/Badge.vue +18 -0
- package/src/components/ui/badge/index.ts +32 -0
- package/src/components/ui/button/Button.vue +28 -0
- package/src/components/ui/button/index.ts +37 -0
- package/src/components/ui/checkbox/Checkbox.vue +33 -0
- package/src/components/ui/checkbox/index.ts +1 -0
- package/src/components/ui/collapsible/Collapsible.vue +18 -0
- package/src/components/ui/collapsible/CollapsibleContent.vue +15 -0
- package/src/components/ui/collapsible/CollapsibleTrigger.vue +12 -0
- package/src/components/ui/collapsible/index.ts +3 -0
- package/src/components/ui/input/Input.vue +29 -0
- package/src/components/ui/input/index.ts +1 -0
- package/src/components/ui/label/Label.vue +29 -0
- package/src/components/ui/label/index.ts +1 -0
- package/src/components/ui/multiselect/Multiselect.vue +104 -0
- package/src/components/ui/select/Select.vue +15 -0
- package/src/components/ui/select/SelectContent.vue +56 -0
- package/src/components/ui/select/SelectGroup.vue +24 -0
- package/src/components/ui/select/SelectItem.vue +40 -0
- package/src/components/ui/select/SelectItemText.vue +12 -0
- package/src/components/ui/select/SelectLabel.vue +14 -0
- package/src/components/ui/select/SelectScrollDownButton.vue +29 -0
- package/src/components/ui/select/SelectScrollUpButton.vue +29 -0
- package/src/components/ui/select/SelectSeparator.vue +22 -0
- package/src/components/ui/select/SelectTrigger.vue +33 -0
- package/src/components/ui/select/SelectValue.vue +12 -0
- package/src/components/ui/select/index.ts +11 -0
- package/src/components/ui/tabs/Tabs.vue +15 -0
- package/src/components/ui/tabs/TabsContent.vue +24 -0
- package/src/components/ui/tabs/TabsList.vue +27 -0
- package/src/components/ui/tabs/TabsTrigger.vue +33 -0
- package/src/components/ui/tabs/index.ts +21 -0
- package/src/composables/useOpenapi.ts +70 -0
- package/src/composables/usePaths.ts +31 -0
- package/src/composables/usePlayground.ts +49 -0
- package/src/composables/useShiki.ts +46 -0
- package/src/composables/useSidebar.ts +301 -0
- package/src/composables/useTheme.ts +799 -0
- package/src/index.ts +8 -0
- package/src/json.css +251 -0
- package/src/lib/OpenApi.ts +254 -0
- package/src/lib/codeSamples/buildRequest.ts +149 -0
- package/src/lib/codeSamples/generateCodeSample.ts +20 -0
- package/src/lib/codeSamples/generateCodeSampleCurl.ts +150 -0
- package/src/lib/codeSamples/generateCodeSampleJavaScript.ts +29 -0
- package/src/lib/codeSamples/generateCodeSamplePhp.ts +50 -0
- package/src/lib/codeSamples/generateCodeSamplePython.ts +32 -0
- package/src/lib/codeSamples/request.ts +25 -0
- package/src/lib/constraintsParser.ts +30 -0
- package/src/lib/createOpenApiInstance.ts +18 -0
- package/src/lib/deepUnref.ts +76 -0
- package/src/lib/examples/getPropertyExample.ts +31 -0
- package/src/lib/examples/getPropertyExamples.ts +27 -0
- package/src/lib/examples/getSchemaExample.ts +38 -0
- package/src/lib/examples/getSchemaUiJson.ts +150 -0
- package/src/lib/examples/getSchemaUiXml.ts +9 -0
- package/src/lib/examples/hasExample.ts +26 -0
- package/src/lib/getOpenApiInstance.ts +39 -0
- package/src/lib/getSchemaUi.ts +280 -0
- package/src/lib/getSecurityUi.ts +33 -0
- package/src/lib/operationData.ts +24 -0
- package/src/lib/prepareOpenAPI/generateMissingOperationIds.ts +19 -0
- package/src/lib/prepareOpenAPI/generateMissingSummary.ts +20 -0
- package/src/lib/prepareOpenAPI/generateMissingTags.ts +36 -0
- package/src/lib/prepareOpenAPI/prepareOpenAPI.ts +35 -0
- package/src/lib/processOpenAPI.ts +131 -0
- package/src/lib/resolveCircularRef.ts +66 -0
- package/src/lib/sidebar/cleanSidebarItems.ts +19 -0
- package/src/lib/sidebar/ensureGroupTextSlashPrefix.ts +18 -0
- package/src/lib/sidebar/flatSidebarItems.ts +58 -0
- package/src/lib/sidebar/generateSidebarItemsByPaths.ts +132 -0
- package/src/lib/sidebar/mergeAdjacentGroups.ts +56 -0
- package/src/lib/sidebar/setItemCollapsedState.ts +15 -0
- package/src/lib/utils.ts +7 -0
- package/src/locales/en.json +50 -0
- package/src/locales/index.ts +4 -0
- package/src/style.css +180 -0
- package/src/types.ts +73 -0
- package/src/vite-env.d.ts +8 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { OpenAPI } from '@scalar/openapi-types'
|
|
2
|
+
|
|
3
|
+
interface SchemaNode {
|
|
4
|
+
key: string
|
|
5
|
+
value: OpenAPI.SchemaObject
|
|
6
|
+
parent: SchemaNode | null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function resolveCircularRef(schema: OpenAPI.SchemaObject): OpenAPI.SchemaObject {
|
|
10
|
+
const rootNode: SchemaNode = {
|
|
11
|
+
key: 'root',
|
|
12
|
+
value: schema,
|
|
13
|
+
parent: null,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
traverseNode(rootNode)
|
|
17
|
+
|
|
18
|
+
return schema
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function traverseNode(node: SchemaNode): void {
|
|
22
|
+
const { value } = node
|
|
23
|
+
|
|
24
|
+
if (typeof value !== 'object' || value === null) {
|
|
25
|
+
// Base case: leaf node or non-object node.
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const circularReference = detectCircularReference(node.parent, value)
|
|
30
|
+
|
|
31
|
+
if (circularReference) {
|
|
32
|
+
// Replace the circular reference with a descriptor object.
|
|
33
|
+
node.parent!.value[node.key] = {
|
|
34
|
+
type: 'object',
|
|
35
|
+
circularReference,
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
// Recursively traverse child nodes.
|
|
39
|
+
for (const [key, childValue] of Object.entries(value)) {
|
|
40
|
+
const childNode: SchemaNode = {
|
|
41
|
+
key,
|
|
42
|
+
value: childValue,
|
|
43
|
+
parent: node,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
traverseNode(childNode)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function detectCircularReference(ancestor: SchemaNode | null, value: any): string | null {
|
|
52
|
+
while (ancestor) {
|
|
53
|
+
if (ancestor.value === value) {
|
|
54
|
+
return buildReferencePath(ancestor)
|
|
55
|
+
}
|
|
56
|
+
ancestor = ancestor.parent
|
|
57
|
+
}
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function buildReferencePath(node: SchemaNode | null): string {
|
|
62
|
+
if (!node) {
|
|
63
|
+
return ''
|
|
64
|
+
}
|
|
65
|
+
return `${buildReferencePath(node.parent)}/${node.key}`
|
|
66
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DefaultTheme } from 'vitepress'
|
|
2
|
+
import type { OASidebarItem } from '../../composables/useSidebar'
|
|
3
|
+
|
|
4
|
+
export function cleanSidebarItems(result: (OASidebarItem[] | OASidebarItem)): DefaultTheme.SidebarItem[] | DefaultTheme.SidebarItem {
|
|
5
|
+
if (Array.isArray(result)) {
|
|
6
|
+
return result.map(cleanSidebarItems) as DefaultTheme.SidebarItem[]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (typeof result === 'object') {
|
|
10
|
+
return {
|
|
11
|
+
text: result.text,
|
|
12
|
+
...(result.collapsed === undefined ? {} : { collapsed: result.collapsed }),
|
|
13
|
+
...(result.link ? { link: result.link } : {}),
|
|
14
|
+
...(result.items ? { items: cleanSidebarItems(result.items) } : {}),
|
|
15
|
+
} as DefaultTheme.SidebarItem
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return result
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OASidebarItem } from '../../composables/useSidebar'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ensures that all group text starts with a slash for consistent path-like formatting.
|
|
5
|
+
*/
|
|
6
|
+
export function ensureGroupTextSlashPrefix(items: OASidebarItem[]): OASidebarItem[] {
|
|
7
|
+
return items.map((item: OASidebarItem) => {
|
|
8
|
+
if (item.items) {
|
|
9
|
+
item.items = ensureGroupTextSlashPrefix(item.items)
|
|
10
|
+
|
|
11
|
+
item.text = item.text?.startsWith('/') ? item.text : `/${item.text}`
|
|
12
|
+
} else if (item.text && !item.isOperation && !item.text.startsWith('/') && !item.text.includes('<span')) {
|
|
13
|
+
item.text = `/${item.text}`
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return item
|
|
17
|
+
})
|
|
18
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { OASidebarItem } from '../../composables/useSidebar'
|
|
2
|
+
|
|
3
|
+
export function flatSidebarItems(items: OASidebarItem[], flattenedItems: Record<string, OASidebarItem>, maxDepth: number, currentDepth: number = 1, parentText = ''): OASidebarItem[] {
|
|
4
|
+
return moveFlattenedItemsToParent(generateFlattenedItems(items, flattenedItems, maxDepth, currentDepth, parentText))
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function generateFlattenedItems(items: OASidebarItem[], flattenedItems: Record<string, OASidebarItem>, maxDepth: number, currentDepth: number, parentText = ''): OASidebarItem[] {
|
|
8
|
+
return items.map((item) => {
|
|
9
|
+
if (item.items) {
|
|
10
|
+
const basePath = parentText + item.text
|
|
11
|
+
|
|
12
|
+
if (currentDepth + 1 > maxDepth) {
|
|
13
|
+
item.flattenedItems = Object.keys(flattenedItems)
|
|
14
|
+
.filter(path => path.startsWith(basePath))
|
|
15
|
+
.map((path) => {
|
|
16
|
+
const item = flattenedItems[path]
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
...item,
|
|
20
|
+
items: item.items?.filter((i: OASidebarItem) => i.isOperation),
|
|
21
|
+
} as OASidebarItem
|
|
22
|
+
})
|
|
23
|
+
} else {
|
|
24
|
+
item.items = generateFlattenedItems(item.items, flattenedItems, maxDepth, currentDepth + 1, basePath)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return item
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function moveFlattenedItemsToParent(items: OASidebarItem[], parentText: string = ''): OASidebarItem[] {
|
|
33
|
+
const result: OASidebarItem[] = []
|
|
34
|
+
|
|
35
|
+
items.forEach((item) => {
|
|
36
|
+
if (item.flattenedItems) {
|
|
37
|
+
result.push(...item.flattenedItems.map((flattenedItem) => {
|
|
38
|
+
if (flattenedItem.items && item.text !== flattenedItem.text) {
|
|
39
|
+
const basePath = parentText + item.text
|
|
40
|
+
|
|
41
|
+
const remainingPath = flattenedItem.path?.replace(basePath, '')
|
|
42
|
+
|
|
43
|
+
flattenedItem.text = (item.text || '') + remainingPath
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return flattenedItem
|
|
47
|
+
}))
|
|
48
|
+
} else {
|
|
49
|
+
result.push(item)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (item.items) {
|
|
53
|
+
item.items = moveFlattenedItemsToParent(item.items, parentText + item.text)
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
return result
|
|
58
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from '@scalar/openapi-types'
|
|
2
|
+
import type { OASidebarItem, SidebarGroupTemplateFn, SidebarItemTemplateFn } from '../../composables/useSidebar'
|
|
3
|
+
import { httpVerbs } from '../../index'
|
|
4
|
+
import { ensureGroupTextSlashPrefix } from './ensureGroupTextSlashPrefix'
|
|
5
|
+
import { flatSidebarItems } from './flatSidebarItems'
|
|
6
|
+
import { mergeAdjacentGroups } from './mergeAdjacentGroups'
|
|
7
|
+
import { setItemCollapsedState } from './setItemCollapsedState'
|
|
8
|
+
|
|
9
|
+
export function generateSidebarItemsByPaths({
|
|
10
|
+
paths,
|
|
11
|
+
startsWith = '',
|
|
12
|
+
collapsible = true,
|
|
13
|
+
itemLinkPrefix = '',
|
|
14
|
+
depth = 6,
|
|
15
|
+
sidebarItemTemplate,
|
|
16
|
+
sidebarGroupTemplate,
|
|
17
|
+
}: {
|
|
18
|
+
paths: OpenAPIV3.PathsObject
|
|
19
|
+
startsWith?: string
|
|
20
|
+
collapsible?: boolean
|
|
21
|
+
itemLinkPrefix?: string
|
|
22
|
+
depth?: number
|
|
23
|
+
sidebarItemTemplate?: SidebarItemTemplateFn
|
|
24
|
+
sidebarGroupTemplate?: SidebarGroupTemplateFn
|
|
25
|
+
} = {
|
|
26
|
+
paths: {},
|
|
27
|
+
}): OASidebarItem[] {
|
|
28
|
+
let sidebarItems: OASidebarItem[] = []
|
|
29
|
+
|
|
30
|
+
const flattenedSidebarItems: Record<string, OASidebarItem> = {}
|
|
31
|
+
|
|
32
|
+
Object.keys(paths)
|
|
33
|
+
.filter(path => path.startsWith(startsWith))
|
|
34
|
+
.forEach((path) => {
|
|
35
|
+
const segments = path.split('/').filter(Boolean)
|
|
36
|
+
let currentGroups = sidebarItems
|
|
37
|
+
|
|
38
|
+
segments.forEach((segment, index) => {
|
|
39
|
+
const isLastSegment = index === segments.length - 1
|
|
40
|
+
const fullPath = `/${segments.slice(0, index + 1).join('/')}`
|
|
41
|
+
|
|
42
|
+
const group = findOrCreateGroup(currentGroups, segment, fullPath)
|
|
43
|
+
|
|
44
|
+
if (isLastSegment) {
|
|
45
|
+
const operationsItems = httpVerbs
|
|
46
|
+
.map((method) => {
|
|
47
|
+
const operation = paths[path] ? paths[path][method] : null
|
|
48
|
+
|
|
49
|
+
if (!operation) {
|
|
50
|
+
return null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
text: sidebarItemTemplate ? sidebarItemTemplate(method as OpenAPIV3.HttpMethods, fullPath) : `[${method.toUpperCase()}] ${operation.summary}`,
|
|
55
|
+
link: `${itemLinkPrefix}${operation.operationId}`,
|
|
56
|
+
method,
|
|
57
|
+
path: fullPath,
|
|
58
|
+
isOperation: true,
|
|
59
|
+
operation,
|
|
60
|
+
} as OASidebarItem
|
|
61
|
+
})
|
|
62
|
+
.filter((item): item is OASidebarItem => item !== null)
|
|
63
|
+
|
|
64
|
+
group.items = group.items || []
|
|
65
|
+
group.items.push(...operationsItems)
|
|
66
|
+
|
|
67
|
+
flattenedSidebarItems[fullPath] = group
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Move to the next level of hierarchy.
|
|
71
|
+
currentGroups = group.items as OASidebarItem[]
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
sidebarItems = mergeAdjacentGroups(sidebarItems)
|
|
76
|
+
|
|
77
|
+
sidebarItems = ensureGroupTextSlashPrefix(sidebarItems)
|
|
78
|
+
|
|
79
|
+
if (collapsible) {
|
|
80
|
+
sidebarItems = setItemCollapsedState(sidebarItems)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
sidebarItems = flatSidebarItems(sidebarItems, flattenedSidebarItems, depth)
|
|
84
|
+
|
|
85
|
+
if (sidebarGroupTemplate) {
|
|
86
|
+
sidebarItems = applySidebarGroupTemplate(sidebarItems, sidebarGroupTemplate)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return sidebarItems
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Find or create a group in the current hierarchy.
|
|
94
|
+
*/
|
|
95
|
+
function findOrCreateGroup(
|
|
96
|
+
currentGroups: OASidebarItem[],
|
|
97
|
+
segment: string,
|
|
98
|
+
fullPath: string,
|
|
99
|
+
): OASidebarItem {
|
|
100
|
+
let group = currentGroups.find(
|
|
101
|
+
g => g.text === segment && g.path === fullPath,
|
|
102
|
+
) as OASidebarItem | undefined
|
|
103
|
+
|
|
104
|
+
if (!group) {
|
|
105
|
+
group = {
|
|
106
|
+
text: segment,
|
|
107
|
+
path: fullPath,
|
|
108
|
+
items: [],
|
|
109
|
+
}
|
|
110
|
+
currentGroups.push(group)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return group
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function applySidebarGroupTemplate(
|
|
117
|
+
sidebarItems: OASidebarItem[],
|
|
118
|
+
sidebarGroupTemplate: SidebarGroupTemplateFn,
|
|
119
|
+
currentDepth: number = 1,
|
|
120
|
+
): OASidebarItem[] {
|
|
121
|
+
return sidebarItems.map((item) => {
|
|
122
|
+
if (item.text && item.path && item.items && item.items.length) {
|
|
123
|
+
item.text = sidebarGroupTemplate(item.path, currentDepth)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (item.items) {
|
|
127
|
+
item.items = applySidebarGroupTemplate(item.items as OASidebarItem[], sidebarGroupTemplate, currentDepth + 1)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return item
|
|
131
|
+
})
|
|
132
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { OASidebarItem } from '../../composables/useSidebar'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Recursively merges sidebar groups by combining groups that have only one child
|
|
5
|
+
* and no direct operation links.
|
|
6
|
+
*/
|
|
7
|
+
export function mergeAdjacentGroups(items: OASidebarItem[]): OASidebarItem[] {
|
|
8
|
+
if (!Array.isArray(items)) {
|
|
9
|
+
return items
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return items.reduce<OASidebarItem[]>((mergedGroups, currentGroup) => {
|
|
13
|
+
// If group has no items, return it as-is.
|
|
14
|
+
if (!currentGroup.items?.length) {
|
|
15
|
+
mergedGroups.push(currentGroup)
|
|
16
|
+
return mergedGroups
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Check if the group can be merged (single child, no direct operation links).
|
|
20
|
+
const canMergeGroup
|
|
21
|
+
= currentGroup.items.length === 1
|
|
22
|
+
&& !currentGroup.items.some(item => 'link' in item)
|
|
23
|
+
|
|
24
|
+
if (canMergeGroup) {
|
|
25
|
+
const childGroup = currentGroup.items[0] as OASidebarItem
|
|
26
|
+
|
|
27
|
+
// Recursively process the child group.
|
|
28
|
+
const processedChildGroup = mergeAdjacentGroups([childGroup])[0]
|
|
29
|
+
|
|
30
|
+
// Update the child group with merged information.
|
|
31
|
+
processedChildGroup.text = constructMergedGroupText(currentGroup.text as string, processedChildGroup.text as string)
|
|
32
|
+
processedChildGroup.path = processedChildGroup.path || currentGroup.path
|
|
33
|
+
|
|
34
|
+
mergedGroups.push(processedChildGroup)
|
|
35
|
+
return mergedGroups
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Recursively process nested groups.
|
|
39
|
+
currentGroup.items = mergeAdjacentGroups(currentGroup.items as OASidebarItem[])
|
|
40
|
+
|
|
41
|
+
mergedGroups.push(currentGroup)
|
|
42
|
+
return mergedGroups
|
|
43
|
+
}, [])
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Constructs a merged group text by combining parent and child group texts.
|
|
48
|
+
*/
|
|
49
|
+
function constructMergedGroupText(parentGroupText: string, childGroupText: string): string {
|
|
50
|
+
// Ensure child text starts with a slash for consistent path-like formatting.
|
|
51
|
+
const formattedChildText = childGroupText.startsWith('/')
|
|
52
|
+
? childGroupText
|
|
53
|
+
: `/${childGroupText}`
|
|
54
|
+
|
|
55
|
+
return parentGroupText + formattedChildText
|
|
56
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { OASidebarItem } from '../../composables/useSidebar'
|
|
2
|
+
|
|
3
|
+
export function setItemCollapsedState(items: OASidebarItem[]): OASidebarItem[] {
|
|
4
|
+
return items.map((item) => {
|
|
5
|
+
if (item.items) {
|
|
6
|
+
item.collapsed = !item.items.length
|
|
7
|
+
|
|
8
|
+
if (item.items.some((item: OASidebarItem) => 'items' in item)) {
|
|
9
|
+
item.items = setItemCollapsedState(item.items as OASidebarItem[])
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return item
|
|
14
|
+
})
|
|
15
|
+
}
|
package/src/lib/utils.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Response": "Response",
|
|
3
|
+
"Responses": "Responses",
|
|
4
|
+
"Try it out": "Try it out",
|
|
5
|
+
"Loading...": "Loading...",
|
|
6
|
+
"Samples": "Samples",
|
|
7
|
+
"Response time": "Response time",
|
|
8
|
+
"Parameters": "Parameters",
|
|
9
|
+
"Path Parameters": "Path Parameters",
|
|
10
|
+
"Query Parameters": "Query Parameters",
|
|
11
|
+
"Required": "Required",
|
|
12
|
+
"Key": "Key",
|
|
13
|
+
"Value": "Value",
|
|
14
|
+
"Variables": "Variables",
|
|
15
|
+
"Powered by": "Powered by",
|
|
16
|
+
"Type": "Type",
|
|
17
|
+
"Header Parameters": "Header Parameters",
|
|
18
|
+
"Headers": "Headers",
|
|
19
|
+
"Request Body": "Request Body",
|
|
20
|
+
"Schema": "Schema",
|
|
21
|
+
"JSON": "JSON",
|
|
22
|
+
"Authorizations": "Authorizations",
|
|
23
|
+
"Authorization": "Authorization",
|
|
24
|
+
"Use example": "Use example",
|
|
25
|
+
"Deprecated": "Deprecated",
|
|
26
|
+
"Body": "Body",
|
|
27
|
+
"Terms of Service": "Terms of Service",
|
|
28
|
+
"License": "License",
|
|
29
|
+
"Contact": "Contact",
|
|
30
|
+
"API Documentation": "API Documentation",
|
|
31
|
+
"External Documentation": "External Documentation",
|
|
32
|
+
"Servers": "Servers",
|
|
33
|
+
"Server": "Server",
|
|
34
|
+
"Your browser does not support the audio element.": "Your browser does not support the audio element.",
|
|
35
|
+
"Unrecognized response type. Raw content:": "Unrecognized response type. Raw content:",
|
|
36
|
+
"Download file": "Download file",
|
|
37
|
+
"Select...": "Select...",
|
|
38
|
+
"operation.badgePrefix.operationId": "ID: ",
|
|
39
|
+
"Content-Type": "Content-Type",
|
|
40
|
+
"Hide operations": "Hide operations",
|
|
41
|
+
"Show operations": "Show operations",
|
|
42
|
+
"Operations": "Operations",
|
|
43
|
+
"Default": "Default",
|
|
44
|
+
"Example": "Example",
|
|
45
|
+
"Examples": "Examples",
|
|
46
|
+
"tags.goTo": "View {tag} operations",
|
|
47
|
+
"or": "or",
|
|
48
|
+
"Enum": "Enum",
|
|
49
|
+
"Copy endpoint": "Copy endpoint"
|
|
50
|
+
}
|
package/src/style.css
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
@layer base {
|
|
6
|
+
:root {
|
|
7
|
+
--card: 0 0% 100%;
|
|
8
|
+
--card-foreground: 222.2 84% 4.9%;
|
|
9
|
+
|
|
10
|
+
--input: 214.3 31.8% 91.4%;
|
|
11
|
+
|
|
12
|
+
--primary: 222.2 47.4% 11.2%;
|
|
13
|
+
--primary-foreground: 210 40% 98%;
|
|
14
|
+
|
|
15
|
+
--secondary: 210 40% 96.1%;
|
|
16
|
+
--secondary-foreground: 222.2 47.4% 11.2%;
|
|
17
|
+
|
|
18
|
+
--accent: 210 40% 96.1%;
|
|
19
|
+
--accent-foreground: 222.2 47.4% 11.2%;
|
|
20
|
+
|
|
21
|
+
--destructive: 0 84.2% 60.2%;
|
|
22
|
+
--destructive-foreground: 210 40% 98%;
|
|
23
|
+
|
|
24
|
+
--ring: 222.2 84% 4.9%;
|
|
25
|
+
|
|
26
|
+
--radius: 0.5rem;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.dark {
|
|
30
|
+
--card: 222.2 84% 4.9%;
|
|
31
|
+
--card-foreground: 210 40% 98%;
|
|
32
|
+
|
|
33
|
+
--input: 217.2 32.6% 17.5%;
|
|
34
|
+
|
|
35
|
+
--primary: 210 40% 98%;
|
|
36
|
+
--primary-foreground: 222.2 47.4% 11.2%;
|
|
37
|
+
|
|
38
|
+
--secondary: 217.2 32.6% 17.5%;
|
|
39
|
+
--secondary-foreground: 210 40% 98%;
|
|
40
|
+
|
|
41
|
+
--accent: 217.2 32.6% 17.5%;
|
|
42
|
+
--accent-foreground: 210 40% 98%;
|
|
43
|
+
|
|
44
|
+
--destructive: 0 62.8% 30.6%;
|
|
45
|
+
--destructive-foreground: 210 40% 98%;
|
|
46
|
+
|
|
47
|
+
--ring: 212.7 26.8% 83.9%;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@layer components {
|
|
52
|
+
.border,
|
|
53
|
+
.border-r,
|
|
54
|
+
.border-l,
|
|
55
|
+
.border-t,
|
|
56
|
+
.border-b,
|
|
57
|
+
.border-x,
|
|
58
|
+
.border-y {
|
|
59
|
+
border-color: var(--vp-c-divider);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
Sidebar
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
.OASidebarItem {
|
|
68
|
+
grid-template-columns: 41px auto;
|
|
69
|
+
@apply grid items-center w-full space-x-1;
|
|
70
|
+
}
|
|
71
|
+
.OASidebarItem-badge {
|
|
72
|
+
@apply px-1 py-0.5 text-xs rounded w-fit ml-auto;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
Method badges
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
.OAMethodBadge--get {
|
|
80
|
+
@apply bg-green-200 text-green-800
|
|
81
|
+
group-hover/oaSidebarItem:bg-green-300 hover:bg-green-300
|
|
82
|
+
dark:bg-green-800 dark:text-green-200
|
|
83
|
+
dark:group-hover/oaSidebarItem:bg-green-700 dark:hover:bg-green-700;
|
|
84
|
+
}
|
|
85
|
+
.OAMethodBadge--post {
|
|
86
|
+
@apply bg-blue-200 text-blue-800
|
|
87
|
+
group-hover/oaSidebarItem:bg-blue-300 hover:bg-blue-300
|
|
88
|
+
dark:bg-blue-800 dark:text-blue-200
|
|
89
|
+
dark:group-hover/oaSidebarItem:bg-blue-700 dark:hover:bg-blue-700;
|
|
90
|
+
}
|
|
91
|
+
.OAMethodBadge--put {
|
|
92
|
+
@apply bg-yellow-200 text-yellow-800
|
|
93
|
+
group-hover/oaSidebarItem:bg-yellow-300 hover:bg-yellow-300
|
|
94
|
+
dark:bg-yellow-800 dark:text-yellow-200
|
|
95
|
+
dark:group-hover/oaSidebarItem:bg-yellow-700 dark:hover:bg-yellow-700;
|
|
96
|
+
}
|
|
97
|
+
.OAMethodBadge--delete {
|
|
98
|
+
@apply bg-red-200 text-red-800
|
|
99
|
+
group-hover/oaSidebarItem:bg-red-300 hover:bg-red-300
|
|
100
|
+
dark:bg-red-800 dark:text-red-200
|
|
101
|
+
dark:group-hover/oaSidebarItem:bg-red-700 dark:hover:bg-red-700;
|
|
102
|
+
}
|
|
103
|
+
.OAMethodBadge--patch {
|
|
104
|
+
@apply bg-purple-200 text-purple-800
|
|
105
|
+
group-hover/oaSidebarItem:bg-purple-300 hover:bg-purple-300
|
|
106
|
+
dark:bg-purple-800 dark:text-purple-200
|
|
107
|
+
dark:group-hover/oaSidebarItem:bg-purple-700 dark:hover:bg-purple-700;
|
|
108
|
+
}
|
|
109
|
+
.OAMethodBadge--options {
|
|
110
|
+
@apply bg-indigo-200 text-indigo-800
|
|
111
|
+
group-hover/oaSidebarItem:bg-indigo-300 hover:bg-indigo-300
|
|
112
|
+
dark:bg-indigo-800 dark:text-indigo-200
|
|
113
|
+
dark:group-hover/oaSidebarItem:bg-indigo-700 dark:hover:bg-indigo-700;
|
|
114
|
+
}
|
|
115
|
+
.OAMethodBadge--head {
|
|
116
|
+
@apply bg-pink-200 text-pink-800
|
|
117
|
+
group-hover/oaSidebarItem:bg-pink-300 hover:bg-pink-300
|
|
118
|
+
dark:bg-pink-800 dark:text-pink-200
|
|
119
|
+
dark:group-hover/oaSidebarItem:bg-pink-700 dark:hover:bg-pink-700;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.OAMethodBadge--delete, .OAMethodBadge--patch, .OAMethodBadge--options {
|
|
123
|
+
font-size: 8px;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.text-method-get {
|
|
127
|
+
@apply text-green-800 dark:text-green-200;
|
|
128
|
+
}
|
|
129
|
+
.text-method-post {
|
|
130
|
+
@apply text-blue-800 dark:text-blue-200;
|
|
131
|
+
}
|
|
132
|
+
.text-method-put {
|
|
133
|
+
@apply text-yellow-800 dark:text-yellow-200;
|
|
134
|
+
}
|
|
135
|
+
.text-method-delete {
|
|
136
|
+
@apply text-red-800 dark:text-red-200;
|
|
137
|
+
}
|
|
138
|
+
.text-method-patch {
|
|
139
|
+
@apply text-purple-800 dark:text-purple-200;
|
|
140
|
+
}
|
|
141
|
+
.text-method-options {
|
|
142
|
+
@apply text-indigo-800 dark:text-indigo-200;
|
|
143
|
+
}
|
|
144
|
+
.text-method-head {
|
|
145
|
+
@apply text-pink-800 dark:text-pink-200;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
Next links
|
|
150
|
+
*/
|
|
151
|
+
.pager-link.next .title .OASidebarItem {
|
|
152
|
+
@apply justify-end;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/*
|
|
156
|
+
Code blocks
|
|
157
|
+
*/
|
|
158
|
+
.shiki.vitesse-light,
|
|
159
|
+
.shiki.vitesse-dark,
|
|
160
|
+
.shiki.github-light,
|
|
161
|
+
.shiki.github-dark {
|
|
162
|
+
@apply bg-transparent !important;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
OAMarkdown
|
|
167
|
+
*/
|
|
168
|
+
.oa-doc p {
|
|
169
|
+
@apply my-1 !important;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
OAPath
|
|
174
|
+
*/
|
|
175
|
+
.VPDoc.has-aside .OAPathContentEnd {
|
|
176
|
+
@apply px-2;
|
|
177
|
+
}
|
|
178
|
+
.VPDoc:not(.has-aside) .OAPathContentEnd {
|
|
179
|
+
@apply sm:px-6;
|
|
180
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { OpenAPI, OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types'
|
|
2
|
+
import type { RemovableRef } from '@vueuse/core'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Slots required for OAOperation component.
|
|
6
|
+
*/
|
|
7
|
+
export type OperationSlot =
|
|
8
|
+
| 'header'
|
|
9
|
+
| 'tags'
|
|
10
|
+
| 'path'
|
|
11
|
+
| 'description'
|
|
12
|
+
| 'security'
|
|
13
|
+
| 'parameters'
|
|
14
|
+
| 'request-body'
|
|
15
|
+
| 'responses'
|
|
16
|
+
| 'try-it'
|
|
17
|
+
| 'code-samples'
|
|
18
|
+
| 'branding'
|
|
19
|
+
| 'footer'
|
|
20
|
+
// TODO: Implement these slots.
|
|
21
|
+
// | 'summary'
|
|
22
|
+
// | 'servers'
|
|
23
|
+
|
|
24
|
+
export type ParsedOpenAPI = OpenAPI.Document & {
|
|
25
|
+
paths: OpenAPIV3.PathsObject & OpenAPIV3_1.PathsObject & {
|
|
26
|
+
[key: string]: OpenAPIV3.PathItemObject & OpenAPIV3_1.PathItemObject & {
|
|
27
|
+
[key: string]: ParsedOperation
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type ParsedOperation = OpenAPIV3.OperationObject & OpenAPIV3_1.OperationObject & {
|
|
33
|
+
operationId: string
|
|
34
|
+
security?: OpenAPIV3.SecurityRequirementObject[] & OpenAPIV3_1.SecurityRequirementObject[] & {
|
|
35
|
+
[key: string]: string[]
|
|
36
|
+
}
|
|
37
|
+
securityUi?: SecurityUi
|
|
38
|
+
requestBody: OpenAPIV3.RequestBodyObject & OpenAPIV3_1.RequestBodyObject & {
|
|
39
|
+
content: ParsedContent
|
|
40
|
+
}
|
|
41
|
+
responses: OpenAPIV3.ResponsesObject & OpenAPIV3_1.ResponsesObject & {
|
|
42
|
+
[key: string]: OpenAPIV3.ResponseObject & OpenAPIV3_1.ResponseObject & {
|
|
43
|
+
content: {
|
|
44
|
+
[key: string]: ParsedContent
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ParsedContent = OpenAPIV3.MediaTypeObject & OpenAPIV3_1.MediaTypeObject & {
|
|
51
|
+
schema: OpenAPIV3.SchemaObject & OpenAPIV3_1.SchemaObject
|
|
52
|
+
ui?: any
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type OperationObject = OpenAPIV3.Document | OpenAPIV3_1.OperationObject
|
|
56
|
+
|
|
57
|
+
export type PlaygroundSecurityScheme = OpenAPIV3.HttpSecurityScheme & OpenAPIV3.ApiKeySecurityScheme & OpenAPIV3.OAuth2SecurityScheme & OpenAPIV3.OpenIdSecurityScheme & {
|
|
58
|
+
playgroundValue: RemovableRef<any>
|
|
59
|
+
label: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface SecurityUi extends Array<SecurityUiItem> {}
|
|
63
|
+
|
|
64
|
+
export interface SecurityUiItem {
|
|
65
|
+
id: string
|
|
66
|
+
schemes: {
|
|
67
|
+
[key: string]: OpenAPIV3.SecuritySchemeObject
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type OAExampleObject = OpenAPI.ExampleObject & {
|
|
72
|
+
isAutogenerated?: boolean
|
|
73
|
+
}
|