From aba7f986add6cd36189e9cc8bc156f40a3b09a06 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Tue, 25 Apr 2023 08:04:43 +0200 Subject: [PATCH] feat(json-schema-2020-12): add support for unevaluatedItems keyword Refs #8513 --- .../components/JSONSchema/JSONSchema.jsx | 2 ++ .../components/keywords/UnevaluatedItems.jsx | 33 +++++++++++++++++++ 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 | 4 +++ 6 files changed, 44 insertions(+) create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.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 f7ab8a8d..8bff5550 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 @@ -58,6 +58,7 @@ const JSONSchema = ({ schema, name }) => { "KeywordAdditionalProperties" ) const KeywordPropertyNames = useComponent("KeywordPropertyNames") + const KeywordUnevaluatedItems = useComponent("KeywordUnevaluatedItems") const KeywordType = useComponent("KeywordType") const KeywordFormat = useComponent("KeywordFormat") const KeywordTitle = useComponent("KeywordTitle") @@ -134,6 +135,7 @@ const JSONSchema = ({ schema, name }) => { + )} diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx new file mode 100644 index 00000000..4c145d57 --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedItems.jsx @@ -0,0 +1,33 @@ +/** + * @prettier + */ +import React from "react" + +import { schema } from "../../prop-types" +import { useFn, useComponent } from "../../hooks" + +const UnevaluatedItems = ({ schema }) => { + const fn = useFn() + + if (!fn.hasKeyword(schema, "unevaluatedItems")) return null + + const { unevaluatedItems } = schema + const JSONSchema = useComponent("JSONSchema") + const name = ( + + Unevaluated items + + ) + + return ( +
+ +
+ ) +} + +UnevaluatedItems.propTypes = { + schema: schema.isRequired, +} + +export default UnevaluatedItems diff --git a/src/core/plugins/json-schema-2020-12/fn.js b/src/core/plugins/json-schema-2020-12/fn.js index 482f1de8..7faac713 100644 --- a/src/core/plugins/json-schema-2020-12/fn.js +++ b/src/core/plugins/json-schema-2020-12/fn.js @@ -157,6 +157,7 @@ export const isExpandable = (schema) => { schema?.patternProperties || fn.hasKeyword(schema, "additionalProperties") || fn.hasKeyword(schema, "propertyNames") || + fn.hasKeyword(schema, "unevaluatedItems") || schema?.description ) } diff --git a/src/core/plugins/json-schema-2020-12/hoc.jsx b/src/core/plugins/json-schema-2020-12/hoc.jsx index 112daa6c..3d8c6869 100644 --- a/src/core/plugins/json-schema-2020-12/hoc.jsx +++ b/src/core/plugins/json-schema-2020-12/hoc.jsx @@ -28,6 +28,7 @@ import KeywordProperties from "./components/keywords/Properties/Properties" import KeywordPatternProperties from "./components/keywords/PatternProperties/PatternProperties" import KeywordAdditionalProperties from "./components/keywords/AdditionalProperties" import KeywordPropertyNames from "./components/keywords/PropertyNames" +import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" import KeywordTitle from "./components/keywords/Title/Title" @@ -73,6 +74,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => { KeywordPatternProperties, KeywordAdditionalProperties, KeywordPropertyNames, + KeywordUnevaluatedItems, KeywordType, KeywordFormat, KeywordTitle, diff --git a/src/core/plugins/json-schema-2020-12/index.js b/src/core/plugins/json-schema-2020-12/index.js index b967fdc7..6bad464f 100644 --- a/src/core/plugins/json-schema-2020-12/index.js +++ b/src/core/plugins/json-schema-2020-12/index.js @@ -26,6 +26,7 @@ import KeywordProperties from "./components/keywords/Properties/Properties" import KeywordPatternProperties from "./components/keywords/PatternProperties/PatternProperties" import KeywordAdditionalProperties from "./components/keywords/AdditionalProperties" import KeywordPropertyNames from "./components/keywords/PropertyNames" +import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" import KeywordTitle from "./components/keywords/Title/Title" @@ -63,6 +64,7 @@ const JSONSchema202012Plugin = () => ({ JSONSchema202012KeywordPatternProperties: KeywordPatternProperties, JSONSchema202012KeywordAdditionalProperties: KeywordAdditionalProperties, JSONSchema202012KeywordPropertyNames: KeywordPropertyNames, + JSONSchema202012KeywordUnevaluatedItems: KeywordUnevaluatedItems, JSONSchema202012KeywordType: KeywordType, JSONSchema202012KeywordFormat: KeywordFormat, JSONSchema202012KeywordTitle: KeywordTitle, diff --git a/src/core/plugins/oas31/wrap-components/models.jsx b/src/core/plugins/oas31/wrap-components/models.jsx index 77e8c702..ad3fcea8 100644 --- a/src/core/plugins/oas31/wrap-components/models.jsx +++ b/src/core/plugins/oas31/wrap-components/models.jsx @@ -43,6 +43,9 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { const KeywordPropertyNames = getComponent( "JSONSchema202012KeywordPropertyNames" ) + const KeywordUnevaluatedItems = getComponent( + "JSONSchema202012KeywordUnevaluatedItems" + ) const KeywordType = getComponent("JSONSchema202012KeywordType") const KeywordFormat = getComponent("JSONSchema202012KeywordFormat") const KeywordTitle = getComponent("JSONSchema202012KeywordTitle") @@ -85,6 +88,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { KeywordPatternProperties, KeywordAdditionalProperties, KeywordPropertyNames, + KeywordUnevaluatedItems, KeywordType, KeywordFormat, KeywordTitle,