From b7a402398f0860a1f33bb3b1c98a0ac45c5d0167 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Fri, 21 Apr 2023 13:17:08 +0200 Subject: [PATCH] feat(json-schema-2020-12): add support for then keyword Refs #8513 --- .../components/JSONSchema/JSONSchema.jsx | 2 ++ .../json-schema-2020-12/components/_all.scss | 1 + .../components/keywords/Then/Then.jsx | 30 +++++++++++++++++++ .../components/keywords/Then/_then.scss | 10 +++++++ src/core/plugins/json-schema-2020-12/fn.js | 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 ++ 8 files changed, 50 insertions(+) create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/Then/Then.jsx create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/Then/_then.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 1a31214b..e5eb288d 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 @@ -46,6 +46,7 @@ const JSONSchema = ({ schema, name }) => { const KeywordOneOf = useComponent("KeywordOneOf") const KeywordNot = useComponent("KeywordNot") const KeywordIf = useComponent("KeywordIf") + const KeywordThen = useComponent("KeywordThen") const KeywordProperties = useComponent("KeywordProperties") const KeywordType = useComponent("KeywordType") const KeywordFormat = useComponent("KeywordFormat") @@ -115,6 +116,7 @@ const JSONSchema = ({ schema, name }) => { + 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 38797636..0c613de4 100644 --- a/src/core/plugins/json-schema-2020-12/components/_all.scss +++ b/src/core/plugins/json-schema-2020-12/components/_all.scss @@ -13,6 +13,7 @@ @import './keywords/OneOf/one-of'; @import './keywords/Not/not'; @import './keywords/If/if'; +@import './keywords/Then/then'; @import './keywords/Type/type'; @import './keywords/Format/format'; @import './keywords/Description/description'; diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Then/Then.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/Then/Then.jsx new file mode 100644 index 00000000..5ae714fd --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/Then/Then.jsx @@ -0,0 +1,30 @@ +/** + * @prettier + */ +import React from "react" + +import { schema } from "../../../prop-types" +import { useComponent } from "../../../hooks" + +const Then = ({ schema }) => { + if (!schema?.then) return null + + const JSONSchema = useComponent("JSONSchema") + const name = ( + + Then + + ) + + return ( +
+ +
+ ) +} + +Then.propTypes = { + schema: schema.isRequired, +} + +export default Then diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Then/_then.scss b/src/core/plugins/json-schema-2020-12/components/keywords/Then/_then.scss new file mode 100644 index 00000000..4acd067c --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/Then/_then.scss @@ -0,0 +1,10 @@ +.json-schema-2020-12 { + &__then { + .json-schema-2020-12-core-keyword--then { + @extend .json-schema-2020-12-core-keyword--allOf; + } + } +} + + + diff --git a/src/core/plugins/json-schema-2020-12/fn.js b/src/core/plugins/json-schema-2020-12/fn.js index 7cf1f40c..4a1264b6 100644 --- a/src/core/plugins/json-schema-2020-12/fn.js +++ b/src/core/plugins/json-schema-2020-12/fn.js @@ -131,6 +131,7 @@ export const isExpandable = (schema) => { schema?.oneOf || schema?.not || schema?.if || + schema?.then || schema?.description || schema?.properties ) diff --git a/src/core/plugins/json-schema-2020-12/hoc.jsx b/src/core/plugins/json-schema-2020-12/hoc.jsx index d8479e5b..d926d8aa 100644 --- a/src/core/plugins/json-schema-2020-12/hoc.jsx +++ b/src/core/plugins/json-schema-2020-12/hoc.jsx @@ -18,6 +18,7 @@ import KeywordAnyOf from "./components/keywords/AnyOf/AnyOf" import KeywordOneOf from "./components/keywords/OneOf/OneOf" import KeywordNot from "./components/keywords/Not/Not" import KeywordIf from "./components/keywords/If/If" +import KeywordThen from "./components/keywords/Then/Then" import KeywordProperties from "./components/keywords/Properties/Properties" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" @@ -53,6 +54,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => { KeywordOneOf, KeywordNot, KeywordIf, + KeywordThen, KeywordProperties, KeywordType, KeywordFormat, diff --git a/src/core/plugins/json-schema-2020-12/index.js b/src/core/plugins/json-schema-2020-12/index.js index bb534c92..6caa674d 100644 --- a/src/core/plugins/json-schema-2020-12/index.js +++ b/src/core/plugins/json-schema-2020-12/index.js @@ -17,6 +17,7 @@ import KeywordAnyOf from "./components/keywords/AnyOf/AnyOf" import KeywordOneOf from "./components/keywords/OneOf/OneOf" import KeywordNot from "./components/keywords/Not/Not" import KeywordIf from "./components/keywords/If/If" +import KeywordThen from "./components/keywords/Then/Then" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" import KeywordTitle from "./components/keywords/Title/Title" @@ -44,6 +45,7 @@ const JSONSchema202012Plugin = () => ({ JSONSchema202012KeywordOneOf: KeywordOneOf, JSONSchema202012KeywordNot: KeywordNot, JSONSchema202012KeywordIf: KeywordIf, + JSONSchema202012KeywordThen: KeywordThen, JSONSchema202012KeywordProperties: KeywordProperties, JSONSchema202012KeywordType: KeywordType, JSONSchema202012KeywordFormat: KeywordFormat, diff --git a/src/core/plugins/oas31/wrap-components/models.jsx b/src/core/plugins/oas31/wrap-components/models.jsx index d9d9203b..7388221a 100644 --- a/src/core/plugins/oas31/wrap-components/models.jsx +++ b/src/core/plugins/oas31/wrap-components/models.jsx @@ -25,6 +25,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { const KeywordOneOf = getComponent("JSONSchema202012KeywordOneOf") const KeywordNot = getComponent("JSONSchema202012KeywordNot") const KeywordIf = getComponent("JSONSchema202012KeywordIf") + const KeywordThen = getComponent("JSONSchema202012KeywordThen") const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") const KeywordType = getComponent("JSONSchema202012KeywordType") const KeywordFormat = getComponent("JSONSchema202012KeywordFormat") @@ -58,6 +59,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { KeywordOneOf, KeywordNot, KeywordIf, + KeywordThen, KeywordProperties, KeywordType, KeywordFormat,