rapi-doc / RapiDoc

RapiDoc -WebComponent for OpenAPI Spec
https://rapidocweb.com
MIT License
1.61k stars 271 forks source link

Blinking Error when Using loadSpec() #970

Open wndisra opened 8 months ago

wndisra commented 8 months ago

Hi @mrin9.

I've been trying to use RapiDoc as open API YAML spec viewer with no luck for last few days. I'm using it with below code.

<template>
    <div>
        <rapi-doc style="height:100vh; width:100%" ref="specref" render-style="read" :spec-url="specurl">
        </rapi-doc>
    </div>
</template>

<script setup>
import { ref, onMounted } from "vue"
import { parse } from 'yaml'

const route = useRoute()
const specurl = ref('')
const specref = ref(null)
const apiPath = route.params.path.join('/')
const config = useRuntimeConfig()

specurl.value = apiPath

// const path = `/repositories/${apiPath}`
const path = `OAI/OpenAPI-Specification/main/examples/v3.0/api-with-examples.yaml`
let { data: spec, error: err } = await useAsyncData('spec', () => $fetch(path, {
    method: 'GET',
    baseURL: 'https://raw.githubusercontent.com',
    headers: {
    },
    params: {}
}))

onMounted(() => {
    let apispec = specref.value
    let data = parse(spec.value)
    apispec.loadSpec(data)
})
</script>

The API spec loads for about 1 sec and then redirected automatically to error page (unable to load spec) immediately after.

Screenshot 2023-10-30 at 10 57 00

Stacks:

Please help. Thanks in advance.

prassie commented 8 months ago

Won't it be simpler/easier to use a simple static html like this: https://rapidocweb.com/examples/api-demo.html ?