@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.
Files changed (135) hide show
  1. package/README.md +52 -0
  2. package/dist/docs-vitepress-openapi.client.cjs.js +1 -0
  3. package/dist/docs-vitepress-openapi.client.es.js +16 -0
  4. package/dist/docs-vitepress-openapi.css +1 -0
  5. package/dist/docs-vitepress-openapi.node.cjs.js +4102 -0
  6. package/dist/docs-vitepress-openapi.node.es.js +72981 -0
  7. package/dist/vanilla-picker-BAEwS4Fy.js +536 -0
  8. package/dist/vanilla-picker-m653iADl.cjs +8 -0
  9. package/package.json +80 -0
  10. package/src/client.ts +73 -0
  11. package/src/components/Common/Lazy/OALazy.vue +49 -0
  12. package/src/components/Common/Lazy/lazyBus.ts +8 -0
  13. package/src/components/Common/OACodeBlock.vue +91 -0
  14. package/src/components/Common/OACodeValue.vue +22 -0
  15. package/src/components/Common/OAHeaderBadges.vue +44 -0
  16. package/src/components/Common/OAHeading.vue +84 -0
  17. package/src/components/Common/OAInfo.vue +106 -0
  18. package/src/components/Common/OAIntroduction.vue +25 -0
  19. package/src/components/Common/OAJSONEditor.vue +41 -0
  20. package/src/components/Common/OAMarkdown.vue +28 -0
  21. package/src/components/Common/OAMethodBadge.vue +20 -0
  22. package/src/components/Common/OAServers.vue +42 -0
  23. package/src/components/Operation/OAOperation.vue +345 -0
  24. package/src/components/Operation/OAOperationTags.vue +30 -0
  25. package/src/components/Parameter/OAParameter.vue +80 -0
  26. package/src/components/Parameter/OAParameterAttribute.vue +44 -0
  27. package/src/components/Parameter/OAParameterExamples.vue +52 -0
  28. package/src/components/Parameter/OAParameters.vue +69 -0
  29. package/src/components/Path/OAPath.vue +347 -0
  30. package/src/components/Path/OAPathEndpoint.vue +99 -0
  31. package/src/components/Path/OAPaths.vue +62 -0
  32. package/src/components/Path/OAPathsByTag.vue +118 -0
  33. package/src/components/Path/OAPathsByTags.vue +99 -0
  34. package/src/components/Path/OAPathsSummary.vue +52 -0
  35. package/src/components/Playground/OAPlaygroundParameterInput.vue +97 -0
  36. package/src/components/Playground/OAPlaygroundParameters.vue +262 -0
  37. package/src/components/Playground/OAPlaygroundResponse.vue +74 -0
  38. package/src/components/Playground/OAPlaygroundSecurityInput.vue +44 -0
  39. package/src/components/Remote/OARemoteContext.vue +42 -0
  40. package/src/components/Remote/OARemoteOperation.vue +30 -0
  41. package/src/components/Remote/OARemoteRoot.vue +29 -0
  42. package/src/components/Remote/OARemoteSpec.vue +23 -0
  43. package/src/components/Request/OARequestBody.vue +24 -0
  44. package/src/components/Response/OAResponse.vue +81 -0
  45. package/src/components/Response/OAResponses.vue +119 -0
  46. package/src/components/Sample/OACodeSamples.vue +71 -0
  47. package/src/components/Schema/OASchemaPropertyAttributes.vue +44 -0
  48. package/src/components/Schema/OASchemaTabs.vue +90 -0
  49. package/src/components/Schema/OASchemaUI.vue +151 -0
  50. package/src/components/Security/OASecurity.vue +79 -0
  51. package/src/components/Security/OASecurityContent.vue +100 -0
  52. package/src/components/Spec/OASpec.vue +127 -0
  53. package/src/components/Spec/OASpecSkeleton.vue +26 -0
  54. package/src/components/Try/OATryItButton.vue +171 -0
  55. package/src/components/Try/OATryWithVariables.vue +105 -0
  56. package/src/components/index.ts +55 -0
  57. package/src/components/ui/badge/Badge.vue +18 -0
  58. package/src/components/ui/badge/index.ts +32 -0
  59. package/src/components/ui/button/Button.vue +28 -0
  60. package/src/components/ui/button/index.ts +37 -0
  61. package/src/components/ui/checkbox/Checkbox.vue +33 -0
  62. package/src/components/ui/checkbox/index.ts +1 -0
  63. package/src/components/ui/collapsible/Collapsible.vue +18 -0
  64. package/src/components/ui/collapsible/CollapsibleContent.vue +15 -0
  65. package/src/components/ui/collapsible/CollapsibleTrigger.vue +12 -0
  66. package/src/components/ui/collapsible/index.ts +3 -0
  67. package/src/components/ui/input/Input.vue +29 -0
  68. package/src/components/ui/input/index.ts +1 -0
  69. package/src/components/ui/label/Label.vue +29 -0
  70. package/src/components/ui/label/index.ts +1 -0
  71. package/src/components/ui/multiselect/Multiselect.vue +104 -0
  72. package/src/components/ui/select/Select.vue +15 -0
  73. package/src/components/ui/select/SelectContent.vue +56 -0
  74. package/src/components/ui/select/SelectGroup.vue +24 -0
  75. package/src/components/ui/select/SelectItem.vue +40 -0
  76. package/src/components/ui/select/SelectItemText.vue +12 -0
  77. package/src/components/ui/select/SelectLabel.vue +14 -0
  78. package/src/components/ui/select/SelectScrollDownButton.vue +29 -0
  79. package/src/components/ui/select/SelectScrollUpButton.vue +29 -0
  80. package/src/components/ui/select/SelectSeparator.vue +22 -0
  81. package/src/components/ui/select/SelectTrigger.vue +33 -0
  82. package/src/components/ui/select/SelectValue.vue +12 -0
  83. package/src/components/ui/select/index.ts +11 -0
  84. package/src/components/ui/tabs/Tabs.vue +15 -0
  85. package/src/components/ui/tabs/TabsContent.vue +24 -0
  86. package/src/components/ui/tabs/TabsList.vue +27 -0
  87. package/src/components/ui/tabs/TabsTrigger.vue +33 -0
  88. package/src/components/ui/tabs/index.ts +21 -0
  89. package/src/composables/useOpenapi.ts +70 -0
  90. package/src/composables/usePaths.ts +31 -0
  91. package/src/composables/usePlayground.ts +49 -0
  92. package/src/composables/useShiki.ts +46 -0
  93. package/src/composables/useSidebar.ts +301 -0
  94. package/src/composables/useTheme.ts +799 -0
  95. package/src/index.ts +8 -0
  96. package/src/json.css +251 -0
  97. package/src/lib/OpenApi.ts +254 -0
  98. package/src/lib/codeSamples/buildRequest.ts +149 -0
  99. package/src/lib/codeSamples/generateCodeSample.ts +20 -0
  100. package/src/lib/codeSamples/generateCodeSampleCurl.ts +150 -0
  101. package/src/lib/codeSamples/generateCodeSampleJavaScript.ts +29 -0
  102. package/src/lib/codeSamples/generateCodeSamplePhp.ts +50 -0
  103. package/src/lib/codeSamples/generateCodeSamplePython.ts +32 -0
  104. package/src/lib/codeSamples/request.ts +25 -0
  105. package/src/lib/constraintsParser.ts +30 -0
  106. package/src/lib/createOpenApiInstance.ts +18 -0
  107. package/src/lib/deepUnref.ts +76 -0
  108. package/src/lib/examples/getPropertyExample.ts +31 -0
  109. package/src/lib/examples/getPropertyExamples.ts +27 -0
  110. package/src/lib/examples/getSchemaExample.ts +38 -0
  111. package/src/lib/examples/getSchemaUiJson.ts +150 -0
  112. package/src/lib/examples/getSchemaUiXml.ts +9 -0
  113. package/src/lib/examples/hasExample.ts +26 -0
  114. package/src/lib/getOpenApiInstance.ts +39 -0
  115. package/src/lib/getSchemaUi.ts +280 -0
  116. package/src/lib/getSecurityUi.ts +33 -0
  117. package/src/lib/operationData.ts +24 -0
  118. package/src/lib/prepareOpenAPI/generateMissingOperationIds.ts +19 -0
  119. package/src/lib/prepareOpenAPI/generateMissingSummary.ts +20 -0
  120. package/src/lib/prepareOpenAPI/generateMissingTags.ts +36 -0
  121. package/src/lib/prepareOpenAPI/prepareOpenAPI.ts +35 -0
  122. package/src/lib/processOpenAPI.ts +131 -0
  123. package/src/lib/resolveCircularRef.ts +66 -0
  124. package/src/lib/sidebar/cleanSidebarItems.ts +19 -0
  125. package/src/lib/sidebar/ensureGroupTextSlashPrefix.ts +18 -0
  126. package/src/lib/sidebar/flatSidebarItems.ts +58 -0
  127. package/src/lib/sidebar/generateSidebarItemsByPaths.ts +132 -0
  128. package/src/lib/sidebar/mergeAdjacentGroups.ts +56 -0
  129. package/src/lib/sidebar/setItemCollapsedState.ts +15 -0
  130. package/src/lib/utils.ts +7 -0
  131. package/src/locales/en.json +50 -0
  132. package/src/locales/index.ts +4 -0
  133. package/src/style.css +180 -0
  134. package/src/types.ts +73 -0
  135. package/src/vite-env.d.ts +8 -0
@@ -0,0 +1,79 @@
1
+ <script setup lang="ts">
2
+ import type { OperationData } from '../../lib/operationData'
3
+ import { defineProps, inject } from 'vue'
4
+ import OASecurityContent from '../Security/OASecurityContent.vue'
5
+
6
+ const { securityUi, headingPrefix } = defineProps({
7
+ securityUi: {
8
+ type: Object,
9
+ required: true,
10
+ },
11
+ headingPrefix: {
12
+ type: String,
13
+ required: false,
14
+ default: '',
15
+ },
16
+ })
17
+
18
+ const operationData = inject('operationData') as OperationData
19
+ </script>
20
+
21
+ <template>
22
+ <div class="flex flex-col">
23
+ <div class="mt-[48px] mb-[16px] pt-[24px] border-t-[1px] border-[var(--vp-c-divider)]">
24
+ <div class="flex flex-row items-center">
25
+ <OAHeading
26
+ level="h2"
27
+ :prefix="headingPrefix"
28
+ class="text-[var(--vp-c-text-1)] !my-0 !py-0 !border-t-0"
29
+ header-anchor-class="!top-0"
30
+ >
31
+ {{ $t('Authorizations') }}
32
+ </OAHeading>
33
+
34
+ <span class="flex-grow min-w-2" />
35
+ </div>
36
+ </div>
37
+
38
+ <div class="flex flex-col gap-3">
39
+ <div v-for="(item, key) in securityUi" :key="key" class="flex flex-col gap-3">
40
+ <div class="flex flex-col gap-1">
41
+ <span
42
+ v-if="Object.keys(securityUi).length > 1 && Object.keys(item.schemes).length > 1"
43
+ :class="{
44
+ 'font-bold': operationData.security.selectedSchemeId.value === item.id,
45
+ }"
46
+ >
47
+ {{ item.id }}
48
+ </span>
49
+
50
+ <div
51
+ :class="{
52
+ 'pl-2 border-l': Object.keys(item.schemes).length > 1,
53
+ 'border-gray-600 dark:border-gray-400': Object.keys(securityUi).length > 1 && operationData.security.selectedSchemeId.value === item.id,
54
+ }"
55
+ >
56
+ <div
57
+ v-for="(scheme, schemeId, index) in item.schemes"
58
+ :key="schemeId"
59
+ >
60
+ <OASecurityContent
61
+ :name="String(schemeId)"
62
+ :scheme="scheme"
63
+ />
64
+
65
+ <span v-if="index < Object.keys(item.schemes).length - 1" class="-ml-4 my-1 w-4 h-4 bg-muted rounded-full flex justify-center items-center">
66
+ +
67
+ </span>
68
+ </div>
69
+ </div>
70
+ </div>
71
+
72
+ <div v-if="Number(key) < Object.keys(securityUi).length - 1" class="flex flex-row items-center space-x-2">
73
+ <span class="text-sm font-bold">{{ $t('or') }}</span>
74
+ <span class="flex-grow border-t border-[var(--vp-c-divider)]" />
75
+ </div>
76
+ </div>
77
+ </div>
78
+ </div>
79
+ </template>
@@ -0,0 +1,100 @@
1
+ <script setup lang="ts">
2
+ import { computed, defineProps } from 'vue'
3
+ import OACodeValue from '../Common/OACodeValue.vue'
4
+ import OAParameterAttribute from '../Parameter/OAParameterAttribute.vue'
5
+ import OAParameterExamples from '../Parameter/OAParameterExamples.vue'
6
+
7
+ const { scheme, name } = defineProps({
8
+ name: {
9
+ type: String,
10
+ required: true,
11
+ },
12
+ scheme: {
13
+ type: Object,
14
+ required: true,
15
+ },
16
+ })
17
+
18
+ const typeValue = computed(() => {
19
+ if (scheme.type === 'http') {
20
+ return `HTTP (${scheme.scheme})`
21
+ }
22
+
23
+ if (scheme.type === 'apiKey') {
24
+ return `API Key (${scheme.in}: ${scheme.name})`
25
+ }
26
+
27
+ if (scheme.type === 'openIdConnect') {
28
+ return `OpenID Connect (${scheme.openIdConnectUrl})`
29
+ }
30
+
31
+ if (scheme.type === 'oauth2') {
32
+ return 'OAuth2'
33
+ }
34
+
35
+ return ''
36
+ })
37
+ </script>
38
+
39
+ <template>
40
+ <div class="flex flex-col p-3 gap-2 rounded bg-muted">
41
+ <div class="flex flex-col gap-2">
42
+ <div class="flex flex-row items-center gap-2">
43
+ <span class="text-sm font-bold">{{ name }}</span>
44
+ </div>
45
+
46
+ <OAMarkdown
47
+ v-if="scheme.description"
48
+ :content="scheme.description"
49
+ class="text-sm text-gray-800 dark:text-gray-100"
50
+ />
51
+ </div>
52
+
53
+ <div class="flex flex-col gap-2">
54
+ <OAParameterAttribute v-if="scheme.type !== 'oauth2'" :name="$t('Type')" bold-name :value="typeValue" />
55
+
56
+ <div
57
+ v-if="scheme.type === 'oauth2'"
58
+ class="pl-2"
59
+ >
60
+ <div
61
+ v-for="(url, flow) in scheme.flows"
62
+ :key="flow"
63
+ >
64
+ <details>
65
+ <summary class="!my-1 cursor-pointer hover:text-[var(--vp-c-brand-1)]">
66
+ {{ flow }} Flow
67
+ </summary>
68
+
69
+ <div class="pl-2 flex flex-col gap-1">
70
+ <div v-if="url.authorizationUrl" class="flex flex-wrap gap-2">
71
+ <span class="text-sm">{{ $t('Authorization URL') }}</span>
72
+ <OACodeValue :value="url.authorizationUrl" />
73
+ </div>
74
+
75
+ <div v-if="url.tokenUrl" class="flex flex-wrap gap-2">
76
+ <span class="text-sm">{{ $t('Token URL') }}</span>
77
+ <OACodeValue :value="url.tokenUrl" />
78
+ </div>
79
+
80
+ <div v-if="url.scopes">
81
+ <span class="text-sm">Scopes:</span>
82
+ <ul class="pl-2 !my-0">
83
+ <li
84
+ v-for="(description, scope) in url.scopes"
85
+ :key="scope"
86
+ >
87
+ <OACodeValue :value="scope" />
88
+ <span class="ml-2 text-sm">{{ description }}</span>
89
+ </li>
90
+ </ul>
91
+ </div>
92
+ </div>
93
+ </details>
94
+ </div>
95
+ </div>
96
+ </div>
97
+
98
+ <OAParameterExamples :property="scheme" />
99
+ </div>
100
+ </template>
@@ -0,0 +1,127 @@
1
+ <script setup lang="ts">
2
+ import type { OperationSlot } from '../../types'
3
+ import { inject } from 'vue'
4
+ import { useTheme } from '../../composables/useTheme'
5
+ import { getOpenApiInstance } from '../../lib/getOpenApiInstance'
6
+ import OAInfo from '../Common/OAInfo.vue'
7
+ import OAServers from '../Common/OAServers.vue'
8
+
9
+ const props = defineProps({
10
+ spec: {
11
+ type: Object,
12
+ required: false,
13
+ default: null,
14
+ },
15
+ hideInfo: {
16
+ type: Boolean,
17
+ default: false,
18
+ },
19
+ hideServers: {
20
+ type: Boolean,
21
+ default: false,
22
+ },
23
+ groupByTags: {
24
+ type: Boolean,
25
+ default: null,
26
+ },
27
+ tags: {
28
+ type: Array,
29
+ default: undefined,
30
+ },
31
+ hideDefaultFooter: {
32
+ /**
33
+ * @deprecated Use `hideBranding` instead
34
+ */
35
+ type: Boolean,
36
+ default: undefined,
37
+ },
38
+ hideBranding: {
39
+ type: Boolean,
40
+ default: (props: { hideBranding?: boolean, hideDefaultFooter?: boolean }) => {
41
+ if (props.hideBranding === undefined && props.hideDefaultFooter !== undefined) {
42
+ console.warn(
43
+ '`hideDefaultFooter` is deprecated. Use `hideBranding` instead.',
44
+ )
45
+
46
+ return props.hideDefaultFooter
47
+ }
48
+
49
+ return false
50
+ },
51
+ },
52
+ hidePathsSummary: {
53
+ type: Boolean,
54
+ default: undefined,
55
+ },
56
+ })
57
+
58
+ const slots = defineSlots<Record<string, OperationSlot>>()
59
+
60
+ const themeConfig = useTheme()
61
+
62
+ const openapi = getOpenApiInstance({
63
+ custom: { spec: props.spec },
64
+ injected: inject('openapi', undefined),
65
+ })
66
+
67
+ const servers = openapi.getServers()
68
+
69
+ const info = openapi.getInfo()
70
+
71
+ const showInfo = !props.hideInfo && Object.keys(info).length
72
+
73
+ const showServers = !props.hideServers && servers.length
74
+
75
+ const groupByTags = props.groupByTags ?? themeConfig.getSpecConfig()?.groupByTags
76
+
77
+ const operationsTags = props.tags ?? openapi.getOperationsTags()
78
+
79
+ const paths = openapi.getPaths()
80
+ </script>
81
+
82
+ <template>
83
+ <div class="flex flex-col space-y-10">
84
+ <div v-if="showInfo || showServers">
85
+ <OAInfo v-if="showInfo" :openapi="openapi" />
86
+
87
+ <OAServers v-if="showServers" :openapi="openapi" />
88
+ </div>
89
+
90
+ <hr v-if="showInfo || showServers">
91
+
92
+ <OAPathsByTags
93
+ v-if="groupByTags && operationsTags.length"
94
+ :openapi="openapi"
95
+ :tags="operationsTags"
96
+ :paths="paths"
97
+ :hide-paths-summary="props.hidePathsSummary === undefined ? undefined : props.hidePathsSummary"
98
+ >
99
+ <!-- Expose all slots upwards -->
100
+ <template
101
+ v-for="(_, name) in slots"
102
+ #[name]="slotProps"
103
+ >
104
+ <slot
105
+ :name="name"
106
+ v-bind="slotProps || {}"
107
+ />
108
+ </template>
109
+ </OAPathsByTags>
110
+ <OAPaths
111
+ v-else
112
+ :openapi="openapi"
113
+ :paths="paths"
114
+ >
115
+ <!-- Expose all slots upwards -->
116
+ <template
117
+ v-for="(_, name) in slots"
118
+ #[name]="slotProps"
119
+ >
120
+ <slot
121
+ :name="name"
122
+ v-bind="slotProps || {}"
123
+ />
124
+ </template>
125
+ </OAPaths>
126
+ </div>
127
+ </template>
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ </script>
3
+
4
+ <template>
5
+ <div class="animate-pulse flex flex-col gap-6 p-4">
6
+ <div class="flex flex-col gap-4">
7
+ <div class="w-1/3 h-10 bg-muted rounded" />
8
+ <div class="w-1/4 h-4 bg-muted rounded" />
9
+ <div class="w-1/2 h-4 bg-muted rounded" />
10
+ </div>
11
+
12
+ <hr>
13
+
14
+ <div class="flex flex-col gap-4">
15
+ <div class="w-1/3 h-10 bg-muted rounded" />
16
+ <div class="w-full h-20 bg-muted rounded" />
17
+ </div>
18
+
19
+ <hr>
20
+
21
+ <div class="flex flex-col gap-4">
22
+ <div class="w-1/3 h-10 bg-muted rounded" />
23
+ <div class="w-1/2 h-4 bg-muted rounded" />
24
+ </div>
25
+ </div>
26
+ </template>
@@ -0,0 +1,171 @@
1
+ <script setup lang="ts">
2
+ import { ref } from 'vue'
3
+ import { OARequest } from '../../lib/codeSamples/request'
4
+ import { Badge } from '../ui/badge'
5
+ import { Button } from '../ui/button'
6
+
7
+ interface PlaygroundResponse {
8
+ body: any
9
+ type: string
10
+ time: string | null
11
+ status: number | null
12
+ }
13
+
14
+ const props = defineProps({
15
+ operationId: {
16
+ type: String,
17
+ required: true,
18
+ },
19
+ path: {
20
+ type: String,
21
+ required: true,
22
+ },
23
+ method: {
24
+ type: String,
25
+ required: true,
26
+ },
27
+ baseUrl: {
28
+ type: String,
29
+ required: true,
30
+ },
31
+ request: {
32
+ type: Object,
33
+ default: () => (new OARequest()),
34
+ },
35
+ })
36
+
37
+ const emits = defineEmits([
38
+ 'response',
39
+ 'loading',
40
+ ])
41
+
42
+ const defaultRequestUrl = `${props.baseUrl}${props.path}`
43
+
44
+ const response = ref<PlaygroundResponse | null>(null)
45
+
46
+ const loading = ref(false)
47
+
48
+ async function tryIt() {
49
+ if (!props.request) {
50
+ return
51
+ }
52
+
53
+ response.value = null
54
+
55
+ const innerResponse: PlaygroundResponse = {
56
+ body: null,
57
+ type: '',
58
+ time: null,
59
+ status: null,
60
+ }
61
+
62
+ const start = performance.now()
63
+
64
+ try {
65
+ innerResponse.time = null
66
+ innerResponse.body = '{}'
67
+ setLoading(true)
68
+
69
+ const headers = props.request.headers ?? {}
70
+ if (props.request.body && !headers['Content-Type']) {
71
+ headers['Content-Type'] = 'application/json'
72
+ }
73
+
74
+ const url = new URL(props.request.url ?? defaultRequestUrl)
75
+ for (const [key, value] of Object.entries(props.request.query)) {
76
+ if (Array.isArray(value)) {
77
+ for (const item of value) {
78
+ url.searchParams.append(`${key}[]`, String(item))
79
+ }
80
+ } else {
81
+ url.searchParams.set(key, String(value))
82
+ }
83
+ }
84
+
85
+ const data = await fetch(url.toString(), {
86
+ method: props.method.toUpperCase(),
87
+ headers,
88
+ body: props.request.body ? JSON.stringify(props.request.body) : null,
89
+ })
90
+
91
+ const contentType = data.headers.get('Content-Type') || 'text/plain'
92
+ innerResponse.type = contentType
93
+
94
+ if (/json/i.test(contentType)) {
95
+ innerResponse.body = await data.json()
96
+ } else if (/xml/i.test(contentType) || /html/i.test(contentType) || /text\/plain/.test(contentType)) {
97
+ innerResponse.body = await data.text()
98
+ } else if (/^image\//i.test(contentType)) {
99
+ const blob = await data.blob()
100
+ innerResponse.body = URL.createObjectURL(blob)
101
+ } else if (/^audio\//i.test(contentType)) {
102
+ innerResponse.body = await data.blob()
103
+ } else {
104
+ innerResponse.body = await data.text()
105
+ }
106
+
107
+ innerResponse.status = data.status
108
+ } catch (error: any) {
109
+ innerResponse.body = error?.message
110
+ innerResponse.type = 'text/plain'
111
+ innerResponse.status = 500
112
+ } finally {
113
+ setLoading(false)
114
+ const end = performance.now()
115
+ innerResponse.time = (end - start).toFixed(2)
116
+
117
+ emits('response', innerResponse)
118
+ response.value = innerResponse
119
+ }
120
+ }
121
+
122
+ function setLoading(value: boolean) {
123
+ loading.value = value
124
+ emits('loading', value)
125
+ }
126
+ </script>
127
+
128
+ <template>
129
+ <div class="flex flex-col gap-2">
130
+ <Button variant="primary" @click="tryIt">
131
+ {{ $t('Try it out') }}
132
+ </Button>
133
+
134
+ <details v-if="response || loading" open>
135
+ <summary class="!my-0 text-lg font-bold cursor-pointer">
136
+ <div class="inline-flex items-center gap-2 w-[calc(100%-24px)]">
137
+ <span>{{ loading ? $t('Loading...') : $t('Response') }}</span>
138
+
139
+ <span class="flex-1" />
140
+
141
+ <Badge
142
+ v-if="response && response.status"
143
+ variant="plain"
144
+ class="rounded py-1.5"
145
+ :class="{
146
+ 'bg-green-100 text-green-800 dark:bg-green-800 dark:text-green-100': String(response.status).startsWith('2'),
147
+ 'bg-yellow-100 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-100': String(response.status).startsWith('3'),
148
+ 'bg-red-100 text-red-800 dark:bg-red-800 dark:text-red-100': String(response.status).startsWith('4') || String(response.status).startsWith('5'),
149
+ }"
150
+ >
151
+ {{ response.status }}
152
+ </Badge>
153
+ </div>
154
+ </summary>
155
+
156
+ <div class="flex flex-col gap-2">
157
+ <div v-if="response" class="text-sm text-gray-500">
158
+ {{ $t('Response time') }}: {{ loading ? $t('Loading...') : `${response.time}ms` }}
159
+ </div>
160
+
161
+ <div class="flex flex-col max-h-96 overflow-y-auto">
162
+ <slot
163
+ v-if="response"
164
+ name="response"
165
+ :response="response"
166
+ />
167
+ </div>
168
+ </div>
169
+ </details>
170
+ </div>
171
+ </template>
@@ -0,0 +1,105 @@
1
+ <script setup lang="ts">
2
+ import type { OpenAPIV3 } from '@scalar/openapi-types'
3
+ import { computed, defineEmits, defineProps, ref } from 'vue'
4
+ import { OARequest } from '../../lib/codeSamples/request'
5
+ import OAPlaygroundParameters from '../Playground/OAPlaygroundParameters.vue'
6
+ import OAPlaygroundResponse from '../Playground/OAPlaygroundResponse.vue'
7
+
8
+ const props = defineProps({
9
+ operationId: {
10
+ type: String,
11
+ required: true,
12
+ },
13
+ baseUrl: {
14
+ type: String,
15
+ required: true,
16
+ },
17
+ path: {
18
+ type: String,
19
+ required: true,
20
+ },
21
+ method: {
22
+ type: String,
23
+ required: true,
24
+ },
25
+ hideEndpoint: {
26
+ type: Boolean,
27
+ default: false,
28
+ },
29
+ parameters: {
30
+ type: Array<OpenAPIV3.ParameterObject>,
31
+ required: false,
32
+ },
33
+ requestBody: {
34
+ type: Object,
35
+ required: false,
36
+ },
37
+ securityUi: {
38
+ type: Object,
39
+ required: true,
40
+ },
41
+ contentType: {
42
+ type: String,
43
+ required: false,
44
+ default: 'application/json',
45
+ },
46
+ request: {
47
+ type: Object,
48
+ default: () => (new OARequest()),
49
+ },
50
+ })
51
+
52
+ const emits = defineEmits([
53
+ 'update:request',
54
+ 'update:selectedServer',
55
+ ])
56
+
57
+ const loading = ref(false)
58
+
59
+ const schemaExamples = computed(() => {
60
+ return props.requestBody?.content?.[props.contentType]?.examples
61
+ })
62
+
63
+ const hasBody = computed(() =>
64
+ Boolean(props.requestBody),
65
+ )
66
+
67
+ const hasSecuritySchemes = computed(() =>
68
+ Object.keys(props.securityUi ?? {}).length > 0,
69
+ )
70
+
71
+ const hasParameters = computed(() =>
72
+ Boolean(props.parameters?.length || hasBody.value || hasSecuritySchemes.value),
73
+ )
74
+ </script>
75
+
76
+ <template>
77
+ <OAPlaygroundParameters
78
+ v-if="hasParameters"
79
+ :request="props.request"
80
+ :operation-id="props.operationId"
81
+ :path="props.path"
82
+ :method="props.method"
83
+ :base-url="props.baseUrl"
84
+ :parameters="props.parameters ?? []"
85
+ :security-ui="props.securityUi ?? {}"
86
+ :examples="schemaExamples"
87
+ @update:request="($event: any) => emits('update:request', $event)"
88
+ @update:selected-server="($event: any) => emits('update:selectedServer', $event)"
89
+ />
90
+
91
+ <OATryItButton
92
+ :request="props.request"
93
+ :operation-id="props.operationId"
94
+ :path="props.path"
95
+ :method="props.method"
96
+ :base-url="props.baseUrl"
97
+ @loading="loading = $event"
98
+ >
99
+ <template #response="response">
100
+ <OAPlaygroundResponse
101
+ :response="response.response"
102
+ />
103
+ </template>
104
+ </OATryItButton>
105
+ </template>
@@ -0,0 +1,55 @@
1
+ import OACodeBlock from './Common/OACodeBlock.vue'
2
+ import OAHeading from './Common/OAHeading.vue'
3
+ import OAInfo from './Common/OAInfo.vue'
4
+ import OAIntroduction from './Common/OAIntroduction.vue'
5
+ import OAMarkdown from './Common/OAMarkdown.vue'
6
+ import OAServers from './Common/OAServers.vue'
7
+ import OAOperation from './Operation/OAOperation.vue'
8
+ import OAParameter from './Parameter/OAParameter.vue'
9
+ import OAParameters from './Parameter/OAParameters.vue'
10
+ import OAPath from './Path/OAPath.vue'
11
+ import OAPathEndpoint from './Path/OAPathEndpoint.vue'
12
+ import OAPaths from './Path/OAPaths.vue'
13
+ import OAPathsByTags from './Path/OAPathsByTags.vue'
14
+ import OARemoteOperation from './Remote/OARemoteOperation.vue'
15
+ import OARemoteSpec from './Remote/OARemoteSpec.vue'
16
+ import OARequestBody from './Request/OARequestBody.vue'
17
+ import OAResponse from './Response/OAResponse.vue'
18
+ import OAResponses from './Response/OAResponses.vue'
19
+ import OACodeSamples from './Sample/OACodeSamples.vue'
20
+ import OASchemaPropertyAttributes from './Schema/OASchemaPropertyAttributes.vue'
21
+ import OASchemaTabs from './Schema/OASchemaTabs.vue'
22
+ import OASecurity from './Security/OASecurity.vue'
23
+ import OASpec from './Spec/OASpec.vue'
24
+ import OASpecSkeleton from './Spec/OASpecSkeleton.vue'
25
+ import OATryItButton from './Try/OATryItButton.vue'
26
+ import OATryWithVariables from './Try/OATryWithVariables.vue'
27
+
28
+ export {
29
+ OACodeBlock,
30
+ OACodeSamples,
31
+ OAHeading,
32
+ OAInfo,
33
+ OAIntroduction,
34
+ OAMarkdown,
35
+ OAOperation,
36
+ OAParameter,
37
+ OAParameters,
38
+ OAPath,
39
+ OAPathEndpoint,
40
+ OAPaths,
41
+ OAPathsByTags,
42
+ OARemoteOperation,
43
+ OARemoteSpec,
44
+ OARequestBody,
45
+ OAResponse,
46
+ OAResponses,
47
+ OASchemaPropertyAttributes,
48
+ OASchemaTabs,
49
+ OASecurity,
50
+ OAServers,
51
+ OASpec,
52
+ OASpecSkeleton,
53
+ OATryItButton,
54
+ OATryWithVariables,
55
+ }
@@ -0,0 +1,18 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue'
3
+ import type { BadgeVariants } from '.'
4
+ import { badgeVariants } from '.'
5
+ import { cn } from '../../../lib/utils'
6
+
7
+ const props = defineProps<{
8
+ variant?: BadgeVariants['variant']
9
+ size?: BadgeVariants['size']
10
+ class?: HTMLAttributes['class']
11
+ }>()
12
+ </script>
13
+
14
+ <template>
15
+ <div :class="cn(badgeVariants({ variant, size }), props.class)">
16
+ <slot />
17
+ </div>
18
+ </template>