Skip to content

Commit

Permalink
feat(oas31): add support for rendering OpenAPI.jsonSchemaDialect field (
Browse files Browse the repository at this point in the history
#8496)

Refs #8491
  • Loading branch information
char0n authored Mar 21, 2023
1 parent 4810801 commit 1868185
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/plugins/oas31/components/info.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="info">
Expand Down Expand Up @@ -67,6 +68,8 @@ const Info = ({ getComponent, specSelectors }) => {
{externalDocsDesc || externalDocsUrl}
</Link>
)}

<JsonSchemaDialect />
</div>
)
}
Expand Down
60 changes: 60 additions & 0 deletions src/core/plugins/oas31/components/json-schema-dialect.jsx
Original file line number Diff line number Diff line change
@@ -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 && (
<p className="info__jsonschemadialect">
JSON Schema dialect:{" "}
<Link target="_blank" href={sanitizeUrl(jsonSchemaDialect)}>
{jsonSchemaDialect}
</Link>
</p>
)}

{jsonSchemaDialect && jsonSchemaDialect !== jsonSchemaDialectDefault && (
<div className="error-wrapper">
<div className="no-margin">
<div className="errors">
<div className="errors-wrapper">
<h4 className="center">Warning</h4>
<p className="message">
<strong>OpenAPI.jsonSchemaDialect</strong> field contains a
value different from the default value of{" "}
<Link target="_blank" href={jsonSchemaDialectDefault}>
{jsonSchemaDialectDefault}
</Link>
. Values different from the default one are currently not
supported. Please either omit the field or provide it with the
default value.
</p>
</div>
</div>
</div>
</div>
)}
</>
)
}

JsonSchemaDialect.propTypes = {
getComponent: PropTypes.func.isRequired,
specSelectors: PropTypes.shape({
selectJsonSchemaDialectField: PropTypes.func.isRequired,
selectJsonSchemaDialectDefault: PropTypes.func.isRequired,
}).isRequired,
}

export default JsonSchemaDialect
7 changes: 7 additions & 0 deletions src/core/plugins/oas31/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -32,6 +33,8 @@ import {
selectExternalDocsUrlField,
selectExternalDocsUrl,
selectWebhooksOperations,
selectJsonSchemaDialectField,
selectJsonSchemaDialectDefault,
} from "./spec-extensions/selectors"
import {
isOAS3 as isOAS3SelectorWrapper,
Expand All @@ -57,6 +60,7 @@ const OAS31Plugin = ({ fn }) => {
},
components: {
Webhooks,
JsonSchemaDialect,
OAS31Info: Info,
OAS31License: License,
OAS31Contact: Contact,
Expand Down Expand Up @@ -97,6 +101,9 @@ const OAS31Plugin = ({ fn }) => {

webhooks: createOnlyOAS31Selector(selectWebhooks),
selectWebhooksOperations: createOnlyOAS31Selector(createSystemSelector(selectWebhooksOperations)), // prettier-ignore

selectJsonSchemaDialectField,
selectJsonSchemaDialectDefault,
},
wrapSelectors: {
isOAS3: isOAS3SelectorWrapper,
Expand Down
7 changes: 7 additions & 0 deletions src/core/plugins/oas31/spec-extensions/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 1868185

Please sign in to comment.