-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
60 lines (54 loc) · 1.6 KB
/
app.vue
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<script setup>
const collection = ref('')
const openapi = ref('')
const editorOptions = {
theme: 'vs-dark',
minimap: {
enabled: false
},
}
let timeout
let delay = 1000
async function callApi() {
const res = await $fetch('/api/postman-to-openapi', {
method: 'POST',
body: { collection: collection.value }
})
openapi.value = res.data
}
watch(collection, (newValue) => {
if (newValue.length < 1) {
// clear
return
}
clearTimeout(timeout)
timeout = setTimeout(callApi, delay)
})
function copyToClipboard() {
navigator.clipboard.writeText(openapi.value)
alert('Copied to clipboard!')
}
</script>
<template>
<div class="flex h-svh bg-gray-800 p-4 space-x-4 text-white">
<div class="flex-1 flex flex-col space-y-2">
<div class="h-8">Postman Collection</div>
<div class="flex-1 rounded-lg overflow-hidden">
<MonacoEditor v-model="collection" lang="json" :options="editorOptions" class="h-full w-full" />
</div>
</div>
<div class="flex-1 flex flex-col space-y-2">
<div class="h-8 flex items-center justify-between">
<div>OpenAPI</div>
<div class="flex items-center">
<button @click="copyToClipboard" class="inline-flex items-center justify-center p-1 transition-colors duration-150 rounded-lg hover:bg-gray-600">
<Icon name="fluent:copy-16-regular" class="text-xl" />
</button>
</div>
</div>
<div class="flex-1 rounded-lg overflow-hidden">
<MonacoEditor v-model="openapi" lang="yaml" :options="editorOptions" class="h-full w-full" />
</div>
</div>
</div>
</template>