From 3a5a605c8ee159e4c0f8084e86c8a3c84e001e3a Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Tue, 25 Apr 2023 08:10:32 +0200 Subject: [PATCH] feat(json-schema-2020-12): add support for unevaluatedProperties Refs #8513 --- .../components/JSONSchema/JSONSchema.jsx | 4 +++ .../keywords/UnevaluatedProperties.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, 46 insertions(+) create mode 100644 src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.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 8bff5550d45..bf36fb7706f 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 @@ -59,6 +59,9 @@ const JSONSchema = ({ schema, name }) => { ) const KeywordPropertyNames = useComponent("KeywordPropertyNames") const KeywordUnevaluatedItems = useComponent("KeywordUnevaluatedItems") + const KeywordUnevaluatedProperties = useComponent( + "KeywordUnevaluatedProperties" + ) const KeywordType = useComponent("KeywordType") const KeywordFormat = useComponent("KeywordFormat") const KeywordTitle = useComponent("KeywordTitle") @@ -124,6 +127,7 @@ const JSONSchema = ({ schema, name }) => { + diff --git a/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx new file mode 100644 index 00000000000..e10efee39b4 --- /dev/null +++ b/src/core/plugins/json-schema-2020-12/components/keywords/UnevaluatedProperties.jsx @@ -0,0 +1,33 @@ +/** + * @prettier + */ +import React from "react" + +import { schema } from "../../prop-types" +import { useFn, useComponent } from "../../hooks" + +const UnevaluatedProperties = ({ schema }) => { + const fn = useFn() + + if (!fn.hasKeyword(schema, "unevaluatedProperties")) return null + + const { unevaluatedProperties } = schema + const JSONSchema = useComponent("JSONSchema") + const name = ( + + Unevaluated properties + + ) + + return ( +
+ +
+ ) +} + +UnevaluatedProperties.propTypes = { + schema: schema.isRequired, +} + +export default UnevaluatedProperties diff --git a/src/core/plugins/json-schema-2020-12/fn.js b/src/core/plugins/json-schema-2020-12/fn.js index 7faac713080..20dcf7fd863 100644 --- a/src/core/plugins/json-schema-2020-12/fn.js +++ b/src/core/plugins/json-schema-2020-12/fn.js @@ -158,6 +158,7 @@ export const isExpandable = (schema) => { fn.hasKeyword(schema, "additionalProperties") || fn.hasKeyword(schema, "propertyNames") || fn.hasKeyword(schema, "unevaluatedItems") || + fn.hasKeyword(schema, "unevaluatedProperties") || 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 3d8c68696f7..ca42b0c9474 100644 --- a/src/core/plugins/json-schema-2020-12/hoc.jsx +++ b/src/core/plugins/json-schema-2020-12/hoc.jsx @@ -29,6 +29,7 @@ import KeywordPatternProperties from "./components/keywords/PatternProperties/Pa import KeywordAdditionalProperties from "./components/keywords/AdditionalProperties" import KeywordPropertyNames from "./components/keywords/PropertyNames" import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems" +import KeywordUnevaluatedProperties from "./components/keywords/UnevaluatedProperties" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" import KeywordTitle from "./components/keywords/Title/Title" @@ -75,6 +76,7 @@ export const withJSONSchemaContext = (Component, overrides = {}) => { KeywordAdditionalProperties, KeywordPropertyNames, KeywordUnevaluatedItems, + KeywordUnevaluatedProperties, 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 6bad464f495..593c0fab059 100644 --- a/src/core/plugins/json-schema-2020-12/index.js +++ b/src/core/plugins/json-schema-2020-12/index.js @@ -27,6 +27,7 @@ import KeywordPatternProperties from "./components/keywords/PatternProperties/Pa import KeywordAdditionalProperties from "./components/keywords/AdditionalProperties" import KeywordPropertyNames from "./components/keywords/PropertyNames" import KeywordUnevaluatedItems from "./components/keywords/UnevaluatedItems" +import KeywordUnevaluatedProperties from "./components/keywords/UnevaluatedProperties" import KeywordType from "./components/keywords/Type/Type" import KeywordFormat from "./components/keywords/Format/Format" import KeywordTitle from "./components/keywords/Title/Title" @@ -65,6 +66,7 @@ const JSONSchema202012Plugin = () => ({ JSONSchema202012KeywordAdditionalProperties: KeywordAdditionalProperties, JSONSchema202012KeywordPropertyNames: KeywordPropertyNames, JSONSchema202012KeywordUnevaluatedItems: KeywordUnevaluatedItems, + JSONSchema202012KeywordUnevaluatedProperties: KeywordUnevaluatedProperties, 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 ad3fcea86d2..cc060f726e7 100644 --- a/src/core/plugins/oas31/wrap-components/models.jsx +++ b/src/core/plugins/oas31/wrap-components/models.jsx @@ -46,6 +46,9 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { const KeywordUnevaluatedItems = getComponent( "JSONSchema202012KeywordUnevaluatedItems" ) + const KeywordUnevaluatedProperties = getComponent( + "JSONSchema202012KeywordUnevaluatedProperties" + ) const KeywordType = getComponent("JSONSchema202012KeywordType") const KeywordFormat = getComponent("JSONSchema202012KeywordFormat") const KeywordTitle = getComponent("JSONSchema202012KeywordTitle") @@ -89,6 +92,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { KeywordAdditionalProperties, KeywordPropertyNames, KeywordUnevaluatedItems, + KeywordUnevaluatedProperties, KeywordType, KeywordFormat, KeywordTitle,