Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add OpenAPIVersion component #9167

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/components/info.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -99,7 +100,8 @@ class Info extends React.Component {
<hgroup className="main">
<h2 className="title">
{title}
{version && <VersionStamp version={version}></VersionStamp>}
{version && <VersionStamp version={version} />}
<OpenAPIVersion oasVersion="2.0" />
</h2>
{host || basePath ? (
<InfoBasePath host={host} basePath={basePath} />
Expand Down
15 changes: 15 additions & 0 deletions src/core/components/openapi-version.jsx
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/core/plugins/oas3/wrap-components/index.js
Original file line number Diff line number Diff line change
@@ -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,
}
7 changes: 7 additions & 0 deletions src/core/plugins/oas3/wrap-components/openapi-version.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react"
import { OAS30ComponentWrapFactory } from "../helpers"

export default OAS30ComponentWrapFactory((props) => {
const { Ori } = props
return <Ori oasVersion="3.0" />
})
19 changes: 0 additions & 19 deletions src/core/plugins/oas3/wrap-components/version-stamp.jsx

This file was deleted.

4 changes: 3 additions & 1 deletion src/core/plugins/oas31/components/info.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -34,7 +35,8 @@ const Info = ({ getComponent, specSelectors }) => {
<hgroup className="main">
<h2 className="title">
{title}
{version && <VersionStamp version={version}></VersionStamp>}
{version && <VersionStamp version={version} />}
<OpenAPIVersion oasVersion="3.1" />
</h2>

{(host || basePath) && <InfoBasePath host={host} basePath={basePath} />}
Expand Down
2 changes: 0 additions & 2 deletions src/core/plugins/oas31/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,7 +90,6 @@ const OAS31Plugin = ({ fn }) => {
License: LicenseWrapper,
Contact: ContactWrapper,
VersionPragmaFilter: VersionPragmaFilterWrapper,
VersionStamp: VersionStampWrapper,
Model: ModelWrapper,
Models: ModelsWrapper,
JSONSchema202012KeywordDescription:
Expand Down
19 changes: 0 additions & 19 deletions src/core/plugins/oas31/wrap-components/version-stamp.jsx

This file was deleted.

2 changes: 2 additions & 0 deletions src/core/presets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -157,6 +158,7 @@ export default function () {
BaseLayout,
VersionPragmaFilter,
VersionStamp,
OpenAPIVersion,
OperationExt,
OperationExtRow,
ParameterExt,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
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")
})

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")
})
Expand Down
4 changes: 2 additions & 2 deletions test/e2e-cypress/e2e/features/urls.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down