Skip to content

Commit dfdf3a1

Browse files
committed
feat(Playground): add x-playground-example extension for custom examples
1 parent aa100d0 commit dfdf3a1

File tree

6 files changed

+515
-0
lines changed

6 files changed

+515
-0
lines changed

docs/.vitepress/config.mts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ export default defineConfigWithTheme({
160160
},
161161
],
162162
},
163+
{
164+
text: 'Playground',
165+
items: [
166+
{
167+
items: [
168+
{
169+
text: 'Examples',
170+
link: '/customizations/playground-examples',
171+
},
172+
],
173+
},
174+
],
175+
},
163176
],
164177
},
165178
],
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: Playground Examples API
3+
---
4+
5+
<script setup>
6+
import { useOpenapi } from 'vitepress-openapi/client'
7+
8+
useOpenapi({
9+
spec: '/openapi-playground-examples.json',
10+
})
11+
</script>
12+
13+
# Playground Examples
14+
15+
When using the Playground, parameter examples are automatically populated from the OpenAPI specification. By default, the Playground uses the `example` or `examples` properties defined in the OpenAPI spec.
16+
17+
### Playground-specific Examples
18+
19+
If you want to specify examples specifically for the Playground that are different from the examples in the OpenAPI spec, you can use the `x-playground-example` extension:
20+
21+
```json
22+
{
23+
"name": "id",
24+
"in": "query",
25+
"required": false,
26+
"description": "Filter by ID",
27+
"x-playground-example": "playground-specific-value",
28+
"schema": {
29+
"type": "string",
30+
"example": "general-example-value"
31+
}
32+
}
33+
```
34+
35+
The `x-playground-example` extension can be used at both the parameter level and the schema level:
36+
37+
```json
38+
{
39+
"name": "id",
40+
"in": "query",
41+
"required": false,
42+
"description": "Filter by ID",
43+
"schema": {
44+
"type": "string",
45+
"example": "general-example-value",
46+
"x-playground-example": "schema-level-playground-example"
47+
}
48+
}
49+
```
50+
51+
The Playground will prioritize examples in the following order:
52+
1. `x-playground-example` at the parameter level
53+
2. `x-playground-example` at the schema level
54+
3. `example` at the parameter level
55+
4. First item in `examples` array at the parameter level
56+
5. `example` at the schema level
57+
6. First item in `examples` array at the schema level
58+
59+
## Example
60+
61+
You can see a live example of this in action in the [Playground Examples API](/tests/playground-examples).

docs/pages.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ export const testsPages = [
2929
specPath: './public/openapi-security.json',
3030
themeConfig: {},
3131
},
32+
{
33+
slug: 'playground-examples',
34+
label: 'Playground Examples',
35+
specPath: './public/openapi-playground-examples.json',
36+
themeConfig: {},
37+
},
3238
]
3339

3440
export const examplesPages = [

0 commit comments

Comments
 (0)