From 5d0bc24ec97b49e4278c928af89c2ab47555ff9e Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Thu, 11 May 2023 09:52:39 +0200 Subject: [PATCH] feat(json-schema-2020-12): add support for writeOnly keyword Refs #8513 --- .../components/JSONSchema/JSONSchema.jsx | 2 ++ .../components/keywords/ReadOnly/ReadOnly.jsx | 2 +- .../keywords/ReadOnly/_read-only.scss | 2 +- .../keywords/WriteOnly/WriteOnly.jsx | 18 ++++++++++++++++++ .../keywords/WriteOnly/_write-only.scss | 5 +++++ .../components/keywords/_all.scss | 1 + src/core/plugins/json-schema-2020-12/hoc.jsx | 2 ++ src/core/plugins/json-schema-2020-12/index.js | 2 ++ .../plugins/oas31/wrap-components/models.jsx | 2 ++ 9 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/WriteOnly/WriteOnly.jsx create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/WriteOnly/_write-only.scss diff --git a/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx b/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx index 6f3037f6b99..40883087a04 100644 --- a/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx +++ b/src/core/plugins/json-schema-2020-12/components/JSONSchema/JSONSchema.jsx @@ -75,6 +75,7 @@ const JSONSchema = forwardRef( const KeywordDefault = useComponent("KeywordDefault") const KeywordDeprecated = useComponent("KeywordDeprecated") const KeywordReadOnly = useComponent("KeywordReadOnly") + const KeywordWriteOnly = useComponent("KeywordWriteOnly") const ExpandDeepButton = useComponent("ExpandDeepButton") /** @@ -136,6 +137,7 @@ const JSONSchema = forwardRef( )} + {constraints.length > 0 && constraints.map((constraint) => ( diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/ReadOnly/ReadOnly.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/ReadOnly/ReadOnly.jsx index ca970618e3e..92118a01346 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/ReadOnly/ReadOnly.jsx +++ b/src/core/plugins/json-schema-2020-12/components/keywords/ReadOnly/ReadOnly.jsx @@ -8,7 +8,7 @@ import { schema } from "../../../prop-types" const ReadOnly = ({ schema }) => { if (schema?.readOnly !== true) return null - return read-only + return read-only } ReadOnly.propTypes = { diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/ReadOnly/_read-only.scss b/src/core/plugins/json-schema-2020-12/components/keywords/ReadOnly/_read-only.scss index 36ce41ddc6a..aa4130c2b21 100644 --- a/src/core/plugins/json-schema-2020-12/components/keywords/ReadOnly/_read-only.scss +++ b/src/core/plugins/json-schema-2020-12/components/keywords/ReadOnly/_read-only.scss @@ -1,5 +1,5 @@ .json-schema-2020-12 { - &__readonly { + &__readOnly { @extend .json-schema-2020-12__deprecated; color: gray; } diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/WriteOnly/WriteOnly.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/WriteOnly/WriteOnly.jsx new file mode 100644 index 00000000000..bc5dd5685b0 --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/WriteOnly/WriteOnly.jsx @@ -0,0 +1,18 @@ +/** + * @prettier + */ +import React from "react" + +import { schema } from "../../../prop-types" + +const WriteOnly = ({ schema }) => { + if (schema?.writeOnly !== true) return null + + return write-only +} + +WriteOnly.propTypes = { + schema: schema.isRequired, +} + +export default WriteOnly diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/WriteOnly/_write-only.scss b/src/core/plugins/json-schema-2020-12/components/keywords/WriteOnly/_write-only.scss new file mode 100644 index 00000000000..461f2dbf3c5 --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/WriteOnly/_write-only.scss @@ -0,0 +1,5 @@ +.json-schema-2020-12 { + &__writeOnly { + @extend .json-schema-2020-12__readOnly; + } +} 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 529f5912e27..78aa7094abc 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 @@ -76,3 +76,4 @@ @import './DependentRequired/dependent-required'; @import './Deprecated/deprecated'; @import './ReadOnly/read-only'; +@import './WriteOnly/write-only'; diff --git a/src/core/plugins/json-schema-2020-12/hoc.jsx b/src/core/plugins/json-schema-2020-12/hoc.jsx index fca017b87d1..cfd4d73b506 100644 --- a/src/core/plugins/json-schema-2020-12/hoc.jsx +++ b/src/core/plugins/json-schema-2020-12/hoc.jsx @@ -41,6 +41,7 @@ import KeywordDescription from "./components/keywords/Description/Description" import KeywordDefault from "./components/keywords/Default" import KeywordDeprecated from "./components/keywords/Deprecated/Deprecated" import KeywordReadOnly from "./components/keywords/ReadOnly/ReadOnly" +import KeywordWriteOnly from "./components/keywords/WriteOnly/WriteOnly" import Accordion from "./components/Accordion/Accordion" import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton" import ChevronRightIcon from "./components/icons/ChevronRight" @@ -98,6 +99,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => { KeywordDefault, KeywordDeprecated, KeywordReadOnly, + KeywordWriteOnly, Accordion, ExpandDeepButton, ChevronRightIcon, diff --git a/src/core/plugins/json-schema-2020-12/index.js b/src/core/plugins/json-schema-2020-12/index.js index 3860ed71e83..983eacc1d0b 100644 --- a/src/core/plugins/json-schema-2020-12/index.js +++ b/src/core/plugins/json-schema-2020-12/index.js @@ -39,6 +39,7 @@ import KeywordDescription from "./components/keywords/Description/Description" import KeywordDefault from "./components/keywords/Default" import KeywordDeprecated from "./components/keywords/Deprecated/Deprecated" import KeywordReadOnly from "./components/keywords/ReadOnly/ReadOnly" +import KeywordWriteOnly from "./components/keywords/WriteOnly/WriteOnly" import Accordion from "./components/Accordion/Accordion" import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton" import ChevronRightIcon from "./components/icons/ChevronRight" @@ -85,6 +86,7 @@ const JSONSchema202012Plugin = () => ({ JSONSchema202012KeywordDefault: KeywordDefault, JSONSchema202012KeywordDeprecated: KeywordDeprecated, JSONSchema202012KeywordReadOnly: KeywordReadOnly, + JSONSchema202012KeywordWriteOnly: KeywordWriteOnly, JSONSchema202012Accordion: Accordion, JSONSchema202012ExpandDeepButton: ExpandDeepButton, JSONSchema202012ChevronRightIcon: ChevronRightIcon, diff --git a/src/core/plugins/oas31/wrap-components/models.jsx b/src/core/plugins/oas31/wrap-components/models.jsx index 21cff9e53a9..df318e80e5f 100644 --- a/src/core/plugins/oas31/wrap-components/models.jsx +++ b/src/core/plugins/oas31/wrap-components/models.jsx @@ -73,6 +73,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { const KeywordDefault = getComponent("JSONSchema202012KeywordDefault") const KeywordDeprecated = getComponent("JSONSchema202012KeywordDeprecated") const KeywordReadOnly = getComponent("JSONSchema202012KeywordReadOnly") + const KeywordWriteOnly = getComponent("JSONSchema202012KeywordWriteOnly") const Accordion = getComponent("JSONSchema202012Accordion") const ExpandDeepButton = getComponent("JSONSchema202012ExpandDeepButton") const ChevronRightIcon = getComponent("JSONSchema202012ChevronRightIcon") @@ -122,6 +123,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { KeywordDefault, KeywordDeprecated, KeywordReadOnly, + KeywordWriteOnly, Accordion, ExpandDeepButton, ChevronRightIcon,