feat(info): indicate OpenAPI 2.0 definition version (#9167)
This commit is contained in:
committed by
GitHub
parent
6fd6e339cc
commit
4b48e36c09
@@ -89,6 +89,7 @@ class Info extends React.Component {
|
|||||||
const Markdown = getComponent("Markdown", true)
|
const Markdown = getComponent("Markdown", true)
|
||||||
const Link = getComponent("Link")
|
const Link = getComponent("Link")
|
||||||
const VersionStamp = getComponent("VersionStamp")
|
const VersionStamp = getComponent("VersionStamp")
|
||||||
|
const OpenAPIVersion = getComponent("OpenAPIVersion")
|
||||||
const InfoUrl = getComponent("InfoUrl")
|
const InfoUrl = getComponent("InfoUrl")
|
||||||
const InfoBasePath = getComponent("InfoBasePath")
|
const InfoBasePath = getComponent("InfoBasePath")
|
||||||
const License = getComponent("License")
|
const License = getComponent("License")
|
||||||
@@ -99,7 +100,8 @@ class Info extends React.Component {
|
|||||||
<hgroup className="main">
|
<hgroup className="main">
|
||||||
<h2 className="title">
|
<h2 className="title">
|
||||||
{title}
|
{title}
|
||||||
{version && <VersionStamp version={version}></VersionStamp>}
|
{version && <VersionStamp version={version} />}
|
||||||
|
<OpenAPIVersion oasVersion="2.0" />
|
||||||
</h2>
|
</h2>
|
||||||
{host || basePath ? (
|
{host || basePath ? (
|
||||||
<InfoBasePath host={host} basePath={basePath} />
|
<InfoBasePath host={host} basePath={basePath} />
|
||||||
|
|||||||
15
src/core/components/openapi-version.jsx
Normal file
15
src/core/components/openapi-version.jsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import React from "react"
|
||||||
|
import PropTypes from "prop-types"
|
||||||
|
|
||||||
|
|
||||||
|
const OpenAPIVersion = ({ oasVersion }) => (
|
||||||
|
<small className="version-stamp">
|
||||||
|
<pre className="version">OAS {oasVersion}</pre>
|
||||||
|
</small>
|
||||||
|
)
|
||||||
|
|
||||||
|
OpenAPIVersion.propTypes = {
|
||||||
|
oasVersion: PropTypes.string.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
export default OpenAPIVersion
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
import Markdown from "./markdown"
|
import Markdown from "./markdown"
|
||||||
import AuthItem from "./auth-item"
|
import AuthItem from "./auth-item"
|
||||||
import VersionStamp from "./version-stamp"
|
|
||||||
import OnlineValidatorBadge from "./online-validator-badge"
|
import OnlineValidatorBadge from "./online-validator-badge"
|
||||||
import Model from "./model"
|
import Model from "./model"
|
||||||
import JsonSchema_string from "./json-schema-string"
|
import JsonSchema_string from "./json-schema-string"
|
||||||
|
import OpenAPIVersion from "./openapi-version"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Markdown,
|
Markdown,
|
||||||
AuthItem,
|
AuthItem,
|
||||||
|
OpenAPIVersion,
|
||||||
JsonSchema_string,
|
JsonSchema_string,
|
||||||
VersionStamp,
|
|
||||||
model: Model,
|
model: Model,
|
||||||
onlineValidatorBadge: OnlineValidatorBadge,
|
onlineValidatorBadge: OnlineValidatorBadge,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import React from "react"
|
||||||
|
import { OAS30ComponentWrapFactory } from "../helpers"
|
||||||
|
|
||||||
|
export default OAS30ComponentWrapFactory((props) => {
|
||||||
|
const { Ori } = props
|
||||||
|
return <Ori oasVersion="3.0" />
|
||||||
|
})
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* @prettier
|
|
||||||
*/
|
|
||||||
import React from "react"
|
|
||||||
|
|
||||||
import { OAS30ComponentWrapFactory } from "../helpers"
|
|
||||||
|
|
||||||
export default OAS30ComponentWrapFactory((props) => {
|
|
||||||
const { Ori } = props
|
|
||||||
|
|
||||||
return (
|
|
||||||
<span>
|
|
||||||
<Ori {...props} />
|
|
||||||
<small className="version-stamp">
|
|
||||||
<pre className="version">OAS 3.0</pre>
|
|
||||||
</small>
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
@@ -23,6 +23,7 @@ const Info = ({ getComponent, specSelectors }) => {
|
|||||||
const Markdown = getComponent("Markdown", true)
|
const Markdown = getComponent("Markdown", true)
|
||||||
const Link = getComponent("Link")
|
const Link = getComponent("Link")
|
||||||
const VersionStamp = getComponent("VersionStamp")
|
const VersionStamp = getComponent("VersionStamp")
|
||||||
|
const OpenAPIVersion = getComponent("OpenAPIVersion")
|
||||||
const InfoUrl = getComponent("InfoUrl")
|
const InfoUrl = getComponent("InfoUrl")
|
||||||
const InfoBasePath = getComponent("InfoBasePath")
|
const InfoBasePath = getComponent("InfoBasePath")
|
||||||
const License = getComponent("License", true)
|
const License = getComponent("License", true)
|
||||||
@@ -34,7 +35,8 @@ const Info = ({ getComponent, specSelectors }) => {
|
|||||||
<hgroup className="main">
|
<hgroup className="main">
|
||||||
<h2 className="title">
|
<h2 className="title">
|
||||||
{title}
|
{title}
|
||||||
{version && <VersionStamp version={version}></VersionStamp>}
|
{version && <VersionStamp version={version} />}
|
||||||
|
<OpenAPIVersion oasVersion="3.1" />
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
{(host || basePath) && <InfoBasePath host={host} basePath={basePath} />}
|
{(host || basePath) && <InfoBasePath host={host} basePath={basePath} />}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import InfoWrapper from "./wrap-components/info"
|
|||||||
import ModelWrapper from "./wrap-components/model"
|
import ModelWrapper from "./wrap-components/model"
|
||||||
import ModelsWrapper from "./wrap-components/models"
|
import ModelsWrapper from "./wrap-components/models"
|
||||||
import VersionPragmaFilterWrapper from "./wrap-components/version-pragma-filter"
|
import VersionPragmaFilterWrapper from "./wrap-components/version-pragma-filter"
|
||||||
import VersionStampWrapper from "./wrap-components/version-stamp"
|
|
||||||
import {
|
import {
|
||||||
isOAS31 as isOAS31Fn,
|
isOAS31 as isOAS31Fn,
|
||||||
createOnlyOAS31Selector as createOnlyOAS31SelectorFn,
|
createOnlyOAS31Selector as createOnlyOAS31SelectorFn,
|
||||||
@@ -91,7 +90,6 @@ const OAS31Plugin = ({ fn }) => {
|
|||||||
License: LicenseWrapper,
|
License: LicenseWrapper,
|
||||||
Contact: ContactWrapper,
|
Contact: ContactWrapper,
|
||||||
VersionPragmaFilter: VersionPragmaFilterWrapper,
|
VersionPragmaFilter: VersionPragmaFilterWrapper,
|
||||||
VersionStamp: VersionStampWrapper,
|
|
||||||
Model: ModelWrapper,
|
Model: ModelWrapper,
|
||||||
Models: ModelsWrapper,
|
Models: ModelsWrapper,
|
||||||
JSONSchema202012KeywordDescription:
|
JSONSchema202012KeywordDescription:
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* @prettier
|
|
||||||
*/
|
|
||||||
import React from "react"
|
|
||||||
|
|
||||||
import { createOnlyOAS31ComponentWrapper } from "../fn"
|
|
||||||
|
|
||||||
const VersionStampWrapper = createOnlyOAS31ComponentWrapper(
|
|
||||||
({ originalComponent: Original, ...restProps }) => (
|
|
||||||
<span>
|
|
||||||
<Original {...restProps} />
|
|
||||||
<small className="version-stamp">
|
|
||||||
<pre className="version">OAS 3.1</pre>
|
|
||||||
</small>
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
export default VersionStampWrapper
|
|
||||||
@@ -86,6 +86,7 @@ import Property from "core/components/property"
|
|||||||
import TryItOutButton from "core/components/try-it-out-button"
|
import TryItOutButton from "core/components/try-it-out-button"
|
||||||
import VersionPragmaFilter from "core/components/version-pragma-filter"
|
import VersionPragmaFilter from "core/components/version-pragma-filter"
|
||||||
import VersionStamp from "core/components/version-stamp"
|
import VersionStamp from "core/components/version-stamp"
|
||||||
|
import OpenAPIVersion from "core/components/openapi-version"
|
||||||
import DeepLink from "core/components/deep-link"
|
import DeepLink from "core/components/deep-link"
|
||||||
import SvgAssets from "core/components/svg-assets"
|
import SvgAssets from "core/components/svg-assets"
|
||||||
import Markdown from "core/components/providers/markdown"
|
import Markdown from "core/components/providers/markdown"
|
||||||
@@ -157,6 +158,7 @@ export default function () {
|
|||||||
BaseLayout,
|
BaseLayout,
|
||||||
VersionPragmaFilter,
|
VersionPragmaFilter,
|
||||||
VersionStamp,
|
VersionStamp,
|
||||||
|
OpenAPIVersion,
|
||||||
OperationExt,
|
OperationExt,
|
||||||
OperationExtRow,
|
OperationExtRow,
|
||||||
ParameterExt,
|
ParameterExt,
|
||||||
|
|||||||
@@ -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", () => {
|
it("should display light green badge with version indicator for OpenAPI 3.0.x", () => {
|
||||||
cy.visit("/?url=/documents/petstore-expanded.openapi.yaml")
|
cy.visit("/?url=/documents/petstore-expanded.openapi.yaml")
|
||||||
.get("#swagger-ui")
|
.get("#swagger-ui")
|
||||||
|
.get('*[class^="version-stamp"]')
|
||||||
.get("pre.version")
|
.get("pre.version")
|
||||||
.contains("OAS 3.0")
|
.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", () => {
|
it("should display light green badge with version indicator for OpenAPI 3.1.0", () => {
|
||||||
cy.visit("/?url=/documents/features/info-openAPI31.yaml")
|
cy.visit("/?url=/documents/features/info-openAPI31.yaml")
|
||||||
.get("#swagger-ui")
|
.get("#swagger-ui")
|
||||||
|
.get('*[class^="version-stamp"]')
|
||||||
.get("pre.version")
|
.get("pre.version")
|
||||||
.contains("OAS 3.1")
|
.contains("OAS 3.1")
|
||||||
})
|
})
|
||||||
@@ -18,7 +18,7 @@ describe("configuration options: `urls` and `urls.primaryName`", () => {
|
|||||||
it("should render the first URL in the list", () => {
|
it("should render the first URL in the list", () => {
|
||||||
cy.visit("/?configUrl=/configs/urls.yaml")
|
cy.visit("/?configUrl=/configs/urls.yaml")
|
||||||
.get("h2.title")
|
.get("h2.title")
|
||||||
.should("have.text", "One")
|
.should("have.text", "OneOAS 2.0")
|
||||||
.window()
|
.window()
|
||||||
.then(win => win.ui.specSelectors.url())
|
.then(win => win.ui.specSelectors.url())
|
||||||
.should("equal", "/documents/features/urls/1.yaml")
|
.should("equal", "/documents/features/urls/1.yaml")
|
||||||
@@ -30,7 +30,7 @@ describe("configuration options: `urls` and `urls.primaryName`", () => {
|
|||||||
.get("select")
|
.get("select")
|
||||||
.should("have.value", "/documents/features/urls/2.yaml")
|
.should("have.value", "/documents/features/urls/2.yaml")
|
||||||
.get("h2.title")
|
.get("h2.title")
|
||||||
.should("have.text", "Two")
|
.should("have.text", "TwoOAS 3.0")
|
||||||
.window()
|
.window()
|
||||||
.then(win => win.ui.specSelectors.url())
|
.then(win => win.ui.specSelectors.url())
|
||||||
.should("equal", "/documents/features/urls/2.yaml")
|
.should("equal", "/documents/features/urls/2.yaml")
|
||||||
|
|||||||
Reference in New Issue
Block a user