Repository: enzonotario/vitepress-openapi
Pull request #99 (2024-10-25 22:51:29)

feat: avoidCirculars && lazyRendering
<!-- Provide a general summary of your changes in the title above. -->

# Description

- Adds an option to avoid circular references when parsing schemas
- Adds an option to lazy render Tags and Operations (for larger schemas)

## Related issues/external references

#65 

## Types of changes

- New feature


vercel[bot]: [vc]: #EDPft8OBfoVTFgf+c9MmMRBpcGDPJ4Oyugcar4VLKcE=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJ2aXRlcHJlc3Mtb3BlbmFwaSIsImxpdmVGZWVkYmFjayI6eyJyZXNvbHZlZCI6MCwidW5yZXNvbHZlZCI6MCwidG90YWwiOjAsImxpbmsiOiJ2aXRlcHJlc3Mtb3BlbmFwaS1naXQtZmVhdHVyZS1sYXotNTg0MzFiLWVuem8tbm90YXJpb3MtcHJvamVjdHMudmVyY2VsLmFwcCJ9LCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vZW56by1ub3Rhcmlvcy1wcm9qZWN0cy92aXRlcHJlc3Mtb3BlbmFwaS9HR1pTN1lETG5ndHNwcWlHbVNnQ2k2THhaWkVzIiwicHJldmlld1VybCI6InZpdGVwcmVzcy1vcGVuYXBpLWdpdC1mZWF0dXJlLWxhei01ODQzMWItZW56by1ub3Rhcmlvcy1wcm9qZWN0cy52ZXJjZWwuYXBwIiwibmV4dENvbW1pdFN0YXR1cyI6IkRFUExPWUVEIn1dfQ==
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Comments | Updated (UTC) |
| :--- | :----- | :------ | :------- | :------ |
| **vitepress-openapi** | ✅ Ready ([Inspect](https://vercel.com/enzo-notarios-projects/vitepress-openapi/GGZS7YDLngtspqiGmSgCi6LxZZEs)) | [Visit Preview](https://vercel.live/open-feedback/vitepress-openapi-git-feature-laz-58431b-enzo-notarios-projects.vercel.app?via=pr-comment-visit-preview-link&passThrough=1) | 💬 [**Add feedback**](https://vercel.live/open-feedback/vitepress-openapi-git-feature-laz-58431b-enzo-notarios-projects.vercel.app?via=pr-comment-feedback-link) | Oct 25, 2024 10:51pm |


coderabbitai[bot]: <!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- This is an auto-generated comment: review in progress by coderabbit.ai -->

> [!NOTE]
> Currently processing new changes in this PR. This may take a few minutes, please wait...
> 
> 	<details>
> <summary>📥 Commits</summary>
> 
> Files that changed from the base of the PR and between 246d360ff53441e9e3f1329283824b2401ad295a and 2c76eae0dabcde06dbc9355c99f834b227f47546.
> 
> </details>
> 
> <details>
> <summary>📒 Files selected for processing (12)</summary>
> 
> * docs/composables/useTheme.md (2 hunks)
> * src/components/Common/Lazy/OALazy.vue (1 hunks)
> * src/components/Common/Lazy/lazyBus.ts (1 hunks)
> * src/components/Path/OAPaths.vue (2 hunks)
> * src/components/Path/OAPathsByTags.vue (4 hunks)
> * src/composables/useTheme.ts (3 hunks)
> * src/lib/formatJson.ts (1 hunks)
> * src/lib/formatJsonWithCircularRef.ts (1 hunks)
> * src/lib/generateSchemaJson.ts (2 hunks)
> * src/lib/hasExample.ts (1 hunks)
> * test/composables/useTheme.test.ts (3 hunks)
> * test/lib/formatJsonWithCircularRef.test.ts (1 hunks)
> 
> </details>
> 
> 	```ascii
>  _________________________
> < Think twice, code once. >
>  -------------------------
>   \
>    \   \
>         \ /\
>         ( )
>       .( o ).
> ```

<!-- end of auto-generated comment: review in progress by coderabbit.ai --><!-- tips_start -->

---

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Generate unit testing code for this file.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai generate unit testing code for this file.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and generate unit testing code.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->
pkg-pr-new[bot]: 
[Open in Stackblitz](https://pkg.pr.new/template/8ed98f77-5935-428c-8a1e-4d3e015bc532)


```
pnpm add https://pkg.pr.new/vitepress-openapi@99
```


```
pnpm add https://pkg.pr.new/vitepress-openapi@99
```


_commit: <a href="https://github.com/enzonotario/vitepress-openapi/runs/32090665377"><code>2c76eae</code></a>_


Patch:
diff --git a/docs/composables/useTheme.md b/docs/composables/useTheme.md
index 6da5e32..23f1b18 100644
--- a/docs/composables/useTheme.md
+++ b/docs/composables/useTheme.md
@@ -68,9 +68,11 @@ export default {
             },
             // Set spec configuration.
             spec: {
-                groupByTags: true,
-                collapsePaths: false,
-                showPathsSummary: true,
+                groupByTags: true, // Group paths by tags.
+                collapsePaths: false, // Collapse paths when grouping by tags.
+                showPathsSummary: true, // Show a summary of the paths when grouping by tags.
+                avoidCirculars: false, // Avoid circular references when parsing schemas.
+                lazyRendering: false, // Lazy render Paths and Tags components.
             },
         })
     }
@@ -133,4 +135,4 @@ export default {
 
 | Function        | Description                  | Default Value                                                         | Allowed Values                                                                |
 |-----------------|------------------------------|-----------------------------------------------------------------------|-------------------------------------------------------------------------------|
-| `setSpecConfig` | Sets the spec configuration. | `{ groupByTags: true, collapsePaths: false, showPathsSummary: true }` | `{ groupByTags: boolean, collapsePaths: boolean, showPathsSummary: boolean }` |
+| `setSpecConfig` | Sets the spec configuration. | `{ groupByTags: true, collapsePaths: false, showPathsSummary: true, avoidCirculars: false, lazyRendering: false }` | `{ groupByTags: boolean, collapsePaths: boolean, showPathsSummary: boolean, avoidCirculars: boolean, lazyRendering: boolean }` |
diff --git a/src/components/Common/Lazy/OALazy.vue b/src/components/Common/Lazy/OALazy.vue
new file mode 100644
index 0000000..f501465
--- /dev/null
+++ b/src/components/Common/Lazy/OALazy.vue
@@ -0,0 +1,55 @@
+<script lang="ts" setup>
+import { nextTick, ref } from 'vue'
+
+import { lazyBus } from './lazyBus'
+
+/**
+ * Component which loads lazily when the browser is "idle"
+ * Disabled if being rendered from the server
+ *
+ * @link https://medium.com/js-dojo/lazy-rendering-in-vue-to-improve-performance-dcccd445d5f
+ * @author [Scalar](https://github.com/scalar/scalar/tree/main/packages/api-reference)
+ */
+const props = withDefaults(
+  defineProps<{
+    // Identifier for loaded event, if no ID is passed then no event is dispatched
+    id?: string
+    // To lazyload or not to lazyload, that is the question
+    isLazy?: boolean
+    // Amount of time in ms to wait before triggering requestIdleCallback
+    lazyTimeout?: number
+  }>(),
+  {
+    isLazy: true,
+    lazyTimeout: 0,
+  },
+)
+
+const onIdle = (cb = () => {}) => {
+  if (typeof window === 'undefined') {
+    // Do nothing and load on the client only
+  } else if ('requestIdleCallback' in window) {
+    setTimeout(() => window.requestIdleCallback(cb), props.lazyTimeout)
+  } else {
+    setTimeout(() => nextTick(cb), props.lazyTimeout ?? 300)
+  }
+}
+
+const shouldRender = ref(!props.isLazy)
+
+// Fire the event for non-lazy components as well to keep track of loading
+if (props.isLazy) {
+  onIdle(() => {
+    shouldRender.value = true
+    if (props.id) {
+      nextTick(() => lazyBus.emit({ id: props.id! }))
+    }
+  })
+} else if (props.id) {
+  nextTick(() => lazyBus.emit({ id: props.id! }))
+}
+</script>
+
+<template>
+  <slot v-if="shouldRender" />
+</template>
diff --git a/src/components/Common/Lazy/lazyBus.ts b/src/components/Common/Lazy/lazyBus.ts
new file mode 100644
index 0000000..9762a98
--- /dev/null
+++ b/src/components/Common/Lazy/lazyBus.ts
@@ -0,0 +1,7 @@
+import { type EventBusKey, useEventBus } from '@vueuse/core'
+
+/**
+ * Setup an event bus so we can listen for loaded events.
+ */
+const lazyEventBusKey: EventBusKey<{ id: string }> = Symbol('lazyEventBus')
+export const lazyBus = useEventBus(lazyEventBusKey)
diff --git a/src/components/Path/OAPaths.vue b/src/components/Path/OAPaths.vue
index ac5aa85..ccb3591 100644
--- a/src/components/Path/OAPaths.vue
+++ b/src/components/Path/OAPaths.vue
@@ -1,5 +1,6 @@
 <script setup>
 import { defineProps } from 'vue'
+import OALazy from 'vitepress-openapi/components/Common/Lazy/OALazy.vue'
 
 const { openapi, paths, isDark } = defineProps({
   openapi: {
@@ -15,27 +16,33 @@ const { openapi, paths, isDark } = defineProps({
     default: false,
   },
 })
+
+const operations = Object.entries(paths).reduce((acc, [_, path]) => {
+  return [
+    ...acc,
+    ...Object.keys(path).filter(m => path[m].operationId).map((method) => {
+      return {
+        operationId: path[method].operationId,
+      }
+    }),
+  ]
+}, [])
 </script>
 
 <template>
-  <div
-    v-for="(path, pathName) in paths"
-    :key="pathName"
-    class="flex flex-col space-y-10"
+  <OALazy
+    v-for="(operation, operationIdx) in operations"
+    :key="operation.operationId"
+    :is-lazy="operationIdx > 0"
   >
-    <template
-      v-for="method in Object.keys(path).filter(m => path[m].operationId)"
-      :key="`${method}-${path.id}`"
-    >
-      <OAOperation
-        :operation-id="path[method].operationId"
-        :openapi="openapi"
-        :is-dark="isDark"
-        prefix-headings
-        hide-default-footer
-      />
+    <OAOperation
+      :operation-id="operation.operationId"
+      :openapi="openapi"
+      :is-dark="isDark"
+      prefix-headings
+      hide-default-footer
+    />
 
-      <hr>
-    </template>
-  </div>
+    <hr>
+  </OALazy>
 </template>
diff --git a/src/components/Path/OAPathsByTags.vue b/src/components/Path/OAPathsByTags.vue
index e1be8e7..d2707d6 100644
--- a/src/components/Path/OAPathsByTags.vue
+++ b/src/components/Path/OAPathsByTags.vue
@@ -1,10 +1,11 @@
 <script setup>
-import { defineProps, ref } from 'vue'
+import { defineProps, nextTick, ref } from 'vue'
 import { Collapsible, CollapsibleTrigger } from 'vitepress-openapi/components/ui/collapsible'
 import { Button } from 'vitepress-openapi/components/ui/button'
 import { useI18n } from 'vue-i18n'
 import { getOpenApiInstance, useTheme } from 'vitepress-openapi'
 import OAPathsSummary from 'vitepress-openapi/components/Path/OAPathsSummary.vue'
+import OALazy from 'vitepress-openapi/components/Common/Lazy/OALazy.vue'
 
 const props = defineProps({
   openapi: {
@@ -42,12 +43,19 @@ const pathsByTags = operationsTags.map((tag) => {
   }
 })
 
+const pathsWithoutTags = openapi.getPathsWithoutTags()
+
 const internalTags = ref([
-  {
-    tag: t('Default'),
-    paths: openapi.getPathsWithoutTags(),
-    isOpen: !themeConfig.getSpecConfig().collapsePaths.value,
-  },
+  ...(pathsWithoutTags.length
+    ? [
+        {
+          tag: t('Default'),
+          paths: pathsWithoutTags,
+          isOpen: !themeConfig.getSpecConfig().collapsePaths.value,
+        },
+      ]
+    : []),
+
   ...pathsByTags.map((tag) => {
     return {
       tag: tag.tag,
@@ -80,17 +88,19 @@ function scrollIntoViewWithOffset(hash, offset) {
 function onPathClick(tagPaths, hash) {
   tagPaths.isOpen = true
 
-  setTimeout(() => {
+  nextTick(() => {
     scrollIntoViewWithOffset(hash, 120)
   })
 }
+
+const lazyRendering = themeConfig.getSpecConfig().lazyRendering.value
 </script>
 
 <template>
-  <div
-    v-for="tagPaths in internalTags"
+  <OALazy
+    v-for="(tagPaths, tagIdx) in internalTags"
     :key="tagPaths.tag"
-    class="flex flex-col space-y-10"
+    :is-lazy="tagIdx > 0"
   >
     <Collapsible
       v-if="Object.keys(tagPaths.paths).length"
@@ -133,12 +143,16 @@ function onPathClick(tagPaths, hash) {
 
       <hr>
 
-      <div class="flex flex-col space-y-10" :class="[{ hidden: !tagPaths.isOpen }]">
+      <div
+        v-if="!lazyRendering || tagPaths.isOpen"
+        class="flex flex-col space-y-10"
+        :class="[{ hidden: !tagPaths.isOpen }]"
+      >
         <OAPaths
           :openapi="openapi"
           :paths="tagPaths.paths"
         />
       </div>
     </Collapsible>
-  </div>
+  </OALazy>
 </template>
diff --git a/src/components/Try/OATryWithVariables.vue b/src/components/Try/OATryWithVariables.vue
index c706d7e..4f2095e 100644
--- a/src/components/Try/OATryWithVariables.vue
+++ b/src/components/Try/OATryWithVariables.vue
@@ -52,15 +52,13 @@ const request = ref({
 const loading = ref(false)
 
 const curl = computed(() => {
-  const headers = request.value.headers
-  if (!headers?.['Content-Type']) {
-    headers['Content-Type'] = 'application/json'
-  }
-
   return fetchToCurl({
     method: props.method.toUpperCase(),
     url: request.value.url,
-    headers,
+    headers: {
+      ...request.value.headers,
+      ...(!request.value.headers?.['Content-Type'] ? { 'Content-Type': 'application/json' } : {}),
+    },
     body: request.value.body ? formatJson(request.value.body) : null,
   })
 })
diff --git a/src/composables/useTheme.ts b/src/composables/useTheme.ts
index 9606690..9e5971e 100644
--- a/src/composables/useTheme.ts
+++ b/src/composables/useTheme.ts
@@ -69,6 +69,8 @@ export interface SpecConfig {
   groupByTags: Ref<boolean>
   collapsePaths: Ref<boolean>
   showPathsSummary: Ref<boolean>
+  avoidCirculars: Ref<boolean>
+  lazyRendering: Ref<boolean>
 }
 
 export interface UseThemeConfig {
@@ -137,6 +139,8 @@ const themeConfig: UseThemeConfig = {
     groupByTags: ref(true),
     collapsePaths: ref(false),
     showPathsSummary: ref(true),
+    avoidCirculars: ref(false),
+    lazyRendering: ref(false),
   },
 }
 
@@ -385,6 +389,14 @@ export function useTheme(config: Partial<UseThemeConfig> = {}) {
     if (config.showPathsSummary !== undefined) {
       themeConfig.spec.showPathsSummary.value = config.showPathsSummary
     }
+
+    if (config.avoidCirculars !== undefined) {
+      themeConfig.spec.avoidCirculars.value = config.avoidCirculars
+    }
+
+    if (config.lazyRendering !== undefined) {
+      themeConfig.spec.lazyRendering.value = config.lazyRendering
+    }
   }
 
   return {
diff --git a/src/lib/OpenApi.ts b/src/lib/OpenApi.ts
index e56644f..da64592 100644
--- a/src/lib/OpenApi.ts
+++ b/src/lib/OpenApi.ts
@@ -243,7 +243,7 @@ export function OpenApi({
   }
 
   return {
-    spec,
+    spec: parsedSpec ?? transformedSpec ?? spec,
     transformedSpec,
     parsedSpec,
     getBaseUrl,
diff --git a/src/lib/formatJson.ts b/src/lib/formatJson.ts
index d0349a6..0a577a7 100644
--- a/src/lib/formatJson.ts
+++ b/src/lib/formatJson.ts
@@ -1,4 +1,11 @@
+import { useTheme } from '../composables/useTheme'
+import { formatJsonWithCircularRef } from './formatJsonWithCircularRef'
+
 export function formatJson(json: any): string {
+  if (useTheme().getSpecConfig().avoidCirculars.value) {
+    return formatJsonWithCircularRef(json)
+  }
+
   if (typeof json !== 'object' && typeof json !== 'undefined' && json !== null) {
     return '{}'
   }
diff --git a/src/lib/formatJsonWithCircularRef.ts b/src/lib/formatJsonWithCircularRef.ts
new file mode 100644
index 0000000..64da88d
--- /dev/null
+++ b/src/lib/formatJsonWithCircularRef.ts
@@ -0,0 +1,33 @@
+export function formatJsonWithCircularRef(json: any): string {
+  if (typeof json !== 'object' && typeof json !== 'undefined' && json !== null) {
+    return '{}'
+  }
+
+  try {
+    return JSON.stringify(json, null, 2)
+  } catch {
+    return replaceCircularDependencies(json)
+  }
+}
+
+/**
+ * JSON.stringify, but with circular dependencies replaced with '[Circular]'.
+ */
+function replaceCircularDependencies(content: any) {
+  const cache = new Set()
+
+  return JSON.stringify(
+    content,
+    (_, value) => {
+      if (typeof value === 'object' && value !== null) {
+        if (cache.has(value)) {
+          return '[Circular]'
+        }
+
+        cache.add(value)
+      }
+      return value
+    },
+    2,
+  )
+}
diff --git a/src/lib/generateSchemaJson.ts b/src/lib/generateSchemaJson.ts
index 3718778..850107e 100644
--- a/src/lib/generateSchemaJson.ts
+++ b/src/lib/generateSchemaJson.ts
@@ -1,3 +1,4 @@
+import { useTheme } from '../composables/useTheme'
 import { formatJson } from './formatJson'
 import { getExample } from './getExample'
 
@@ -6,6 +7,10 @@ export function generateSchemaJson(schema: any, useExample = false) {
     return '{}'
   }
 
+  if (useTheme().getSpecConfig().avoidCirculars.value) {
+    schema = JSON.parse(formatJson(schema))
+  }
+
   const properties = propertiesTypesJsonRecursive(schema, useExample, new Set())
 
   if (properties === null) {
diff --git a/src/lib/hasExample.ts b/src/lib/hasExample.ts
index 0ad06ff..592e4b9 100644
--- a/src/lib/hasExample.ts
+++ b/src/lib/hasExample.ts
@@ -1,4 +1,15 @@
+import { useTheme } from '../composables/useTheme'
+import { formatJson } from './formatJson'
+
 export function hasExample(schema: any, visited: Set<any> = new Set(), level: number = 0): boolean {
+  if (!schema) {
+    return false
+  }
+
+  if (useTheme().getSpecConfig().avoidCirculars.value) {
+    schema = JSON.parse(formatJson(schema))
+  }
+
   if (visited.has(schema)) {
     if (level > 10) {
       return false // Assume no example for circular references.


Test patch:
diff --git a/test/composables/useTheme.test.ts b/test/composables/useTheme.test.ts
index 108665b..650e1cf 100644
--- a/test/composables/useTheme.test.ts
+++ b/test/composables/useTheme.test.ts
@@ -1,4 +1,5 @@
 import { describe, expect, it } from 'vitest'
+import { ref } from 'vue'
 import { useTheme } from '../../src/composables/useTheme'
 
 describe('composition API', () => {
@@ -82,9 +83,11 @@ describe('composition API', () => {
     expect(theme.getSecuritySelectedScheme()).toBe('bearer')
     expect(theme.getI18nConfig().locale.value).toBe('es')
     expect(theme.getSpecConfig()).toEqual({
-      groupByTags: expect.any(Object),
-      collapsePaths: expect.any(Object),
-      showPathsSummary: expect.any(Object),
+      groupByTags: ref(false),
+      collapsePaths: ref(true),
+      showPathsSummary: ref(false),
+      avoidCirculars: ref(false),
+      lazyRendering: ref(false),
     })
   })
 
@@ -318,17 +321,27 @@ describe('useTheme', () => {
   it('returns the spec config', () => {
     const result = themeConfig.getSpecConfig()
     expect(result).toEqual({
-      groupByTags: expect.any(Object),
-      collapsePaths: expect.any(Object),
-      showPathsSummary: expect.any(Object),
+      groupByTags: ref(true),
+      collapsePaths: ref(false),
+      showPathsSummary: ref(true),
+      avoidCirculars: ref(false),
+      lazyRendering: ref(false),
     })
   })
 
   it('sets spec config', () => {
-    themeConfig.setSpecConfig({ groupByTags: false, collapsePaths: true, showPathsSummary: false })
+    themeConfig.setSpecConfig({
+      groupByTags: false,
+      collapsePaths: true,
+      showPathsSummary: false,
+      avoidCirculars: true,
+      lazyRendering: true,
+    })
     const result = themeConfig.getSpecConfig()
     result.groupByTags.value = false
     result.collapsePaths.value = true
     result.showPathsSummary.value = false
+    result.avoidCirculars.value = true
+    result.lazyRendering.value = true
   })
 })
diff --git a/test/lib/formatJsonWithCircularRef.test.ts b/test/lib/formatJsonWithCircularRef.test.ts
new file mode 100644
index 0000000..8430d44
--- /dev/null
+++ b/test/lib/formatJsonWithCircularRef.test.ts
@@ -0,0 +1,14 @@
+import { describe, expect, it } from 'vitest'
+import { formatJsonWithCircularRef } from '../../src/lib/formatJsonWithCircularRef'
+
+describe('formatJsonWithCircularRef', () => {
+  it('formats a JSON object with circular reference', () => {
+    const input: any = { key: 'value' }
+    input.circular = input
+    const output = formatJsonWithCircularRef(input)
+    expect(output).toBe(`{
+  "key": "value",
+  "circular": "[Circular]"
+}`)
+  })
+})