diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/PatternProperties/PatternProperties.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/PatternProperties/PatternProperties.jsx
index 5c10c656..d874cadb 100644
--- a/src/core/plugins/json-schema-2020-12/components/keywords/PatternProperties/PatternProperties.jsx
+++ b/src/core/plugins/json-schema-2020-12/components/keywords/PatternProperties/PatternProperties.jsx
@@ -21,10 +21,7 @@ const PatternProperties = ({ schema }) => {
{Object.entries(patternProperties).map(([propertyName, schema]) => (
- -
+
-
))}
diff --git a/src/core/plugins/json-schema-2020-12/index.js b/src/core/plugins/json-schema-2020-12/index.js
index fc4f8609..816357e3 100644
--- a/src/core/plugins/json-schema-2020-12/index.js
+++ b/src/core/plugins/json-schema-2020-12/index.js
@@ -45,7 +45,7 @@ import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton"
import ChevronRightIcon from "./components/icons/ChevronRight"
import { upperFirst, hasKeyword, isExpandable } from "./fn"
import { JSONSchemaDeepExpansionContext } from "./context"
-import { useFn, useComponent, useIsExpandedDeeply } from "./hooks"
+import { useFn, useConfig, useComponent, useIsExpandedDeeply } from "./hooks"
import { withJSONSchemaContext } from "./hoc"
const JSONSchema202012Plugin = () => ({
@@ -101,6 +101,7 @@ const JSONSchema202012Plugin = () => ({
isExpandable,
hasKeyword,
useFn,
+ useConfig,
useComponent,
useIsExpandedDeeply,
},
diff --git a/src/core/plugins/oas31/index.js b/src/core/plugins/oas31/index.js
index b3e18b65..8aa25421 100644
--- a/src/core/plugins/oas31/index.js
+++ b/src/core/plugins/oas31/index.js
@@ -58,7 +58,11 @@ import JSONSchema202012KeywordDiscriminator from "./json-schema-2020-12-extensio
import JSONSchema202012KeywordExternalDocs from "./json-schema-2020-12-extensions/components/keywords/ExternalDocs"
import JSONSchema202012KeywordDescriptionWrapper from "./json-schema-2020-12-extensions/wrap-components/keywords/Description"
import JSONSchema202012KeywordDefaultWrapper from "./json-schema-2020-12-extensions/wrap-components/keywords/Default"
-import { makeIsExpandable } from "./json-schema-2020-12-extensions/fn"
+import JSONSchema202012KeywordPropertiesWrapper from "./json-schema-2020-12-extensions/wrap-components/keywords/Properties"
+import {
+ makeIsExpandable,
+ getProperties,
+} from "./json-schema-2020-12-extensions/fn"
const OAS31Plugin = ({ getSystem }) => {
const system = getSystem()
@@ -75,6 +79,7 @@ const OAS31Plugin = ({ getSystem }) => {
pluginFn.jsonSchema202012 = {
...fn.jsonSchema202012,
isExpandable: makeIsExpandable(fn.jsonSchema202012.isExpandable, system),
+ getProperties,
}
}
@@ -105,6 +110,8 @@ const OAS31Plugin = ({ getSystem }) => {
JSONSchema202012KeywordDescription:
JSONSchema202012KeywordDescriptionWrapper,
JSONSchema202012KeywordDefault: JSONSchema202012KeywordDefaultWrapper,
+ JSONSchema202012KeywordProperties:
+ JSONSchema202012KeywordPropertiesWrapper,
},
statePlugins: {
spec: {
diff --git a/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Properties.jsx b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Properties.jsx
new file mode 100644
index 00000000..09edb965
--- /dev/null
+++ b/src/core/plugins/oas31/json-schema-2020-12-extensions/components/keywords/Properties.jsx
@@ -0,0 +1,56 @@
+/**
+ * @prettier
+ */
+import React from "react"
+import PropTypes from "prop-types"
+import classNames from "classnames"
+
+const Properties = ({ schema, getSystem }) => {
+ const { fn } = getSystem()
+ const { useComponent } = fn.jsonSchema202012
+ const { getDependentRequired, getProperties } = fn.jsonSchema202012.useFn()
+ const config = fn.jsonSchema202012.useConfig()
+ const required = Array.isArray(schema?.required) ? schema.required : []
+ const JSONSchema = useComponent("JSONSchema")
+ const properties = getProperties(schema, config)
+
+ /**
+ * Rendering.
+ */
+ if (Object.keys(properties).length === 0) {
+ return null
+ }
+
+ return (
+
+
+ {Object.entries(properties).map(([propertyName, propertySchema]) => {
+ const isRequired = required.includes(propertyName)
+ const dependentRequired = getDependentRequired(propertyName, schema)
+
+ return (
+ -
+
+
+ )
+ })}
+
+
+ )
+}
+
+Properties.propTypes = {
+ schema: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]).isRequired,
+ getSystem: PropTypes.func.isRequired,
+}
+
+export default Properties
diff --git a/src/core/plugins/oas31/json-schema-2020-12-extensions/fn.js b/src/core/plugins/oas31/json-schema-2020-12-extensions/fn.js
index 7d9b0cfd..d13466de 100644
--- a/src/core/plugins/oas31/json-schema-2020-12-extensions/fn.js
+++ b/src/core/plugins/oas31/json-schema-2020-12-extensions/fn.js
@@ -15,3 +15,23 @@ export const makeIsExpandable = (original, { fn }) => {
schema?.discriminator ||
schema?.externalDocs
}
+
+export const getProperties = (
+ schema,
+ { includeReadOnly, includeWriteOnly }
+) => {
+ // shortcut
+ if (!schema?.properties) return {}
+
+ const properties = Object.entries(schema.properties)
+ const filteredProperties = properties.filter(([, value]) => {
+ const isReadOnly = value?.readOnly === true
+ const isWriteOnly = value?.writeOnly === true
+
+ return (
+ (!isReadOnly || includeReadOnly) && (!isWriteOnly || includeWriteOnly)
+ )
+ })
+
+ return Object.fromEntries(filteredProperties)
+}
diff --git a/src/core/plugins/oas31/json-schema-2020-12-extensions/wrap-components/keywords/Properties.jsx b/src/core/plugins/oas31/json-schema-2020-12-extensions/wrap-components/keywords/Properties.jsx
new file mode 100644
index 00000000..2c11ddcb
--- /dev/null
+++ b/src/core/plugins/oas31/json-schema-2020-12-extensions/wrap-components/keywords/Properties.jsx
@@ -0,0 +1,9 @@
+/**
+ * @prettier
+ */
+import PropertiesKeyword from "../../components/keywords/Properties"
+import { createOnlyOAS31ComponentWrapper } from "../../../fn"
+
+const PropertiesWrapper = createOnlyOAS31ComponentWrapper(PropertiesKeyword)
+
+export default PropertiesWrapper
diff --git a/src/core/plugins/oas31/wrap-components/model.jsx b/src/core/plugins/oas31/wrap-components/model.jsx
index c720bd1f..1e990fde 100644
--- a/src/core/plugins/oas31/wrap-components/model.jsx
+++ b/src/core/plugins/oas31/wrap-components/model.jsx
@@ -4,7 +4,10 @@
import React from "react"
import { createOnlyOAS31ComponentWrapper } from "../fn"
-import { makeIsExpandable } from "../json-schema-2020-12-extensions/fn"
+import {
+ makeIsExpandable,
+ getProperties,
+} from "../json-schema-2020-12-extensions/fn"
const ModelWrapper = createOnlyOAS31ComponentWrapper(
({ getSystem, ...props }) => {
@@ -140,6 +143,7 @@ const ModelWrapper = createOnlyOAS31ComponentWrapper(
fn.jsonSchema202012.isExpandable,
system
),
+ getProperties,
},
})
diff --git a/src/core/plugins/oas31/wrap-components/models.jsx b/src/core/plugins/oas31/wrap-components/models.jsx
index 7d947219..824c523c 100644
--- a/src/core/plugins/oas31/wrap-components/models.jsx
+++ b/src/core/plugins/oas31/wrap-components/models.jsx
@@ -4,7 +4,10 @@
import React from "react"
import { createOnlyOAS31ComponentWrapper } from "../fn"
-import { makeIsExpandable } from "../json-schema-2020-12-extensions/fn"
+import {
+ makeIsExpandable,
+ getProperties,
+} from "../json-schema-2020-12-extensions/fn"
const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
const system = getSystem()
@@ -83,6 +86,8 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
config: {
default$schema: "https://spec.openapis.org/oas/3.1/dialect/base",
defaultExpandedLevels: configs.defaultModelsExpandDepth - 1,
+ includeReadOnly: true,
+ includeWriteOnly: true,
},
components: {
JSONSchema,
@@ -131,6 +136,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
fn: {
upperFirst: fn.upperFirst,
isExpandable: makeIsExpandable(fn.jsonSchema202012.isExpandable, system),
+ getProperties,
},
})