diff --git a/src/core/components/info.jsx b/src/core/components/info.jsx index b2327ed5a56..2fbbbede6b7 100644 --- a/src/core/components/info.jsx +++ b/src/core/components/info.jsx @@ -89,6 +89,7 @@ class Info extends React.Component { const Markdown = getComponent("Markdown", true) const Link = getComponent("Link") const VersionStamp = getComponent("VersionStamp") + const OpenAPIVersion = getComponent("OpenAPIVersion") const InfoUrl = getComponent("InfoUrl") const InfoBasePath = getComponent("InfoBasePath") const License = getComponent("License") @@ -99,7 +100,8 @@ class Info extends React.Component {

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

{host || basePath ? ( diff --git a/src/core/components/openapi-version.jsx b/src/core/components/openapi-version.jsx new file mode 100644 index 00000000000..c8608dceef1 --- /dev/null +++ b/src/core/components/openapi-version.jsx @@ -0,0 +1,15 @@ +import React from "react" +import PropTypes from "prop-types" + + +const OpenAPIVersion = ({ oasVersion }) => ( + +
OAS {oasVersion}
+
+) + +OpenAPIVersion.propTypes = { + oasVersion: PropTypes.string.isRequired +} + +export default OpenAPIVersion diff --git a/src/core/plugins/oas3/wrap-components/index.js b/src/core/plugins/oas3/wrap-components/index.js index 2c421add245..9e880566859 100644 --- a/src/core/plugins/oas3/wrap-components/index.js +++ b/src/core/plugins/oas3/wrap-components/index.js @@ -1,15 +1,15 @@ 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" +import OpenAPIVersion from "./openapi-version" export default { Markdown, AuthItem, + OpenAPIVersion, JsonSchema_string, - VersionStamp, model: Model, onlineValidatorBadge: OnlineValidatorBadge, } diff --git a/src/core/plugins/oas3/wrap-components/openapi-version.jsx b/src/core/plugins/oas3/wrap-components/openapi-version.jsx new file mode 100644 index 00000000000..137f74200a7 --- /dev/null +++ b/src/core/plugins/oas3/wrap-components/openapi-version.jsx @@ -0,0 +1,7 @@ +import React from "react" +import { OAS30ComponentWrapFactory } from "../helpers" + +export default OAS30ComponentWrapFactory((props) => { + const { Ori } = props + return +}) 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 9ec70f1b5fc..00000000000 --- 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 f49e8ff1321..8881f8c6b70 100644 --- a/src/core/plugins/oas31/components/info.jsx +++ b/src/core/plugins/oas31/components/info.jsx @@ -23,6 +23,7 @@ const Info = ({ getComponent, specSelectors }) => { const Markdown = getComponent("Markdown", true) const Link = getComponent("Link") const VersionStamp = getComponent("VersionStamp") + const OpenAPIVersion = getComponent("OpenAPIVersion") const InfoUrl = getComponent("InfoUrl") const InfoBasePath = getComponent("InfoBasePath") const License = getComponent("License", true) @@ -34,7 +35,8 @@ 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 51ed5afdaeb..3527a20fa3f 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 5254343fb5a..00000000000 --- 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/src/core/presets/base.js b/src/core/presets/base.js index 9b560d425b9..4c483123675 100644 --- a/src/core/presets/base.js +++ b/src/core/presets/base.js @@ -86,6 +86,7 @@ import Property from "core/components/property" import TryItOutButton from "core/components/try-it-out-button" import VersionPragmaFilter from "core/components/version-pragma-filter" import VersionStamp from "core/components/version-stamp" +import OpenAPIVersion from "core/components/openapi-version" import DeepLink from "core/components/deep-link" import SvgAssets from "core/components/svg-assets" import Markdown from "core/components/providers/markdown" @@ -157,6 +158,7 @@ export default function () { BaseLayout, VersionPragmaFilter, VersionStamp, + OpenAPIVersion, OperationExt, OperationExtRow, ParameterExt, 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 1db2ae5f642..1b70c906fc0 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/e2e-cypress/e2e/features/urls.cy.js b/test/e2e-cypress/e2e/features/urls.cy.js index d661939eac8..7d92e6a18ac 100644 --- a/test/e2e-cypress/e2e/features/urls.cy.js +++ b/test/e2e-cypress/e2e/features/urls.cy.js @@ -18,7 +18,7 @@ describe("configuration options: `urls` and `urls.primaryName`", () => { it("should render the first URL in the list", () => { cy.visit("/?configUrl=/configs/urls.yaml") .get("h2.title") - .should("have.text", "One") + .should("have.text", "OneOAS 2.0") .window() .then(win => win.ui.specSelectors.url()) .should("equal", "/documents/features/urls/1.yaml") @@ -30,7 +30,7 @@ describe("configuration options: `urls` and `urls.primaryName`", () => { .get("select") .should("have.value", "/documents/features/urls/2.yaml") .get("h2.title") - .should("have.text", "Two") + .should("have.text", "TwoOAS 3.0") .window() .then(win => win.ui.specSelectors.url()) .should("equal", "/documents/features/urls/2.yaml")