From dea5dbb10e4555383d4bb4aa653887c499451933 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Fri, 21 Apr 2023 13:10:09 +0200 Subject: [PATCH] feat(json-schema-2020-12): add support for if keyword Refs #8513 --- .../components/JSONSchema/JSONSchema.jsx | 2 ++ .../json-schema-2020-12/components/_all.scss | 1 + .../components/keywords/If/If.jsx | 30 +++++++++++++++++++ .../components/keywords/If/_if.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/If/If.jsx create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/If/_if.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 47cc8189..1a31214b 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 @@ -45,6 +45,7 @@ const JSONSchema = ({ schema, name }) => { const KeywordAnyOf = useComponent("KeywordAnyOf") const KeywordOneOf = useComponent("KeywordOneOf") const KeywordNot = useComponent("KeywordNot") + const KeywordIf = useComponent("KeywordIf") const KeywordProperties = useComponent("KeywordProperties") const KeywordType = useComponent("KeywordType") const KeywordFormat = useComponent("KeywordFormat") @@ -113,6 +114,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 84689518..38797636 100644 --- a/src/core/plugins/json-schema-2020-12/components/_all.scss +++ b/src/core/plugins/json-schema-2020-12/components/_all.scss @@ -12,6 +12,7 @@ @import './keywords/AnyOf/any-of'; @import './keywords/OneOf/one-of'; @import './keywords/Not/not'; +@import './keywords/If/if'; @import './keywords/Type/type'; @import './keywords/Format/format'; @import './keywords/Description/description'; diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/If/If.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/If/If.jsx new file mode 100644 index 00000000..81ce6b61 --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/If/If.jsx @@ -0,0 +1,30 @@ +/** + * @prettier + */ +import React from "react" + +import { schema } from "../../../prop-types" +import { useComponent } from "../../../hooks" + +const If = ({ schema }) => { + if (!schema?.if) return null + + const JSONSchema = useComponent("JSONSchema") + const name = ( + + If + + ) + + return ( +
+ +
+ ) +} + +If.propTypes = { + schema: schema.isRequired, +} + +export default If diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/If/_if.scss b/src/core/plugins/json-schema-2020-12/components/keywords/If/_if.scss new file mode 100644 index 00000000..52a490be --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/If/_if.scss @@ -0,0 +1,10 @@ +.json-schema-2020-12 { + &__if { + .json-schema-2020-12-core-keyword--if { + @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 1b2ce4ed..7cf1f40c 100644 --- a/src/core/plugins/json-schema-2020-12/fn.js +++ b/src/core/plugins/json-schema-2020-12/fn.js @@ -130,6 +130,7 @@ export const isExpandable = (schema) => { schema?.anyOf || schema?.oneOf || schema?.not || + schema?.if || 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 8ee4b6f4..d8479e5b 100644 --- a/src/core/plugins/json-schema-2020-12/hoc.jsx +++ b/src/core/plugins/json-schema-2020-12/hoc.jsx @@ -17,6 +17,7 @@ import KeywordAllOf from "./components/keywords/AllOf/AllOf" 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 KeywordProperties from "./components/keywords/Properties/Properties" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" @@ -51,6 +52,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => { KeywordAnyOf, KeywordOneOf, KeywordNot, + KeywordIf, 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 20c6e659..bb534c92 100644 --- a/src/core/plugins/json-schema-2020-12/index.js +++ b/src/core/plugins/json-schema-2020-12/index.js @@ -16,6 +16,7 @@ import KeywordAllOf from "./components/keywords/AllOf/AllOf" 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 KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" import KeywordTitle from "./components/keywords/Title/Title" @@ -42,6 +43,7 @@ const JSONSchema202012Plugin = () => ({ JSONSchema202012KeywordAnyOf: KeywordAnyOf, JSONSchema202012KeywordOneOf: KeywordOneOf, JSONSchema202012KeywordNot: KeywordNot, + JSONSchema202012KeywordIf: KeywordIf, 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 864bb748..d9d9203b 100644 --- a/src/core/plugins/oas31/wrap-components/models.jsx +++ b/src/core/plugins/oas31/wrap-components/models.jsx @@ -24,6 +24,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { const KeywordAnyOf = getComponent("JSONSchema202012KeywordAnyOf") const KeywordOneOf = getComponent("JSONSchema202012KeywordOneOf") const KeywordNot = getComponent("JSONSchema202012KeywordNot") + const KeywordIf = getComponent("JSONSchema202012KeywordIf") const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") const KeywordType = getComponent("JSONSchema202012KeywordType") const KeywordFormat = getComponent("JSONSchema202012KeywordFormat") @@ -56,6 +57,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { KeywordAnyOf, KeywordOneOf, KeywordNot, + KeywordIf, KeywordProperties, KeywordType, KeywordFormat,