Skip to content

Multiple specs

You can use multiple OpenAPI specs on the same page by importing them and passing them as spec prop to the OAOperation component.

Example

In this example, we are using two different specs to render the same operation.

markdown
---
aside: false
outline: false
title: vitepress-openapi
---

<script setup lang="ts">
import { useData } from 'vitepress'
import defaultSpec from './openapi.json'
import schemasSpec from './openapi-schemas.json'

const { isDark } = useData()
</script>

::: info
Using [default spec](../public/openapi.json)
:::

<OAOperation operationId="getAllArtists" :spec="defaultSpec" :isDark="isDark" />

---

::: info
Using [schemas spec](../public/openapi-schemas.json)
:::

<OAOperation operationId="getCircularReference" :spec="schemasSpec" :isDark="isDark" />

INFO

Using default spec


INFO

Using schemas spec

Get a parent

GET
/circular-reference

Example of a JSON object with a circular reference.

Responses

A parent with a child
application/json
JSON
{
"id": "string",
"child": {
"id": "string",
"parent": "[Circular Reference]"
}
}

Samples

Bruno
get {
  url: http://localhost/circular-reference
}

headers {
  Content-Type: application/json
}
cURL
curl -X GET \
'http://localhost/circular-reference' \
 -H "Content-Type: application/json"
JavaScript
fetch('http://localhost/circular-reference', {headers:{'Content-Type':'application/json'}})
  .then(response => response.json())
  .then(data => console.log(data));
PHP
<?php
$url = 'http://localhost/circular-reference';
$method = 'GET';
$headers = [
    'Content-Type' => 'application/json',
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>
Python
import requests

url = 'http://localhost/circular-reference'

headers = {
    'Content-Type': 'application/json'
}

response = requests.get(url, headers=headers)
print(response.json())
Powered by VitePress OpenAPI