@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,99 @@
1
+ <script setup lang="ts">
2
+ import type { OpenAPIV3 } from '@scalar/openapi-types'
3
+ import type { OperationSlot } from '../../types'
4
+ import { defineProps, ref } from 'vue'
5
+ import { useI18n } from 'vue-i18n'
6
+ import { useTheme } from '../../composables/useTheme'
7
+ import { getOpenApiInstance } from '../../lib/getOpenApiInstance'
8
+ import OALazy from '../Common/Lazy/OALazy.vue'
9
+ import OAPathsByTag from './OAPathsByTag.vue'
10
+
11
+ const props = defineProps({
12
+ openapi: {
13
+ type: Object,
14
+ required: true,
15
+ },
16
+ tags: {
17
+ type: Array,
18
+ required: false,
19
+ },
20
+ paths: {
21
+ type: Object,
22
+ required: true,
23
+ },
24
+ hidePathsSummary: {
25
+ type: Boolean,
26
+ default: undefined,
27
+ },
28
+ })
29
+
30
+ const slots = defineSlots<Record<string, OperationSlot>>()
31
+
32
+ const { t } = useI18n()
33
+
34
+ const themeConfig = useTheme()
35
+
36
+ const openapi = props.openapi ?? getOpenApiInstance()
37
+
38
+ const specTags: OpenAPIV3.TagObject[] = openapi.getTags()
39
+
40
+ const operationsTags = props.tags ?? openapi.getOperationsTags()
41
+
42
+ const pathsByTags = operationsTags.map((tag: string) => {
43
+ return {
44
+ tag,
45
+ paths: openapi.getPathsByTags(tag),
46
+ }
47
+ })
48
+
49
+ const pathsWithoutTags = openapi.getPathsWithoutTags()
50
+
51
+ const internalTags = ref([
52
+ ...(pathsWithoutTags.length
53
+ ? [
54
+ {
55
+ tag: t(useTheme().getSpecConfig()?.defaultTag ?? 'Default'),
56
+ paths: pathsWithoutTags,
57
+ // isOpen: !themeConfig.getSpecConfig()?.collapsePaths?.value,
58
+ },
59
+ ]
60
+ : []),
61
+
62
+ ...pathsByTags.map((tag: { tag: string, paths: Record<string, any> }) => {
63
+ return {
64
+ tag: tag.tag,
65
+ paths: tag.paths,
66
+ // isOpen: !themeConfig.getSpecConfig()?.collapsePaths?.value,
67
+ description: specTags.find(tagInfo => tagInfo.name === tag.tag)?.description,
68
+ }
69
+ }),
70
+ ])
71
+
72
+ const lazyRendering = themeConfig.getSpecConfig()?.lazyRendering?.value
73
+ </script>
74
+
75
+ <template>
76
+ <OALazy
77
+ v-for="(tagObject, tagIdx) in internalTags"
78
+ :key="tagObject.tag"
79
+ :is-lazy="lazyRendering && tagIdx > 0"
80
+ >
81
+ <OAPathsByTag
82
+ v-if="Object.keys(tagObject.paths).length"
83
+ :openapi="openapi"
84
+ :tag="tagObject"
85
+ :hide-paths-summary="props.hidePathsSummary"
86
+ >
87
+ <!-- Expose all slots upwards -->
88
+ <template
89
+ v-for="(_, name) in slots"
90
+ #[name]="slotProps"
91
+ >
92
+ <slot
93
+ :name="name"
94
+ v-bind="slotProps || {}"
95
+ />
96
+ </template>
97
+ </OAPathsByTag>
98
+ </OALazy>
99
+ </template>
@@ -0,0 +1,52 @@
1
+ <script setup>
2
+ import { defineProps } from 'vue'
3
+
4
+ const { paths } = defineProps({
5
+ paths: {
6
+ type: Object,
7
+ required: true,
8
+ },
9
+ })
10
+
11
+ const emit = defineEmits([
12
+ 'pathClick',
13
+ ])
14
+ </script>
15
+
16
+ <template>
17
+ <div class="bg-muted rounded border divide-y divide-[var(--vp-c-divider)]">
18
+ <div class="p-2 pl-4">
19
+ <OAHeading level="h3" class="!mt-0 !text-sm">
20
+ {{ $t('Operations') }}
21
+ </OAHeading>
22
+ </div>
23
+
24
+ <div class="py-2">
25
+ <template
26
+ v-for="(path, idx) in Object.keys(paths)"
27
+ :key="idx"
28
+ >
29
+ <a
30
+ v-for="method in Object.keys(paths[path])"
31
+ :key="`${path}-${method}`"
32
+ class="grid grid-cols-[4rem,1fr] items-center gap-2 !text-foreground !no-underline cursor-pointer"
33
+ :aria-label="`${method.toUpperCase()} ${path}`"
34
+ :title="`${method.toUpperCase()} ${path}`"
35
+ @click="emit('pathClick', `#${paths[path][method].operationId}`)"
36
+ >
37
+ <span :class="[`text-method-${method}`]" class="text-sm text-right">
38
+ {{ method.toUpperCase() }}
39
+ </span>
40
+ <span
41
+ :class="{
42
+ 'line-through': paths[path][method].deprecated,
43
+ }"
44
+ class="truncate hover:underline"
45
+ >
46
+ {{ path }}
47
+ </span>
48
+ </a>
49
+ </template>
50
+ </div>
51
+ </div>
52
+ </template>
@@ -0,0 +1,97 @@
1
+ <script setup lang="ts">
2
+ import { defineEmits, defineProps, onMounted } from 'vue'
3
+ import { getPropertyExample } from '../../lib/examples/getPropertyExample'
4
+ import { Checkbox } from '../ui/checkbox'
5
+ import { Input } from '../ui/input'
6
+ import Multiselect from '../ui/multiselect/Multiselect.vue'
7
+ import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '../ui/select'
8
+
9
+ const props = defineProps({
10
+ parameter: {
11
+ type: Object,
12
+ required: true,
13
+ },
14
+ modelValue: {
15
+ type: [String, Number, Boolean, Array],
16
+ required: true,
17
+ },
18
+ })
19
+
20
+ const emits = defineEmits([
21
+ 'update:modelValue',
22
+ ])
23
+
24
+ function inputType(parameter: any) {
25
+ if (parameter.schema?.type === 'integer') {
26
+ return 'number'
27
+ }
28
+ if (parameter.schema?.type === 'number') {
29
+ return 'number'
30
+ }
31
+ return 'text'
32
+ }
33
+
34
+ onMounted(() => {
35
+ if (props.parameter.schema?.enum) {
36
+ emits('update:modelValue', getPropertyExample(props.parameter) ?? props.parameter.schema.enum[0])
37
+ }
38
+ })
39
+
40
+ const parameterExample = getPropertyExample(props.parameter)
41
+ </script>
42
+
43
+ <template>
44
+ <div class="flex flex-col space-y-2">
45
+ <Input
46
+ v-if="['string', 'number', 'integer'].includes(parameter.schema?.type) && !parameter.schema?.enum"
47
+ :value="modelValue"
48
+ :type="inputType(parameter)"
49
+ :placeholder="String(parameterExample ?? '')"
50
+ class="bg-muted"
51
+ @update:model-value="emits('update:modelValue', $event)"
52
+ />
53
+
54
+ <Checkbox
55
+ v-if="['boolean'].includes(parameter.schema?.type)"
56
+ :checked="String(modelValue) === '' ? 'indeterminate' : (modelValue as boolean)"
57
+ @update:checked="emits('update:modelValue', $event)"
58
+ />
59
+
60
+ <Select
61
+ v-if="parameter.schema?.enum && parameter.schema?.type !== 'array'"
62
+ @update:model-value="emits('update:modelValue', $event)"
63
+ >
64
+ <SelectTrigger>
65
+ <SelectValue :placeholder="String(parameterExample ?? $t('Select...'))" />
66
+ </SelectTrigger>
67
+
68
+ <SelectContent>
69
+ <SelectGroup>
70
+ <SelectItem
71
+ v-for="enumValue in parameter.schema.enum"
72
+ :key="enumValue"
73
+ :value="String(enumValue)"
74
+ >
75
+ {{ enumValue }}
76
+ </SelectItem>
77
+ </SelectGroup>
78
+ </SelectContent>
79
+ </Select>
80
+
81
+ <template v-if="parameter.schema?.type === 'array'">
82
+ <Multiselect
83
+ v-if="parameter.schema?.items?.enum?.length" :model-value="modelValue as string[]" :parameter="parameter"
84
+ @update:model-value="(v) => emits('update:modelValue', v)"
85
+ />
86
+
87
+ <Input
88
+ v-else
89
+ :value="modelValue"
90
+ :type="inputType(parameter)"
91
+ :placeholder="$t('item1, item2, ...')"
92
+ class="bg-muted"
93
+ @update:model-value="emits('update:modelValue', $event)"
94
+ />
95
+ </template>
96
+ </div>
97
+ </template>
@@ -0,0 +1,262 @@
1
+ <script setup lang="ts">
2
+ import type { OpenAPIV3 } from '@scalar/openapi-types'
3
+ import type { OperationData } from '../../lib/operationData'
4
+ import type { PlaygroundSecurityScheme, SecurityUiItem } from '../../types'
5
+ import { useStorage } from '@vueuse/core'
6
+ import { defineEmits, defineProps, inject, ref, watch } from 'vue'
7
+ import { usePlayground } from '../../composables/usePlayground'
8
+ import { buildRequest } from '../../lib/codeSamples/buildRequest'
9
+ import { OARequest } from '../../lib/codeSamples/request'
10
+ import { getPropertyExample } from '../../lib/examples/getPropertyExample'
11
+ import OAJSONEditor from '../Common/OAJSONEditor.vue'
12
+ import OAPlaygroundParameterInput from '../Playground/OAPlaygroundParameterInput.vue'
13
+ import OAPlaygroundSecurityInput from '../Playground/OAPlaygroundSecurityInput.vue'
14
+ import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '../ui/select'
15
+
16
+ const props = defineProps({
17
+ request: { // v-model
18
+ type: Object,
19
+ default: () => (new OARequest()),
20
+ },
21
+ operationId: {
22
+ type: String,
23
+ required: true,
24
+ },
25
+ path: {
26
+ type: String,
27
+ required: true,
28
+ },
29
+ method: {
30
+ type: String,
31
+ required: true,
32
+ },
33
+ baseUrl: {
34
+ type: String,
35
+ required: true,
36
+ },
37
+ parameters: {
38
+ type: Array<OpenAPIV3.ParameterObject>,
39
+ required: true,
40
+ },
41
+ securityUi: {
42
+ type: Object,
43
+ required: true,
44
+ },
45
+ examples: {
46
+ type: Object,
47
+ required: false,
48
+ },
49
+ })
50
+
51
+ const emits = defineEmits([
52
+ 'update:request',
53
+ ])
54
+
55
+ const headerParameters = props.parameters.filter(parameter => parameter && parameter.in === 'header')
56
+
57
+ const pathParameters = props.parameters.filter(parameter => parameter && parameter.in === 'path')
58
+
59
+ const queryParameters = props.parameters.filter(parameter => parameter && parameter.in === 'query')
60
+
61
+ const variables = ref({
62
+ ...initializeVariables(headerParameters),
63
+ ...initializeVariables(pathParameters),
64
+ ...initializeVariables(queryParameters),
65
+ })
66
+
67
+ function initializeVariables(parameters: OpenAPIV3.ParameterObject[]) {
68
+ return parameters
69
+ .reduce((acc: Record<string, string | []>, parameter: OpenAPIV3.ParameterObject) => {
70
+ if (!parameter.name) {
71
+ return acc
72
+ }
73
+
74
+ acc[parameter.name] = getPropertyExample(parameter) ?? parameter.schema?.items?.enum?.length ? [] : ''
75
+ return acc
76
+ }, {})
77
+ }
78
+
79
+ const operationData = inject('operationData') as OperationData
80
+
81
+ const authorizations = ref<PlaygroundSecurityScheme[] | null>(null)
82
+
83
+ const body = ref(Object.keys(props.examples ?? {}).length ? Object.values(props.examples ?? {})[0].value : null)
84
+
85
+ function setAuthorizations(schemes: Record<string, PlaygroundSecurityScheme>) {
86
+ if (!schemes || !Object.keys(schemes).length) {
87
+ authorizations.value = null
88
+ return
89
+ }
90
+
91
+ authorizations.value = Object.keys(schemes).map((name) => {
92
+ const scheme = schemes[name] as PlaygroundSecurityScheme
93
+ return {
94
+ type: scheme.type,
95
+ scheme: scheme.scheme,
96
+ name: scheme.name ?? name,
97
+ playgroundValue: typeof localStorage !== 'undefined'
98
+ ? useStorage(`--oa-authorization-${name}`, usePlayground().getSecuritySchemeDefaultValue(scheme), localStorage)
99
+ : usePlayground().getSecuritySchemeDefaultValue(scheme),
100
+ label: name,
101
+ }
102
+ })
103
+ }
104
+
105
+ watch([variables, authorizations, body, () => props.baseUrl], () => {
106
+ emits('update:request', buildRequest({
107
+ baseUrl: props.baseUrl,
108
+ method: props.method as OpenAPIV3.HttpMethods,
109
+ path: props.path,
110
+ variables: variables.value,
111
+ authorizations: authorizations.value,
112
+ body: body.value,
113
+ parameters: props.parameters,
114
+ }))
115
+ }, { deep: true })
116
+
117
+ watch(operationData.security.selectedSchemeId, () => {
118
+ setAuthorizations(
119
+ props.securityUi?.find((scheme: SecurityUiItem) => scheme.id === operationData.security.selectedSchemeId.value)?.schemes
120
+ ?? props.securityUi?.[0]?.schemes
121
+ ?? {},
122
+ )
123
+ }, { immediate: true })
124
+ </script>
125
+
126
+ <template>
127
+ <div class="OAPlaygroundParameters">
128
+ <details v-if="authorizations" open>
129
+ <summary>
130
+ {{ $t('Authorization') }}
131
+ <div v-if="props.securityUi.length > 1" class="w-full max-w-[33%] md:max-w-[50%] ml-auto -mt-8">
132
+ <Select
133
+ :model-value="operationData.security.selectedSchemeId.value"
134
+ @update:model-value="operationData.security.selectedSchemeId.value = $event"
135
+ >
136
+ <SelectTrigger
137
+ aria-label="Security Scheme"
138
+ class="h-9 px-3 py-1.5 text-foreground font-normal"
139
+ >
140
+ <SelectValue :placeholder="operationData.security.selectedSchemeId.value ?? $t('Select...')" />
141
+ </SelectTrigger>
142
+ <SelectContent>
143
+ <SelectGroup>
144
+ <SelectItem
145
+ v-for="item in props.securityUi"
146
+ :key="item.id"
147
+ :value="item.id"
148
+ >
149
+ {{ item.id }}
150
+ </SelectItem>
151
+ </SelectGroup>
152
+ </SelectContent>
153
+ </Select>
154
+ </div>
155
+ </summary>
156
+
157
+ <div
158
+ v-for="authorization in authorizations"
159
+ :key="authorization.name"
160
+ class="flex flex-col gap-2"
161
+ >
162
+ <div class="flex flex-row items-center space-x-2">
163
+ <span class="text-sm font-bold">{{ authorization.label }}</span>
164
+ </div>
165
+ <div class="flex flex-row items-center space-x-2">
166
+ <OAPlaygroundSecurityInput
167
+ v-model="authorization.playgroundValue"
168
+ :scheme="authorization"
169
+ class="w-full"
170
+ />
171
+ </div>
172
+ </div>
173
+ </details>
174
+
175
+ <details v-if="headerParameters.length" open>
176
+ <summary>
177
+ {{ $t('Headers') }}
178
+ </summary>
179
+
180
+ <div class="flex flex-col gap-2">
181
+ <div
182
+ v-for="parameter in headerParameters"
183
+ :key="parameter.name"
184
+ class="flex flex-col gap-2"
185
+ >
186
+ <div class="flex flex-row items-center space-x-2">
187
+ <span class="text-sm font-bold">{{ parameter.name }}</span>
188
+ <span
189
+ v-if="parameter.required"
190
+ class="text-sm text-red-500"
191
+ >*</span>
192
+ </div>
193
+ <div class="flex flex-row items-center space-x-2">
194
+ <OAPlaygroundParameterInput
195
+ v-model="variables[parameter.name ?? '']"
196
+ :parameter="parameter"
197
+ class="w-full"
198
+ />
199
+ </div>
200
+ </div>
201
+ </div>
202
+ </details>
203
+
204
+ <details v-if="Object.keys(queryParameters).length || Object.keys(pathParameters).length" open>
205
+ <summary>
206
+ {{ $t('Variables') }}
207
+ </summary>
208
+
209
+ <div class="flex flex-col gap-1">
210
+ <div class="flex flex-row gap-2">
211
+ <div class="w-1/2 flex justify-start">
212
+ <span class="text-xs text-gray-700 dark:text-gray-300 uppercase">{{ $t('Key') }}</span>
213
+ </div>
214
+ <div class="w-1/2 flex justify-start">
215
+ <span class="text-xs text-gray-700 dark:text-gray-300 uppercase">{{ $t('Value') }}</span>
216
+ </div>
217
+ </div>
218
+
219
+ <div
220
+ v-for="parameter in [...pathParameters, ...queryParameters]"
221
+ :key="parameter.name"
222
+ class="flex flex-row gap-2"
223
+ >
224
+ <div class="w-1/2 flex flex-row items-center space-x-2">
225
+ <span class="text-sm font-bold">{{ parameter.name }}</span>
226
+ <span
227
+ v-if="parameter.required"
228
+ class="text-sm text-red-500"
229
+ >*</span>
230
+ </div>
231
+ <div class="w-1/2 flex flex-row items-center space-x-2">
232
+ <OAPlaygroundParameterInput
233
+ v-model="variables[parameter.name ?? '']"
234
+ :parameter="parameter"
235
+ class="w-full"
236
+ />
237
+ </div>
238
+ </div>
239
+ </div>
240
+ </details>
241
+
242
+ <details v-if="body" open>
243
+ <summary>
244
+ {{ $t('Body') }}
245
+ </summary>
246
+
247
+ <OAJSONEditor v-model="body" class="w-full" />
248
+ </details>
249
+ </div>
250
+ </template>
251
+
252
+ <style scoped>
253
+ .OAPlaygroundParameters {
254
+ @apply flex flex-col gap-2;
255
+ }
256
+ .OAPlaygroundParameters > details {
257
+ @apply flex flex-col gap-2;
258
+ }
259
+ .OAPlaygroundParameters > details > summary {
260
+ @apply !my-0 text-lg font-bold cursor-pointer;
261
+ }
262
+ </style>
@@ -0,0 +1,74 @@
1
+ <script setup lang="ts">
2
+ import { computed, defineProps } from 'vue'
3
+ import OACodeBlock from '../Common/OACodeBlock.vue'
4
+
5
+ const { response } = defineProps({
6
+ response: {
7
+ type: Object,
8
+ required: true,
9
+ },
10
+ })
11
+
12
+ const isJson = /json/i.test(response.type)
13
+ const isXml = /xml/i.test(response.type)
14
+ const isHtml = /text\/html/i.test(response.type)
15
+ const isPlainText = /text\/plain/i.test(response.type)
16
+ const isCsv = /text\/csv/i.test(response.type)
17
+ const isImage = /^image\//i.test(response.type)
18
+
19
+ const lang = computed(() => {
20
+ if (isJson) {
21
+ return 'json'
22
+ }
23
+ if (isXml) {
24
+ return 'xml'
25
+ }
26
+ if (isHtml) {
27
+ return 'html'
28
+ }
29
+ if (isPlainText) {
30
+ return 'plaintext'
31
+ }
32
+ if (isCsv) {
33
+ return 'csv'
34
+ }
35
+ return 'plaintext'
36
+ })
37
+
38
+ const label = computed(() => {
39
+ if (isJson) {
40
+ return 'JSON'
41
+ }
42
+ if (isXml) {
43
+ return 'XML'
44
+ }
45
+ if (isHtml) {
46
+ return 'HTML'
47
+ }
48
+ if (isPlainText) {
49
+ return 'Plain Text'
50
+ }
51
+ if (isCsv) {
52
+ return 'CSV'
53
+ }
54
+ return 'Plain Text'
55
+ })
56
+ </script>
57
+
58
+ <template>
59
+ <div>
60
+ <OACodeBlock
61
+ v-if="isJson || isXml || isHtml || isPlainText || isCsv"
62
+ :code="response.body"
63
+ :lang="lang"
64
+ :label="label"
65
+ :disable-html-transform="response.body.length > 1000"
66
+ class="!my-0"
67
+ />
68
+ <img v-else-if="isImage" :src="response.body" alt="Response Image">
69
+ <div v-else>
70
+ <p>{{ $t('Unrecognized response type. Raw content:') }}</p>
71
+ <pre class="whitespace-pre-wrap">{{ response.body }}</pre>
72
+ </div>
73
+ </div>
74
+ </template>
@@ -0,0 +1,44 @@
1
+ <script setup lang="ts">
2
+ import { computed, defineEmits, defineProps } from 'vue'
3
+ import { usePlayground } from '../../composables/usePlayground'
4
+ import { Input } from '../ui/input'
5
+
6
+ const props = defineProps({
7
+ scheme: {
8
+ type: Object,
9
+ required: true,
10
+ },
11
+ modelValue: {
12
+ type: [String, Number],
13
+ required: true,
14
+ },
15
+ })
16
+
17
+ const emits = defineEmits([
18
+ 'update:modelValue',
19
+ ])
20
+
21
+ const placeholder = computed(() => {
22
+ if (props.modelValue) {
23
+ return props.modelValue
24
+ }
25
+
26
+ if (!props.scheme || !props.scheme.type) {
27
+ return ''
28
+ }
29
+
30
+ return usePlayground().getSecuritySchemeDefaultValue(props.scheme)
31
+ })
32
+ </script>
33
+
34
+ <template>
35
+ <div class="flex flex-col space-y-2">
36
+ <Input
37
+ :value="modelValue"
38
+ type="text"
39
+ :placeholder="placeholder"
40
+ class="bg-muted"
41
+ @update:model-value="emits('update:modelValue', $event)"
42
+ />
43
+ </div>
44
+ </template>
@@ -0,0 +1,42 @@
1
+ <script setup lang="ts">
2
+ import { parseYAML } from 'confbox'
3
+
4
+ const props = defineProps({
5
+ specUrl: {
6
+ type: String,
7
+ required: true,
8
+ },
9
+ })
10
+
11
+ const emits = defineEmits([
12
+ 'update:spec',
13
+ ])
14
+
15
+ const spec = await fetchSpec(props.specUrl)
16
+
17
+ async function fetchSpec(url: string) {
18
+ const spec = await parseSpec(url)
19
+
20
+ emits('update:spec', spec)
21
+
22
+ return spec
23
+ }
24
+
25
+ async function parseSpec(url: string) {
26
+ const res = await fetch(url)
27
+
28
+ if (!res.ok) {
29
+ throw new Error(`Failed to fetch ${url}`)
30
+ }
31
+
32
+ if (res.headers.get('content-type')?.includes('text/yaml') || url.endsWith('.yaml') || url.endsWith('.yml')) {
33
+ return parseYAML(await res.text())
34
+ }
35
+
36
+ return res.json()
37
+ }
38
+ </script>
39
+
40
+ <template>
41
+ <slot :spec="spec" />
42
+ </template>
@@ -0,0 +1,30 @@
1
+ <script setup lang="ts">
2
+ import OARemoteRoot from './OARemoteRoot.vue'
3
+
4
+ const props = defineProps({
5
+ specUrl: {
6
+ type: String,
7
+ required: true,
8
+ },
9
+ operationId: {
10
+ type: String,
11
+ required: true,
12
+ },
13
+ })
14
+
15
+ const emits = defineEmits([
16
+ 'update:spec',
17
+ ])
18
+ </script>
19
+
20
+ <template>
21
+ <OARemoteRoot :spec-url="props.specUrl" @update:spec="emits('update:spec', $event)">
22
+ <template #default="{ spec }">
23
+ <OAOperation
24
+ :spec="spec"
25
+ :operation-id="props.operationId"
26
+ v-bind="$attrs"
27
+ />
28
+ </template>
29
+ </OARemoteRoot>
30
+ </template>