Skip to content

Commit

Permalink
feat: add oas 2.0 badge
Browse files Browse the repository at this point in the history
  • Loading branch information
kowalczyk-krzysztof committed Aug 25, 2023
1 parent e3ade63 commit f5a1cda
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 51 deletions.
4 changes: 3 additions & 1 deletion src/core/components/info.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Info extends React.Component {
getComponent: PropTypes.func.isRequired,
oas3selectors: PropTypes.func,
selectedServer: PropTypes.string,
oasVersion: PropTypes.string,
}

render() {
Expand All @@ -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")
Expand Down Expand Up @@ -99,7 +101,7 @@ class Info extends React.Component {
<hgroup className="main">
<h2 className="title">
{title}
{version && <VersionStamp version={version}></VersionStamp>}
{version && <VersionStamp version={version} oasVersion={oasVersion}></VersionStamp>}
</h2>
{host || basePath ? (
<InfoBasePath host={host} basePath={basePath} />
Expand Down
18 changes: 14 additions & 4 deletions src/core/components/version-stamp.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import React from "react"
import PropTypes from "prop-types"

const VersionStamp = ({ version }) => {
return <small><pre className="version"> { version } </pre></small>
}

const VersionStamp = ({ version, oasVersion }) => (
<>
<small>
<pre className="version"> {version} </pre>
</small>
{oasVersion &&
<small className="version-stamp">
<pre className="version">OAS {oasVersion}</pre>
</small>}
</>
)

VersionStamp.propTypes = {
version: PropTypes.string.isRequired
version: PropTypes.string.isRequired,
oasVersion: PropTypes.string
}

export default VersionStamp
6 changes: 5 additions & 1 deletion src/core/containers/info.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ 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")

return (
<div>
{info && info.count() ? (
<Info info={info} url={url} host={host} basePath={basePath} externalDocs={externalDocs}
getComponent={getComponent} selectedServer={selectedServer} />
getComponent={getComponent} selectedServer={selectedServer} oasVersion={oasVersion()}/>
) : null}
</div>
)
Expand Down
2 changes: 0 additions & 2 deletions src/core/plugins/oas3/wrap-components/index.js
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -9,7 +8,6 @@ export default {
Markdown,
AuthItem,
JsonSchema_string,
VersionStamp,
model: Model,
onlineValidatorBadge: OnlineValidatorBadge,
}
19 changes: 0 additions & 19 deletions src/core/plugins/oas3/wrap-components/version-stamp.jsx

This file was deleted.

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

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: 3 additions & 1 deletion test/unit/components/info-wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ describe("<InfoContainer/>", function () {
url () {},
basePath () {},
host () {},
externalDocs () {},
externalDocs() {},
isSwagger2 () {},
isOAS30 () {}
},
oas3Selectors: {
selectedServer () {},
Expand Down

0 comments on commit f5a1cda

Please sign in to comment.