diff --git a/src/core/components/info.jsx b/src/core/components/info.jsx index b2327ed5a56d..e3c4b0cdd414 100644 --- a/src/core/components/info.jsx +++ b/src/core/components/info.jsx @@ -56,6 +56,7 @@ class Info extends React.Component { getComponent: PropTypes.func.isRequired, oas3selectors: PropTypes.func, selectedServer: PropTypes.string, + oasVersion: PropTypes.string, } render() { @@ -68,6 +69,7 @@ class Info extends React.Component { externalDocs, selectedServer, url: specUrl, + oasVersion } = this.props const version = info.get("version") const description = info.get("description") @@ -99,7 +101,7 @@ class Info extends React.Component {

{title} - {version && } + {version && }

{host || basePath ? ( diff --git a/src/core/components/version-stamp.jsx b/src/core/components/version-stamp.jsx index 262cc023c466..ed50941c1b1b 100644 --- a/src/core/components/version-stamp.jsx +++ b/src/core/components/version-stamp.jsx @@ -1,12 +1,22 @@ import React from "react" import PropTypes from "prop-types" -const VersionStamp = ({ version }) => { - return
 { version } 
-} + +const VersionStamp = ({ version, oasVersion }) => ( + <> + +
 {version} 
+
+ {oasVersion && + +
OAS {oasVersion}
+
} + +) VersionStamp.propTypes = { - version: PropTypes.string.isRequired + version: PropTypes.string.isRequired, + oasVersion: PropTypes.string } export default VersionStamp diff --git a/src/core/containers/info.jsx b/src/core/containers/info.jsx index ebf01a1f71d1..8fde80ec5e9f 100644 --- a/src/core/containers/info.jsx +++ b/src/core/containers/info.jsx @@ -19,6 +19,10 @@ export default class InfoContainer extends React.Component { const host = specSelectors.host() const externalDocs = specSelectors.externalDocs() const selectedServer = oas3Selectors.selectedServer() + const oasVersion = () => { + if (specSelectors.isSwagger2()) return "2.0" + if (specSelectors.isOAS30()) return "3.0" + } const Info = getComponent("info") @@ -26,7 +30,7 @@ export default class InfoContainer extends React.Component {
{info && info.count() ? ( + getComponent={getComponent} selectedServer={selectedServer} oasVersion={oasVersion()}/> ) : null}
) diff --git a/src/core/plugins/oas3/wrap-components/index.js b/src/core/plugins/oas3/wrap-components/index.js index 2c421add2457..296967db033b 100644 --- a/src/core/plugins/oas3/wrap-components/index.js +++ b/src/core/plugins/oas3/wrap-components/index.js @@ -1,6 +1,5 @@ import Markdown from "./markdown" import AuthItem from "./auth-item" -import VersionStamp from "./version-stamp" import OnlineValidatorBadge from "./online-validator-badge" import Model from "./model" import JsonSchema_string from "./json-schema-string" @@ -9,7 +8,6 @@ export default { Markdown, AuthItem, JsonSchema_string, - VersionStamp, model: Model, onlineValidatorBadge: OnlineValidatorBadge, } diff --git a/src/core/plugins/oas3/wrap-components/version-stamp.jsx b/src/core/plugins/oas3/wrap-components/version-stamp.jsx deleted file mode 100644 index 9ec70f1b5fc3..000000000000 --- a/src/core/plugins/oas3/wrap-components/version-stamp.jsx +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @prettier - */ -import React from "react" - -import { OAS30ComponentWrapFactory } from "../helpers" - -export default OAS30ComponentWrapFactory((props) => { - const { Ori } = props - - return ( - - - -
OAS 3.0
-
-
- ) -}) diff --git a/src/core/plugins/oas31/components/info.jsx b/src/core/plugins/oas31/components/info.jsx index f49e8ff1321a..7842e28d9e5a 100644 --- a/src/core/plugins/oas31/components/info.jsx +++ b/src/core/plugins/oas31/components/info.jsx @@ -34,7 +34,7 @@ const Info = ({ getComponent, specSelectors }) => {

{title} - {version && } + {version && }

{(host || basePath) && } diff --git a/src/core/plugins/oas31/index.js b/src/core/plugins/oas31/index.js index 51ed5afdaeb0..3527a20fa3f3 100644 --- a/src/core/plugins/oas31/index.js +++ b/src/core/plugins/oas31/index.js @@ -15,7 +15,6 @@ import InfoWrapper from "./wrap-components/info" import ModelWrapper from "./wrap-components/model" import ModelsWrapper from "./wrap-components/models" import VersionPragmaFilterWrapper from "./wrap-components/version-pragma-filter" -import VersionStampWrapper from "./wrap-components/version-stamp" import { isOAS31 as isOAS31Fn, createOnlyOAS31Selector as createOnlyOAS31SelectorFn, @@ -91,7 +90,6 @@ const OAS31Plugin = ({ fn }) => { License: LicenseWrapper, Contact: ContactWrapper, VersionPragmaFilter: VersionPragmaFilterWrapper, - VersionStamp: VersionStampWrapper, Model: ModelWrapper, Models: ModelsWrapper, JSONSchema202012KeywordDescription: diff --git a/src/core/plugins/oas31/wrap-components/version-stamp.jsx b/src/core/plugins/oas31/wrap-components/version-stamp.jsx deleted file mode 100644 index 5254343fb5a1..000000000000 --- a/src/core/plugins/oas31/wrap-components/version-stamp.jsx +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @prettier - */ -import React from "react" - -import { createOnlyOAS31ComponentWrapper } from "../fn" - -const VersionStampWrapper = createOnlyOAS31ComponentWrapper( - ({ originalComponent: Original, ...restProps }) => ( - - - -
OAS 3.1
-
-
- ) -) - -export default VersionStampWrapper diff --git a/test/e2e-cypress/e2e/features/oas3-badge.cy.js b/test/e2e-cypress/e2e/features/oas-badge.cy.js similarity index 55% rename from test/e2e-cypress/e2e/features/oas3-badge.cy.js rename to test/e2e-cypress/e2e/features/oas-badge.cy.js index 1db2ae5f6429..1b70c906fc03 100644 --- a/test/e2e-cypress/e2e/features/oas3-badge.cy.js +++ b/test/e2e-cypress/e2e/features/oas-badge.cy.js @@ -1,7 +1,16 @@ -describe("OpenAPI 3.x.y Badge", () => { +describe("OpenAPI Badge", () => { + it("should display light green badge with version indicator for Swagger 2.0", () => { + cy.visit("/?url=/documents/features/info-openAPI2.yaml") + .get("#swagger-ui") + .get('*[class^="version-stamp"]') + .get("pre.version") + .contains("OAS 2.0") + }) + it("should display light green badge with version indicator for OpenAPI 3.0.x", () => { cy.visit("/?url=/documents/petstore-expanded.openapi.yaml") .get("#swagger-ui") + .get('*[class^="version-stamp"]') .get("pre.version") .contains("OAS 3.0") }) @@ -9,6 +18,7 @@ describe("OpenAPI 3.x.y Badge", () => { it("should display light green badge with version indicator for OpenAPI 3.1.0", () => { cy.visit("/?url=/documents/features/info-openAPI31.yaml") .get("#swagger-ui") + .get('*[class^="version-stamp"]') .get("pre.version") .contains("OAS 3.1") }) diff --git a/test/unit/components/info-wrapper.jsx b/test/unit/components/info-wrapper.jsx index 256ee1d30411..8c9c0cb9ee5a 100644 --- a/test/unit/components/info-wrapper.jsx +++ b/test/unit/components/info-wrapper.jsx @@ -14,7 +14,9 @@ describe("", function () { url () {}, basePath () {}, host () {}, - externalDocs () {}, + externalDocs() {}, + isSwagger2 () {}, + isOAS30 () {} }, oas3Selectors: { selectedServer () {},