-
-
-
-
property1
-
Object
-
int64
-
[0...100]
-
- Whether to turn on or off the light.
-
-
-
-
-
-
-
- property11
-
- Object
-
-
-
-
-
-
-
- property22
-
- Object
-
-
-
-
- Additional properties are allowed.
-
-
-
-
-
-
-
- property2
- Object
-
-
-
-
-
-
- property3
- Object
-
-
-
-
- Additional properties are allowed.
-
+
+
+
+
+
+ {name || fn.getTitle(schema)}
+
+
- )}
-
+ {expanded && (
+
+
+
+ )}
+
+
)
}
diff --git a/src/core/plugins/json-schema-2020-12/components/JSONSchema/_json-schema.scss b/src/core/plugins/json-schema-2020-12/components/JSONSchema/_json-schema.scss
index 50b14085743..8e90484761a 100644
--- a/src/core/plugins/json-schema-2020-12/components/JSONSchema/_json-schema.scss
+++ b/src/core/plugins/json-schema-2020-12/components/JSONSchema/_json-schema.scss
@@ -19,6 +19,7 @@
&__title {
@include text_headline($section-models-model-title-font-color);
+ display: inline-block;
font-weight: bold;
}
@@ -31,8 +32,9 @@
margin: 7px 0;
.json-schema-2020-12__title {
- font-size: 12px;
@include text_code();
+ font-size: 12px;
+ vertical-align: bottom;
}
}
@@ -42,7 +44,6 @@
font-size: 12px;
text-transform: capitalize;
font-weight: bold;
- margin-left: 10px;
&:before {
content: "{";
diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Properties.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/Properties.jsx
new file mode 100644
index 00000000000..8112f72ae64
--- /dev/null
+++ b/src/core/plugins/json-schema-2020-12/components/keywords/Properties.jsx
@@ -0,0 +1,38 @@
+/**
+ * @prettier
+ */
+import React from "react"
+
+import { schema } from "../../prop-types"
+import { useFn, useComponent } from "../../hooks"
+
+const Properties = ({ schema }) => {
+ const fn = useFn()
+ const JSONSchema = useComponent("JSONSchema")
+
+ if (fn.isBooleanJSONSchema(schema)) {
+ return null
+ }
+
+ const properties = schema.properties || {}
+
+ if (Object.keys(properties).length === 0) {
+ return null
+ }
+
+ return (
+ <>
+ {Object.entries(properties).map(([propertyName, propertyValue]) => (
+
+
+
+ ))}
+ >
+ )
+}
+
+Properties.propTypes = {
+ schema: schema.isRequired,
+}
+
+export default Properties
diff --git a/src/core/plugins/json-schema-2020-12/context.js b/src/core/plugins/json-schema-2020-12/context.js
index 094f6d16d68..3d1bf85f30f 100644
--- a/src/core/plugins/json-schema-2020-12/context.js
+++ b/src/core/plugins/json-schema-2020-12/context.js
@@ -6,4 +6,5 @@ import { createContext } from "react"
export const JSONSchemaContext = createContext(null)
JSONSchemaContext.displayName = "JSONSchemaContext"
-export default JSONSchemaContext
+export const JSONSchemaLevelContext = createContext(0)
+JSONSchemaLevelContext.displayName = "JSONSchemaLevelContext"
diff --git a/src/core/plugins/json-schema-2020-12/hoc.jsx b/src/core/plugins/json-schema-2020-12/hoc.jsx
index 8d288e1cd3b..209430f72c1 100644
--- a/src/core/plugins/json-schema-2020-12/hoc.jsx
+++ b/src/core/plugins/json-schema-2020-12/hoc.jsx
@@ -5,9 +5,10 @@ import React from "react"
import JSONSchema from "./components/JSONSchema/JSONSchema"
import BooleanJSONSchema from "./components/BooleanJSONSchema/BooleanJSONSchema"
+import KeywordProperties from "./components/keywords/Properties"
import Accordion from "./components/Accordion/Accordion"
import ChevronRightIcon from "./components/icons/ChevronRight"
-import JSONSchemaContext from "./context"
+import { JSONSchemaContext } from "./context"
import { getTitle, isBooleanJSONSchema, upperFirst } from "./fn"
export const withJSONSchemaContext = (Component, overrides = {}) => {
@@ -15,6 +16,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => {
components: {
JSONSchema,
BooleanJSONSchema,
+ KeywordProperties,
Accordion,
ChevronRightIcon,
...overrides.components,
diff --git a/src/core/plugins/json-schema-2020-12/hooks.js b/src/core/plugins/json-schema-2020-12/hooks.js
index 8b26f066f40..afdd4c5cff8 100644
--- a/src/core/plugins/json-schema-2020-12/hooks.js
+++ b/src/core/plugins/json-schema-2020-12/hooks.js
@@ -3,7 +3,7 @@
*/
import { useContext } from "react"
-import JSONSchemaContext from "./context"
+import { JSONSchemaContext, JSONSchemaLevelContext } from "./context"
export const useConfig = () => {
const { config } = useContext(JSONSchemaContext)
@@ -20,3 +20,15 @@ export const useFn = (fnName = undefined) => {
return typeof fnName !== "undefined" ? fn[fnName] : fn
}
+
+export const useLevel = () => {
+ const level = useContext(JSONSchemaLevelContext)
+
+ return [level, level + 1]
+}
+
+export const useIsEmbedded = () => {
+ const [level] = useLevel()
+
+ return level > 0
+}
diff --git a/src/core/plugins/json-schema-2020-12/index.js b/src/core/plugins/json-schema-2020-12/index.js
index b76542d3042..212a07d002d 100644
--- a/src/core/plugins/json-schema-2020-12/index.js
+++ b/src/core/plugins/json-schema-2020-12/index.js
@@ -3,6 +3,7 @@
*/
import JSONSchema from "./components/JSONSchema/JSONSchema"
import BooleanJSONSchema from "./components/BooleanJSONSchema/BooleanJSONSchema"
+import JSONSchemaKeywordProperties from "./components/keywords/Properties"
import Accordion from "./components/Accordion/Accordion"
import ChevronRightIcon from "./components/icons/ChevronRight"
import { upperFirst } from "./fn"
@@ -12,6 +13,7 @@ const JSONSchema202012Plugin = () => ({
components: {
JSONSchema202012: JSONSchema,
BooleanJSONSchema202012: BooleanJSONSchema,
+ JSONSchema202012KeywordProperties: JSONSchemaKeywordProperties,
JSONSchema202012Accordion: Accordion,
JSONSchema202012ChevronRightIcon: ChevronRightIcon,
withJSONSchema202012Context: withJSONSchemaContext,
diff --git a/src/core/plugins/oas31/wrap-components/models.jsx b/src/core/plugins/oas31/wrap-components/models.jsx
index 84abe5c1e3f..a32d1f8fcc4 100644
--- a/src/core/plugins/oas31/wrap-components/models.jsx
+++ b/src/core/plugins/oas31/wrap-components/models.jsx
@@ -10,6 +10,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const Models = getComponent("OAS31Models", true)
const JSONSchema = getComponent("JSONSchema202012")
const BooleanJSONSchema = getComponent("BooleanJSONSchema202012")
+ const KeywordProperties = getComponent("JSONSchema202012KeywordProperties")
const Accordion = getComponent("JSONSchema202012Accordion")
const ChevronRightIcon = getComponent("JSONSchema202012ChevronRightIcon")
const withSchemaContext = getComponent("withJSONSchema202012Context")
@@ -20,6 +21,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
components: {
JSONSchema,
BooleanJSONSchema,
+ KeywordProperties,
Accordion,
ChevronRightIcon,
},