Repository: enzonotario/vitepress-openapi
Pull request #148 (2025-01-08 22:22:45)

refactor: move examples functions to own directory
# Description

Move examples functions to own directory

## Related issues/external references


## Types of changes

- Refactor

vercel[bot]: [vc]: #UEuKZXf47dN+3OkmRha+1cneAc2kAqA4h9k0+fdNGDs=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJ2aXRlcHJlc3Mtb3BlbmFwaSIsImluc3BlY3RvclVybCI6Imh0dHBzOi8vdmVyY2VsLmNvbS9lbnpvLW5vdGFyaW9zLXByb2plY3RzL3ZpdGVwcmVzcy1vcGVuYXBpLzcxbnp1WGdjNDlXaGhvaGdtN3lnQnc1MmpRbXciLCJwcmV2aWV3VXJsIjoidml0ZXByZXNzLW9wZW5hcGktZ2l0LWZlYXR1cmUtZXhhbXBsZXMtZW56by1ub3Rhcmlvcy1wcm9qZWN0cy52ZXJjZWwuYXBwIiwibmV4dENvbW1pdFN0YXR1cyI6IlBFTkRJTkciLCJsaXZlRmVlZGJhY2siOnsicmVzb2x2ZWQiOjAsInVucmVzb2x2ZWQiOjAsInRvdGFsIjowLCJsaW5rIjoidml0ZXByZXNzLW9wZW5hcGktZ2l0LWZlYXR1cmUtZXhhbXBsZXMtZW56by1ub3Rhcmlvcy1wcm9qZWN0cy52ZXJjZWwuYXBwIn19XX0=
**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** | 🔄 Building ([Inspect](https://vercel.com/enzo-notarios-projects/vitepress-openapi/71nzuXgc49Whhohgm7ygBw52jQmw)) | [Visit Preview](https://vitepress-openapi-git-feature-examples-enzo-notarios-projects.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/vitepress-openapi-git-feature-examples-enzo-notarios-projects.vercel.app?via=pr-comment-feedback-link) | Jan 8, 2025 10:22pm |


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

> [!WARNING]
> ## Rate limit exceeded
> 
> @enzonotario has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait **11 minutes and 32 seconds** before requesting another review.
> 
> <details>
> <summary>⌛ How to resolve this issue?</summary>
> 
> After the wait time has elapsed, a review can be triggered using the `@coderabbitai review` command as a PR comment. Alternatively, push new commits to this PR.
> 
> We recommend that you space out your commits to avoid hitting the rate limit.
> 
> </details>
> 
> 
> <details>
> <summary>🚦 How do rate limits work?</summary>
> 
> CodeRabbit enforces hourly rate limits for each developer per organization.
> 
> Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
> 
> Please see our [FAQ](https://docs.coderabbit.ai/faq) for further information.
> 
> </details>
> 
> <details>
> <summary>📥 Commits</summary>
> 
> Reviewing files that changed from the base of the PR and between 3b322594d224ba9061b9980f699e7c69ee578da5 and bc45f09296c5890164be2bf87d4c62817e67237a.
> 
> </details>
> 
> <details>
> <summary>📒 Files selected for processing (12)</summary>
> 
> * `docs/.vitepress/config.mts` (2 hunks)
> * `docs/pages.ts` (2 hunks)
> * `src/components/Parameter/OAParameterExamples.vue` (1 hunks)
> * `src/components/Playground/OAPlaygroundParameterInput.vue` (1 hunks)
> * `src/components/Playground/OAPlaygroundParameters.vue` (1 hunks)
> * `src/components/Schema/OASchemaTabs.vue` (1 hunks)
> * `src/lib/codeSamples/buildRequest.ts` (1 hunks)
> * `src/lib/getSchemaUi.ts` (1 hunks)
> * `src/lib/getSchemaUiJson.ts` (1 hunks)
> * `test/lib/examples/getPropertyExample.test.ts` (1 hunks)
> * `test/lib/examples/getPropertyExamples.test.ts` (1 hunks)
> * `test/lib/examples/hasExample.test.ts` (1 hunks)
> 
> </details>

<!-- end of auto-generated comment: rate limited by coderabbit.ai -->

<!-- finishing_touch_checkbox_start -->

## Finishing Touches

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

<!-- finishing_touch_checkbox_end -->
<!-- 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 generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#beta))
- `@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://docs.coderabbit.ai) 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/f76ac8a4-0bc8-43e4-8f29-c3706d2aeef3)


```
npm i https://pkg.pr.new/vitepress-openapi@148
```


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


Patch:
diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts
index 18cd254..e558950 100644
--- a/docs/.vitepress/config.mts
+++ b/docs/.vitepress/config.mts
@@ -1,6 +1,7 @@
 import { resolve } from 'node:path'
 import { useSidebar } from 'vitepress-openapi'
 import spec from '../public/openapi.json' assert { type: 'json' }
+import { examplesPages } from '../pages'
 import { defineConfigWithTheme } from 'vitepress'
 
 const sidebar = useSidebar({
@@ -224,26 +225,10 @@ export default defineConfigWithTheme({
         text: 'Remote Examples',
         collapsed: true,
         items: [
-          {
-            text: 'ArgentinaDatos',
-            link: '/examples/argentinadatos',
-          },
-          {
-            text: 'CriptoYA Argentina',
-            link: '/examples/criptoya-argentina',
-          },
-          {
-            text: 'Scalar Galaxy',
-            link: '/examples/scalar-galaxy',
-          },
-          {
-            text: 'Plant Store',
-            link: '/examples/plant-store',
-          },
-          {
-            text: 'Museum',
-            link: '/examples/museum',
-          },
+          ...examplesPages.map(page => ({
+            text: page.label,
+            link: `/examples/${page.slug}`,
+          })),
         ],
       },
     ],
diff --git a/docs/pages.ts b/docs/pages.ts
index 6f726db..4cb4021 100644
--- a/docs/pages.ts
+++ b/docs/pages.ts
@@ -29,11 +29,13 @@ export const testsPages = [
 export const examplesPages = [
   {
     slug: 'argentinadatos',
+    label: 'ArgentinaDatos',
     specUrl: 'https://argentinadatos.com/openapi.json',
     themeConfig: {},
   },
   {
     slug: 'criptoya-argentina',
+    label: 'CriptoYa Argentina',
     specUrl: 'https://docs.criptoya.com/argentina/openapi.json',
     themeConfig: {
       jsonViewer: {
@@ -49,17 +51,26 @@ export const examplesPages = [
   },
   {
     slug: 'scalar-galaxy',
+    label: 'Scalar Galaxy',
     specUrl: 'https://galaxy.scalar.com/openapi.yaml',
     themeConfig: {},
   },
   {
     slug: 'plant-store',
+    label: 'Mintlify Plant Store',
     specUrl: 'https://raw.githubusercontent.com/mintlify/starter/refs/heads/main/api-reference/openapi.json',
     themeConfig: {},
   },
   {
     slug: 'museum',
+    label: 'Redocly Museum',
     specUrl: 'https://raw.githubusercontent.com/Redocly/museum-openapi-example/refs/heads/main/openapi.yaml',
     themeConfig: {},
   },
+  {
+    slug: 'petstore-3.1',
+    label: 'Petstore 3.1',
+    specUrl: 'https://raw.githubusercontent.com/Redocly/redoc/refs/heads/main/demo/openapi-3-1.yaml',
+    themeConfig: {},
+  },
 ]
diff --git a/src/components/Parameter/OAParameterExamples.vue b/src/components/Parameter/OAParameterExamples.vue
index 6704b48..38312e1 100644
--- a/src/components/Parameter/OAParameterExamples.vue
+++ b/src/components/Parameter/OAParameterExamples.vue
@@ -1,6 +1,6 @@
 <script setup>
 import OACodeValue from '../Common/OACodeValue.vue'
-import { getPropertyExamples } from '../../lib/getPropertyExamples'
+import { getPropertyExamples } from '../../lib/examples/getPropertyExamples'
 import { useTheme } from '../../composables/useTheme'
 import OAParameterAttribute from './OAParameterAttribute.vue'
 
diff --git a/src/components/Playground/OAPlaygroundParameterInput.vue b/src/components/Playground/OAPlaygroundParameterInput.vue
index e73df77..0be3a9b 100644
--- a/src/components/Playground/OAPlaygroundParameterInput.vue
+++ b/src/components/Playground/OAPlaygroundParameterInput.vue
@@ -2,7 +2,7 @@
 import { defineEmits, defineProps, onMounted } from 'vue'
 import { Input } from '../ui/input'
 import { Checkbox } from '../ui/checkbox'
-import { getPropertyExample } from '../../lib/getPropertyExample'
+import { getPropertyExample } from '../../lib/examples/getPropertyExample'
 import {
   Select,
   SelectContent,
diff --git a/src/components/Playground/OAPlaygroundParameters.vue b/src/components/Playground/OAPlaygroundParameters.vue
index a6904a7..dfc82f5 100644
--- a/src/components/Playground/OAPlaygroundParameters.vue
+++ b/src/components/Playground/OAPlaygroundParameters.vue
@@ -8,7 +8,7 @@ import type { PlaygroundSecurityScheme, SecurityUiItem } from '../../types'
 import OAJSONEditor from '../Common/OAJSONEditor.vue'
 import OAPlaygroundParameterInput from '../Playground/OAPlaygroundParameterInput.vue'
 import OAPlaygroundSecurityInput from '../Playground/OAPlaygroundSecurityInput.vue'
-import { getPropertyExample } from '../../lib/getPropertyExample'
+import { getPropertyExample } from '../../lib/examples/getPropertyExample'
 import { buildRequest } from '../../lib/codeSamples/buildRequest'
 import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '../ui/select'
 import type { OperationData } from '../../lib/operationData'
diff --git a/src/components/Schema/OASchemaTabs.vue b/src/components/Schema/OASchemaTabs.vue
index c2590c3..f4d56fb 100644
--- a/src/components/Schema/OASchemaTabs.vue
+++ b/src/components/Schema/OASchemaTabs.vue
@@ -1,7 +1,7 @@
 <script setup>
 import { computed, ref } from 'vue'
 import { useTheme } from '../../composables/useTheme'
-import { hasExample } from '../../lib/hasExample'
+import { hasExample } from '../../lib/examples/hasExample'
 import { getSchemaUiContentType } from '../../lib/getSchemaUiContentType'
 import { Tabs, TabsContent, TabsList, TabsTrigger } from '../ui/tabs'
 import { Checkbox } from '../ui/checkbox'
diff --git a/src/lib/codeSamples/buildRequest.ts b/src/lib/codeSamples/buildRequest.ts
index a5909c8..7aec2c1 100644
--- a/src/lib/codeSamples/buildRequest.ts
+++ b/src/lib/codeSamples/buildRequest.ts
@@ -1,6 +1,6 @@
 import type { OpenAPIV3 } from '@scalar/openapi-types'
 import { unref } from 'vue'
-import { getPropertyExample } from '../getPropertyExample'
+import { getPropertyExample } from '../examples/getPropertyExample'
 import type { PlaygroundSecurityScheme } from '../../types'
 import { OARequest } from './request'
 
diff --git a/src/lib/getPropertyExample.ts b/src/lib/examples/getPropertyExample.ts
similarity index 100%
rename from src/lib/getPropertyExample.ts
rename to src/lib/examples/getPropertyExample.ts
diff --git a/src/lib/getPropertyExamples.ts b/src/lib/examples/getPropertyExamples.ts
similarity index 100%
rename from src/lib/getPropertyExamples.ts
rename to src/lib/examples/getPropertyExamples.ts
diff --git a/src/lib/hasExample.ts b/src/lib/examples/hasExample.ts
similarity index 100%
rename from src/lib/hasExample.ts
rename to src/lib/examples/hasExample.ts
diff --git a/src/lib/getSchemaUi.ts b/src/lib/getSchemaUi.ts
index e48c6bf..818da73 100644
--- a/src/lib/getSchemaUi.ts
+++ b/src/lib/getSchemaUi.ts
@@ -1,6 +1,6 @@
 import type { OpenAPI } from '@scalar/openapi-types'
 import { literalTypes } from '../index'
-import { getPropertyExamples } from './getPropertyExamples'
+import { getPropertyExamples } from './examples/getPropertyExamples'
 import { resolveCircularRef } from './resolveCircularRef'
 import { getConstraints, hasConstraints } from './constraintsParser'
 
diff --git a/src/lib/getSchemaUiJson.ts b/src/lib/getSchemaUiJson.ts
index 9eaf0e6..7e98bc9 100644
--- a/src/lib/getSchemaUiJson.ts
+++ b/src/lib/getSchemaUiJson.ts
@@ -1,5 +1,5 @@
 import { literalTypes } from '../index'
-import { getPropertyExample } from './getPropertyExample'
+import { getPropertyExample } from './examples/getPropertyExample'
 import type { OAProperty } from './getSchemaUi'
 
 export function getSchemaUiJson(uiProperties: OAProperty[] | OAProperty, useExample = false): any {


Test patch:
diff --git a/test/lib/getPropertyExample.test.ts b/test/lib/examples/getPropertyExample.test.ts
similarity index 96%
rename from test/lib/getPropertyExample.test.ts
rename to test/lib/examples/getPropertyExample.test.ts
index 095aecb..1288880 100644
--- a/test/lib/getPropertyExample.test.ts
+++ b/test/lib/examples/getPropertyExample.test.ts
@@ -1,5 +1,5 @@
 import { describe, expect, it } from 'vitest'
-import { getPropertyExample } from '../../src/lib/getPropertyExample'
+import { getPropertyExample } from '../../../src/lib/examples/getPropertyExample'
 
 describe('getPropertyExample', () => {
   it('returns the example property if it exists', () => {
diff --git a/test/lib/getPropertyExamples.test.ts b/test/lib/examples/getPropertyExamples.test.ts
similarity index 92%
rename from test/lib/getPropertyExamples.test.ts
rename to test/lib/examples/getPropertyExamples.test.ts
index 1cbe965..c4b562a 100644
--- a/test/lib/getPropertyExamples.test.ts
+++ b/test/lib/examples/getPropertyExamples.test.ts
@@ -1,5 +1,5 @@
 import { describe, expect, it } from 'vitest'
-import { getPropertyExamples } from '../../src/lib/getPropertyExamples'
+import { getPropertyExamples } from '../../../src/lib/examples/getPropertyExamples'
 
 describe('getPropertyExamples', () => {
   it('returns an array with the example property if it exists', () => {
diff --git a/test/lib/hasExample.test.ts b/test/lib/examples/hasExample.test.ts
similarity index 94%
rename from test/lib/hasExample.test.ts
rename to test/lib/examples/hasExample.test.ts
index b2fdb47..d08bb29 100644
--- a/test/lib/hasExample.test.ts
+++ b/test/lib/examples/hasExample.test.ts
@@ -1,7 +1,7 @@
 import { describe, expect, it } from 'vitest'
-import { hasExample } from '../../src/lib/hasExample'
-import { specWithCircularRef, specWithCircularRefAndExample } from '../testsConstants'
-import { getSchemaUi } from '../../src/lib/getSchemaUi'
+import { hasExample } from '../../../src/lib/examples/hasExample'
+import { specWithCircularRef, specWithCircularRefAndExample } from '../../testsConstants'
+import { getSchemaUi } from '../../../src/lib/getSchemaUi'
 
 describe('hasExample', () => {
   it('returns true if schema has an example at the root level', () => {