From 1f1f045b2bc537fa19c74e896414553d5a91fb7b Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Mon, 24 Apr 2023 13:58:54 +0200 Subject: [PATCH] feat(json-schema-2020-12): add support for items keyword Refs #8513 --- .../components/JSONSchema/JSONSchema.jsx | 2 ++ .../components/keywords/Items.jsx | 30 +++++++++++++++++++ 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 ++ 6 files changed, 39 insertions(+) create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/Items.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 eca28ea1..aa033d6d 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 @@ -50,6 +50,7 @@ const JSONSchema = ({ schema, name }) => { const KeywordElse = useComponent("KeywordElse") const KeywordDependentSchemas = useComponent("KeywordDependentSchemas") const KeywordPrefixItems = useComponent("KeywordPrefixItems") + const KeywordItems = useComponent("KeywordItems") const KeywordProperties = useComponent("KeywordProperties") const KeywordType = useComponent("KeywordType") const KeywordFormat = useComponent("KeywordFormat") @@ -123,6 +124,7 @@ const JSONSchema = ({ schema, name }) => { + diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/Items.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/Items.jsx new file mode 100644 index 00000000..2802e9dd --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/Items.jsx @@ -0,0 +1,30 @@ +/** + * @prettier + */ +import React from "react" + +import { schema } from "../../prop-types" +import { useComponent } from "../../hooks" + +const Items = ({ schema }) => { + if (!schema?.items) return null + + const JSONSchema = useComponent("JSONSchema") + const name = ( + + Items + + ) + + return ( +
+ +
+ ) +} + +Items.propTypes = { + schema: schema.isRequired, +} + +export default Items diff --git a/src/core/plugins/json-schema-2020-12/fn.js b/src/core/plugins/json-schema-2020-12/fn.js index 98be04eb..9db48181 100644 --- a/src/core/plugins/json-schema-2020-12/fn.js +++ b/src/core/plugins/json-schema-2020-12/fn.js @@ -142,6 +142,7 @@ export const isExpandable = (schema) => { schema?.else || schema?.dependentSchemas || schema?.prefixItems || + schema?.items || 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 16ef1ad4..cfafed6c 100644 --- a/src/core/plugins/json-schema-2020-12/hoc.jsx +++ b/src/core/plugins/json-schema-2020-12/hoc.jsx @@ -22,6 +22,7 @@ import KeywordThen from "./components/keywords/Then" import KeywordElse from "./components/keywords/Else" import KeywordDependentSchemas from "./components/keywords/DependentSchemas" import KeywordPrefixItems from "./components/keywords/PrefixItems" +import KeywordItems from "./components/keywords/Items" import KeywordProperties from "./components/keywords/Properties/Properties" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" @@ -61,6 +62,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => { KeywordElse, KeywordDependentSchemas, KeywordPrefixItems, + KeywordItems, 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 81f6110c..c107e602 100644 --- a/src/core/plugins/json-schema-2020-12/index.js +++ b/src/core/plugins/json-schema-2020-12/index.js @@ -21,6 +21,7 @@ import KeywordThen from "./components/keywords/Then" import KeywordElse from "./components/keywords/Else" import KeywordDependentSchemas from "./components/keywords/DependentSchemas" import KeywordPrefixItems from "./components/keywords/PrefixItems" +import KeywordItems from "./components/keywords/Items" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" import KeywordTitle from "./components/keywords/Title/Title" @@ -52,6 +53,7 @@ const JSONSchema202012Plugin = () => ({ JSONSchema202012KeywordElse: KeywordElse, JSONSchema202012KeywordDependentSchemas: KeywordDependentSchemas, JSONSchema202012KeywordPrefixItems: KeywordPrefixItems, + JSONSchema202012KeywordItems: KeywordItems, 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 a674d709..afe3fc00 100644 --- a/src/core/plugins/oas31/wrap-components/models.jsx +++ b/src/core/plugins/oas31/wrap-components/models.jsx @@ -31,6 +31,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { "JSONSchema202012KeywordDependentSchemas" ) const KeywordPrefixItems = getComponent("JSONSchema202012KeywordPrefixItems") + const KeywordItems = getComponent("JSONSchema202012KeywordItems") const KeywordProperties = getComponent("JSONSchema202012KeywordProperties") const KeywordType = getComponent("JSONSchema202012KeywordType") const KeywordFormat = getComponent("JSONSchema202012KeywordFormat") @@ -68,6 +69,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { KeywordElse, KeywordDependentSchemas, KeywordPrefixItems, + KeywordItems, KeywordProperties, KeywordType, KeywordFormat,