Skip to content

Commit c4272d9

Browse files
committed
Merge branch 'defaultExpandDepth' of https://github.com/jy95/docusaurus-json-schema-plugin into defaultExpandDepth
2 parents 821ea6c + 10e3451 commit c4272d9

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

src/theme/JSONSchemaViewer/components/SchemaItem/SchemaItem.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ export default function SchemaItem({
4141
const { defaultExpandDepth } = useJSVOptionsContext()
4242

4343
// Determine if Collapsible should be open or closed by default
44-
const isOpenByDefault = level < (defaultExpandDepth ?? 0)
45-
44+
// Depth is measured from root (root level = 0). Clamp negatives to 0.
45+
const expandDepth = defaultExpandDepth ?? 0;
46+
const isOpenByDefault = level <= expandDepth
4647
// Notice : "deprecated" started at 2019-09
4748
let typedSchema = schema as JSONSchema_Draft_2019_09
4849
let isDeprecated =

src/theme/JSONSchemaViewer/contexts/jsvOptions.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ export type JSVOptions = {
3939
*/
4040
UnresolvedRefsComponent?: (params: { schema: JSONSchema }) => JSX.Element
4141
/**
42-
* Defines how deep the schema should be expanded by default.
43-
* @default 0 No expansion at all (only root level expanded)
42+
* Defines how deep the schema should be expanded by default
43+
* Examples:
44+
* - 0: only the root level is expanded
45+
* - 1: root level and its direct children are expanded
46+
* - Infinity: expand all levels
47+
* @default 0
48+
* @min 0
4449
*/
4550
defaultExpandDepth?: number
4651
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
description: Defines how deep the schema should be expanded by default
3+
title: "📏 Custom defaultExpandDepth"
4+
---
5+
6+
import CodeBlock from '@theme/CodeBlock';
7+
import Schema from "@site/static/schemas/examples/custom/defaultExpandDepth.json";
8+
import JSONSchemaViewer from "@theme/JSONSchemaViewer";
9+
import ReactMarkdown from 'react-markdown'
10+
import Tabs from '@theme/Tabs';
11+
import TabItem from '@theme/TabItem';
12+
13+
# Custom defaultExpandDepth
14+
15+
<Tabs>
16+
<TabItem value="Viewer" label="Viewer" default>
17+
<JSONSchemaViewer
18+
schema={ Schema }
19+
viewerOptions={{
20+
defaultExpandDepth: Infinity
21+
}}
22+
/>
23+
</TabItem>
24+
<TabItem value="viewerOptions" label='viewerOptions'>
25+
```js
26+
{
27+
defaultExpandDepth: Infinity
28+
}
29+
```
30+
</TabItem>
31+
<TabItem value="JSON Schema" label='JSON Schema'>
32+
<CodeBlock language="json-schema">{JSON.stringify(Schema, null, 2)}</CodeBlock>
33+
</TabItem>
34+
</Tabs>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"level1_prop1": {
5+
"type": "string"
6+
},
7+
"level1_prop2": {
8+
"type": "object",
9+
"properties": {
10+
"level2_prop1": {
11+
"type": "integer"
12+
},
13+
"level2_prop2": {
14+
"type": "object",
15+
"properties": {
16+
"level3_prop1": {
17+
"type": "boolean"
18+
}
19+
}
20+
}
21+
}
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)