diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/PropertyNames.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/PropertyNames.jsx
index b84c0bd0..dfca5bc5 100644
--- a/src/core/plugins/json-schema-2020-12/components/keywords/PropertyNames.jsx
+++ b/src/core/plugins/json-schema-2020-12/components/keywords/PropertyNames.jsx
@@ -8,9 +8,6 @@ import { useFn, useComponent } from "../../hooks"
const PropertyNames = ({ schema }) => {
const fn = useFn()
-
- if (!fn.hasKeyword(schema, "propertyNames")) return null
-
const { propertyNames } = schema
const JSONSchema = useComponent("JSONSchema")
const name = (
@@ -19,6 +16,11 @@ const PropertyNames = ({ schema }) => {
)
+ /**
+ * Rendering.
+ */
+ if (!fn.hasKeyword(schema, "propertyNames")) return null
+
return (
diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Then.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/Then.jsx
index f3bfff67..0e05f462 100644
--- a/src/core/plugins/json-schema-2020-12/components/keywords/Then.jsx
+++ b/src/core/plugins/json-schema-2020-12/components/keywords/Then.jsx
@@ -8,10 +8,13 @@ import { useFn, useComponent } from "../../hooks"
const Then = ({ schema }) => {
const fn = useFn()
+ const JSONSchema = useComponent("JSONSchema")
+ /**
+ * Rendering.
+ */
if (!fn.hasKeyword(schema, "then")) return null
- const JSONSchema = useComponent("JSONSchema")
const name = (
Then
diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx
index 4c145d57..e9a1aa16 100644
--- a/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx
+++ b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx
@@ -8,11 +8,14 @@ import { useFn, useComponent } from "../../hooks"
const UnevaluatedItems = ({ schema }) => {
const fn = useFn()
-
- if (!fn.hasKeyword(schema, "unevaluatedItems")) return null
-
const { unevaluatedItems } = schema
const JSONSchema = useComponent("JSONSchema")
+
+ /**
+ * Rendering.
+ */
+ if (!fn.hasKeyword(schema, "unevaluatedItems")) return null
+
const name = (
Unevaluated items
diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx
index e10efee3..4fa6814d 100644
--- a/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx
+++ b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx
@@ -8,11 +8,14 @@ import { useFn, useComponent } from "../../hooks"
const UnevaluatedProperties = ({ schema }) => {
const fn = useFn()
-
- if (!fn.hasKeyword(schema, "unevaluatedProperties")) return null
-
const { unevaluatedProperties } = schema
const JSONSchema = useComponent("JSONSchema")
+
+ /**
+ * Rendering.
+ */
+ if (!fn.hasKeyword(schema, "unevaluatedProperties")) return null
+
const name = (
Unevaluated properties
diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/_all.scss b/src/core/plugins/json-schema-2020-12/components/keywords/_all.scss
index 0fecfab8..54d8ef68 100644
--- a/src/core/plugins/json-schema-2020-12/components/keywords/_all.scss
+++ b/src/core/plugins/json-schema-2020-12/components/keywords/_all.scss
@@ -1,9 +1,13 @@
.json-schema-2020-12-keyword {
margin: 5px 0 5px 0;
- & > ul {
+ &__children {
@include expansion-border;
padding: 0;
+
+ &--collapsed {
+ display: none;
+ }
}
&__name {
diff --git a/src/core/plugins/json-schema-2020-12/hoc.jsx b/src/core/plugins/json-schema-2020-12/hoc.jsx
index ca42b0c9..48e42a0d 100644
--- a/src/core/plugins/json-schema-2020-12/hoc.jsx
+++ b/src/core/plugins/json-schema-2020-12/hoc.jsx
@@ -88,6 +88,23 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
},
config: {
default$schema: "https://json-schema.org/draft/2020-12/schema",
+ /**
+ * Defines an upper exclusive boundary of the level range for automatic expansion.
+ *
+ * 0 -> do nothing
+ * 1 -> [0]...(1)
+ * 2 -> [0]...(2)
+ * 3 -> [0]...(3)
+ */
+ defaultExpandedLevels: 0, // 2 = 0...2
+ /**
+ * Can be turned on for complex and extensive schemas.
+ * Child schemas are not rendered until parent schema is expanded.
+ *
+ * By default, entire schema tree is rendered and collapsed parts of the
+ * tree are hidden with css.
+ */
+ optimizeExpansion: false,
...overrides.config,
},
fn: {
diff --git a/src/core/plugins/json-schema-2020-12/hooks.js b/src/core/plugins/json-schema-2020-12/hooks.js
index 0e433671..2afd91eb 100644
--- a/src/core/plugins/json-schema-2020-12/hooks.js
+++ b/src/core/plugins/json-schema-2020-12/hooks.js
@@ -39,7 +39,11 @@ export const useIsEmbedded = () => {
}
export const useIsExpandedDeeply = () => {
- return useContext(JSONSchemaDeepExpansionContext)
+ const [level] = useLevel()
+ const { defaultExpandedLevels } = useConfig()
+ const isExpandedByDefault = defaultExpandedLevels - level > 0
+
+ return isExpandedByDefault || useContext(JSONSchemaDeepExpansionContext)
}
export const useRenderedSchemas = (schema = undefined) => {
diff --git a/src/core/plugins/oas31/components/models.jsx b/src/core/plugins/oas31/components/models.jsx
index b3d65b74..8129cd71 100644
--- a/src/core/plugins/oas31/components/models.jsx
+++ b/src/core/plugins/oas31/components/models.jsx
@@ -15,6 +15,7 @@ const Models = ({
fn,
}) => {
const schemas = specSelectors.selectSchemas()
+ const hasSchemas = Object.keys(schemas).length > 0
const schemasPath = ["components", "schemas"]
const { docExpansion, defaultModelsExpandDepth } = getConfigs()
const isOpenDefault = defaultModelsExpandDepth > 0 && docExpansion !== "none"
@@ -34,15 +35,19 @@ const Models = ({
/**
* Event handlers.
*/
+
const handleCollapse = useCallback(() => {
layoutActions.show(schemasPath, !isOpen)
- }, [layoutActions, schemasPath, isOpen])
+ }, [isOpen, layoutActions])
- const handleModelsRef = useCallback((node) => {
- if (node !== null) {
- layoutActions.readyToScroll(schemasPath, node)
- }
- }, [])
+ const handleModelsRef = useCallback(
+ (node) => {
+ if (node !== null) {
+ layoutActions.readyToScroll(schemasPath, node)
+ }
+ },
+ [layoutActions]
+ )
const handleJSONSchema202012Ref = (schemaName) => (node) => {
if (node !== null) {
@@ -50,6 +55,14 @@ const Models = ({
}
}
+ /**
+ * Rendering.
+ */
+
+ if (!hasSchemas || defaultModelsExpandDepth < 0) {
+ return null
+ }
+
return (
{
- const { getComponent, fn } = getSystem()
+ const { getComponent, fn, getConfigs } = getSystem()
+ const configs = getConfigs()
if (ModelsWrapper.ModelsWithJSONContext) {
return
@@ -61,7 +62,6 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
"JSONSchema202012KeywordDescription",
true
)
-
const Accordion = getComponent("JSONSchema202012Accordion")
const ExpandDeepButton = getComponent("JSONSchema202012ExpandDeepButton")
const ChevronRightIcon = getComponent("JSONSchema202012ChevronRightIcon")
@@ -70,6 +70,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
ModelsWrapper.ModelsWithJSONContext = withSchemaContext(Models, {
config: {
default$schema: "https://spec.openapis.org/oas/3.1/dialect/base",
+ defaultExpandedLevels: configs.defaultModelsExpandDepth - 1,
},
components: {
JSONSchema,