From 18681857c67435f2e5e47e4cc4a5ff1a6c20debf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Tue, 21 Mar 2023 14:13:18 +0100 Subject: [PATCH] feat(oas31): add support for rendering OpenAPI.jsonSchemaDialect field (#8496) Refs #8491 --- src/core/plugins/oas31/components/info.jsx | 3 + .../oas31/components/json-schema-dialect.jsx | 60 +++++++++++++++++++ src/core/plugins/oas31/index.js | 7 +++ .../oas31/spec-extensions/selectors.js | 7 +++ 4 files changed, 77 insertions(+) create mode 100644 src/core/plugins/oas31/components/json-schema-dialect.jsx diff --git a/src/core/plugins/oas31/components/info.jsx b/src/core/plugins/oas31/components/info.jsx index d81f911e..f49e8ff1 100644 --- a/src/core/plugins/oas31/components/info.jsx +++ b/src/core/plugins/oas31/components/info.jsx @@ -27,6 +27,7 @@ const Info = ({ getComponent, specSelectors }) => { const InfoBasePath = getComponent("InfoBasePath") const License = getComponent("License", true) const Contact = getComponent("Contact", true) + const JsonSchemaDialect = getComponent("JsonSchemaDialect", true) return (
@@ -67,6 +68,8 @@ const Info = ({ getComponent, specSelectors }) => { {externalDocsDesc || externalDocsUrl} )} + +
) } diff --git a/src/core/plugins/oas31/components/json-schema-dialect.jsx b/src/core/plugins/oas31/components/json-schema-dialect.jsx new file mode 100644 index 00000000..a7f25df9 --- /dev/null +++ b/src/core/plugins/oas31/components/json-schema-dialect.jsx @@ -0,0 +1,60 @@ +/** + * @prettier + */ + +import React from "react" +import PropTypes from "prop-types" + +import { sanitizeUrl } from "core/utils" + +const JsonSchemaDialect = ({ getComponent, specSelectors }) => { + const jsonSchemaDialect = specSelectors.selectJsonSchemaDialectField() + const jsonSchemaDialectDefault = specSelectors.selectJsonSchemaDialectDefault() // prettier-ignore + + const Link = getComponent("Link") + + return ( + <> + {jsonSchemaDialect && jsonSchemaDialect === jsonSchemaDialectDefault && ( +

+ JSON Schema dialect:{" "} + + {jsonSchemaDialect} + +

+ )} + + {jsonSchemaDialect && jsonSchemaDialect !== jsonSchemaDialectDefault && ( +
+
+
+
+

Warning

+

+ OpenAPI.jsonSchemaDialect field contains a + value different from the default value of{" "} + + {jsonSchemaDialectDefault} + + . Values different from the default one are currently not + supported. Please either omit the field or provide it with the + default value. +

+
+
+
+
+ )} + + ) +} + +JsonSchemaDialect.propTypes = { + getComponent: PropTypes.func.isRequired, + specSelectors: PropTypes.shape({ + selectJsonSchemaDialectField: PropTypes.func.isRequired, + selectJsonSchemaDialectDefault: PropTypes.func.isRequired, + }).isRequired, +} + +export default JsonSchemaDialect diff --git a/src/core/plugins/oas31/index.js b/src/core/plugins/oas31/index.js index 19a8b1ff..11c60c1b 100644 --- a/src/core/plugins/oas31/index.js +++ b/src/core/plugins/oas31/index.js @@ -5,6 +5,7 @@ import Webhooks from "./components/webhooks" import License from "./components/license" import Contact from "./components/contact" import Info from "./components/info" +import JsonSchemaDialect from "./components/json-schema-dialect" import VersionPragmaFilter from "./components/version-pragma-filter" import LicenseWrapper from "./wrap-components/license" import ContactWrapper from "./wrap-components/contact" @@ -32,6 +33,8 @@ import { selectExternalDocsUrlField, selectExternalDocsUrl, selectWebhooksOperations, + selectJsonSchemaDialectField, + selectJsonSchemaDialectDefault, } from "./spec-extensions/selectors" import { isOAS3 as isOAS3SelectorWrapper, @@ -57,6 +60,7 @@ const OAS31Plugin = ({ fn }) => { }, components: { Webhooks, + JsonSchemaDialect, OAS31Info: Info, OAS31License: License, OAS31Contact: Contact, @@ -97,6 +101,9 @@ const OAS31Plugin = ({ fn }) => { webhooks: createOnlyOAS31Selector(selectWebhooks), selectWebhooksOperations: createOnlyOAS31Selector(createSystemSelector(selectWebhooksOperations)), // prettier-ignore + + selectJsonSchemaDialectField, + selectJsonSchemaDialectDefault, }, wrapSelectors: { isOAS3: isOAS3SelectorWrapper, diff --git a/src/core/plugins/oas31/spec-extensions/selectors.js b/src/core/plugins/oas31/spec-extensions/selectors.js index fedf1ee0..401967a7 100644 --- a/src/core/plugins/oas31/spec-extensions/selectors.js +++ b/src/core/plugins/oas31/spec-extensions/selectors.js @@ -154,3 +154,10 @@ export const selectExternalDocsUrl = createSelector( return undefined } ) + +export const selectJsonSchemaDialectField = () => (system) => { + return system.specSelectors.specJson().get("jsonSchemaDialect") +} + +export const selectJsonSchemaDialectDefault = () => + "https://spec.openapis.org/oas/3.1/dialect/base"