From a7efbf5b19e6ec1237cfc8942725f51880038d7e Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Fri, 14 Apr 2023 15:02:01 +0200 Subject: [PATCH] feat(json-schema-2020-12): add support for description keyword Refs #8513 --- .../components/JSONSchema/JSONSchema.jsx | 2 ++ .../components/JSONSchema/_json-schema.scss | 5 ----- .../json-schema-2020-12/components/_all.scss | 1 + .../keywords/Description/Description.jsx | 20 +++++++++++++++++++ .../keywords/Description/_description.scss | 5 +++++ src/core/plugins/json-schema-2020-12/hoc.jsx | 2 ++ src/core/plugins/json-schema-2020-12/index.js | 2 ++ src/core/plugins/oas31/index.js | 3 +++ ...son-schema-2020-12-keyword-description.jsx | 20 +++++++++++++++++++ .../plugins/oas31/wrap-components/models.jsx | 5 +++++ src/core/presets/apis.js | 2 +- 11 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/Description/Description.jsx create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/Description/_description.scss create mode 100644 src/core/plugins/oas31/wrap-components/json-schema-2020-12-keyword-description.jsx 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 16ea51fb..5578fb1f 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 @@ -30,6 +30,7 @@ const JSONSchema = ({ schema, name }) => { const KeywordProperties = useComponent("KeywordProperties") const KeywordType = useComponent("KeywordType") const KeywordFormat = useComponent("KeywordFormat") + const KeywordDescription = useComponent("KeywordDescription") const ExpandDeepButton = useComponent("ExpandDeepButton") /** @@ -85,6 +86,7 @@ const JSONSchema = ({ schema, name }) => { {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 a9024932..e5283ada 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 @@ -38,11 +38,6 @@ } } - &__description { - color: #6b6b6b; - font-size: 12px; - } - &__limit { @include text_code(); margin-left: 10px; diff --git a/src/core/plugins/json-schema-2020-12/components/_all.scss b/src/core/plugins/json-schema-2020-12/components/_all.scss index c04c48e9..01f07e9d 100644 --- a/src/core/plugins/json-schema-2020-12/components/_all.scss +++ b/src/core/plugins/json-schema-2020-12/components/_all.scss @@ -4,3 +4,4 @@ @import './ExpandDeepButton/expand-deep-button'; @import './keywords/Type/type'; @import './keywords/Format/format'; +@import './keywords/Description/description'; diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Description/Description.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/Description/Description.jsx new file mode 100644 index 00000000..0ca3c920 --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/Description/Description.jsx @@ -0,0 +1,20 @@ +/** + * @prettier + */ +import React from "react" + +import { schema } from "../../../prop-types" + +const Description = ({ schema }) => { + if (!schema.description) return null + + return ( +
{schema.description}
+ ) +} + +Description.propTypes = { + schema: schema.isRequired, +} + +export default Description diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Description/_description.scss b/src/core/plugins/json-schema-2020-12/components/keywords/Description/_description.scss new file mode 100644 index 00000000..291e1663 --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/Description/_description.scss @@ -0,0 +1,5 @@ +.json-schema-2020-12__description { + color: #6b6b6b; + font-size: 12px; + margin-left: 20px; +} diff --git a/src/core/plugins/json-schema-2020-12/hoc.jsx b/src/core/plugins/json-schema-2020-12/hoc.jsx index 5f8c897b..1cd02519 100644 --- a/src/core/plugins/json-schema-2020-12/hoc.jsx +++ b/src/core/plugins/json-schema-2020-12/hoc.jsx @@ -8,6 +8,7 @@ import BooleanJSONSchema from "./components/BooleanJSONSchema/BooleanJSONSchema" import KeywordProperties from "./components/keywords/Properties" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" +import KeywordDescription from "./components/keywords/Description/Description" import Accordion from "./components/Accordion/Accordion" import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton" import ChevronRightIcon from "./components/icons/ChevronRight" @@ -22,6 +23,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => { KeywordProperties, KeywordType, KeywordFormat, + KeywordDescription, 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 cb33bff4..e614eb1a 100644 --- a/src/core/plugins/json-schema-2020-12/index.js +++ b/src/core/plugins/json-schema-2020-12/index.js @@ -6,6 +6,7 @@ import BooleanJSONSchema from "./components/BooleanJSONSchema/BooleanJSONSchema" import KeywordProperties from "./components/keywords/Properties" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" +import KeywordDescription from "./components/keywords/Description/Description" import Accordion from "./components/Accordion/Accordion" import ExpandDeepButton from "./components/ExpandDeepButton/ExpandDeepButton" import ChevronRightIcon from "./components/icons/ChevronRight" @@ -19,6 +20,7 @@ const JSONSchema202012Plugin = () => ({ JSONSchema202012KeywordProperties: KeywordProperties, JSONSchema202012KeywordType: KeywordType, JSONSchema202012KeywordFormat: KeywordFormat, + JSONSchema202012KeywordDescription: KeywordDescription, JSONSchema202012Accordion: Accordion, JSONSchema202012ExpandDeepButton: ExpandDeepButton, JSONSchema202012ChevronRightIcon: ChevronRightIcon, diff --git a/src/core/plugins/oas31/index.js b/src/core/plugins/oas31/index.js index 0a1dd76d..f20e30a6 100644 --- a/src/core/plugins/oas31/index.js +++ b/src/core/plugins/oas31/index.js @@ -14,6 +14,7 @@ import InfoWrapper from "./wrap-components/info" import ModelsWrapper from "./wrap-components/models" import VersionPragmaFilterWrapper from "./wrap-components/version-pragma-filter" import VersionStampWrapper from "./wrap-components/version-stamp" +import JSONSchema202012KeywordDescriptionWrapper from "./wrap-components/json-schema-2020-12-keyword-description" import { license as selectLicense, contact as selectContact, @@ -77,6 +78,8 @@ const OAS31Plugin = ({ fn }) => { VersionPragmaFilter: VersionPragmaFilterWrapper, VersionStamp: VersionStampWrapper, Models: ModelsWrapper, + JSONSchema202012KeywordDescription: + JSONSchema202012KeywordDescriptionWrapper, }, statePlugins: { spec: { diff --git a/src/core/plugins/oas31/wrap-components/json-schema-2020-12-keyword-description.jsx b/src/core/plugins/oas31/wrap-components/json-schema-2020-12-keyword-description.jsx new file mode 100644 index 00000000..b16d41df --- /dev/null +++ b/src/core/plugins/oas31/wrap-components/json-schema-2020-12-keyword-description.jsx @@ -0,0 +1,20 @@ +/** + * @prettier + */ +import React from "react" +import { createOnlyOAS31ComponentWrapper } from "../fn" + +const JSONSchema202012KeywordDescriptionWrapper = + createOnlyOAS31ComponentWrapper(({ schema, getComponent }) => { + if (!schema.description) return null + + const MarkDown = getComponent("Markdown") + + return ( +
+ +
+ ) + }) + +export default JSONSchema202012KeywordDescriptionWrapper diff --git a/src/core/plugins/oas31/wrap-components/models.jsx b/src/core/plugins/oas31/wrap-components/models.jsx index 2f1dcbfe..2338882d 100644 --- a/src/core/plugins/oas31/wrap-components/models.jsx +++ b/src/core/plugins/oas31/wrap-components/models.jsx @@ -13,6 +13,10 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") const KeywordType = getComponent("JSONSchema202012KeywordType") const KeywordFormat = getComponent("JSONSchema202012KeywordFormat") + const KeywordDescription = getComponent( + "JSONSchema202012KeywordDescription", + true + ) const Accordion = getComponent("JSONSchema202012Accordion") const ExpandDeepButton = getComponent("JSONSchema202012ExpandDeepButton") const ChevronRightIcon = getComponent("JSONSchema202012ChevronRightIcon") @@ -27,6 +31,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { KeywordProperties, KeywordType, KeywordFormat, + KeywordDescription, Accordion, ExpandDeepButton, ChevronRightIcon, diff --git a/src/core/presets/apis.js b/src/core/presets/apis.js index 9df199e1..4498aee5 100644 --- a/src/core/presets/apis.js +++ b/src/core/presets/apis.js @@ -7,5 +7,5 @@ import OAS31Plugin from "../plugins/oas31" import JSONSchema202012Plugin from "../plugins/json-schema-2020-12" export default function PresetApis() { - return [BasePreset, OAS3Plugin, OAS31Plugin, JSONSchema202012Plugin] + return [BasePreset, OAS3Plugin, JSONSchema202012Plugin, OAS31Plugin] }