-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oas31): add support for OpenAPI 3.1.0 in VersionPragmaFilter (#8495
) Refs #8492
- Loading branch information
Showing
4 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/core/plugins/oas31/components/version-pragma-filter.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from "react" | ||
import PropTypes from "prop-types" | ||
|
||
const VersionPragmaFilter = ({ | ||
bypass, | ||
isSwagger2, | ||
isOAS3, | ||
isOAS31, | ||
alsoShow, | ||
children, | ||
}) => { | ||
if (bypass) { | ||
return <div>{children}</div> | ||
} | ||
|
||
if (isSwagger2 && (isOAS3 || isOAS31)) { | ||
return ( | ||
<div className="version-pragma"> | ||
{alsoShow} | ||
<div className="version-pragma__message version-pragma__message--ambiguous"> | ||
<div> | ||
<h3>Unable to render this definition</h3> | ||
<p> | ||
<code>swagger</code> and <code>openapi</code> fields cannot be | ||
present in the same Swagger or OpenAPI definition. Please remove | ||
one of the fields. | ||
</p> | ||
<p> | ||
Supported version fields are <code>swagger: "2.0"</code> and | ||
those that match <code>openapi: 3.x.y</code> (for example,{" "} | ||
<code>openapi: 3.1.0</code>). | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
if (!isSwagger2 && !isOAS3 && !isOAS31) { | ||
return ( | ||
<div className="version-pragma"> | ||
{alsoShow} | ||
<div className="version-pragma__message version-pragma__message--missing"> | ||
<div> | ||
<h3>Unable to render this definition</h3> | ||
<p> | ||
The provided definition does not specify a valid version field. | ||
</p> | ||
<p> | ||
Please indicate a valid Swagger or OpenAPI version field. | ||
Supported version fields are <code>swagger: "2.0"</code> and | ||
those that match <code>openapi: 3.x.y</code> (for example,{" "} | ||
<code>openapi: 3.1.0</code>). | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
return <div>{children}</div> | ||
} | ||
|
||
VersionPragmaFilter.propTypes = { | ||
isSwagger2: PropTypes.bool.isRequired, | ||
isOAS3: PropTypes.bool.isRequired, | ||
isOAS31: PropTypes.bool.isRequired, | ||
bypass: PropTypes.bool, | ||
alsoShow: PropTypes.element, | ||
children: PropTypes.any, | ||
} | ||
|
||
export default VersionPragmaFilter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/core/plugins/oas31/wrap-components/version-pragma-filter.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import React from "react" | ||
|
||
const VersionPragmaFilterWrapper = (Original, system) => (props) => { | ||
const isOAS31 = system.specSelectors.isOAS31() | ||
|
||
const OAS31VersionPragmaFilter = system.getComponent( | ||
"OAS31VersionPragmaFilter" | ||
) | ||
|
||
return <OAS31VersionPragmaFilter isOAS31={isOAS31} {...props} /> | ||
} | ||
|
||
export default VersionPragmaFilterWrapper |
84 changes: 84 additions & 0 deletions
84
test/unit/core/plugins/oas31/components/version-pragma-filter.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from "react" | ||
import { shallow } from "enzyme" | ||
import VersionPragmaFilter from "core/plugins/oas31/components/version-pragma-filter" | ||
|
||
describe("<VersionPragmaFilter/>", function(){ | ||
it("renders children for a Swagger 2 definition", function(){ | ||
// When | ||
let wrapper = shallow( | ||
<VersionPragmaFilter isSwagger2={true} isOAS3={false} isOAS31={false}> | ||
hello! | ||
</VersionPragmaFilter> | ||
) | ||
|
||
// Then | ||
expect(wrapper.find("div").length).toEqual(1) | ||
expect(wrapper.find("div").text()).toEqual("hello!") | ||
}) | ||
|
||
it("renders children for an OpenAPI 3.0.x definition", function(){ | ||
// When | ||
let wrapper = shallow( | ||
<VersionPragmaFilter isSwagger2={false} isOAS3={true} isOAS31={false}> | ||
hello! | ||
</VersionPragmaFilter> | ||
) | ||
|
||
// Then | ||
expect(wrapper.find("div").length).toEqual(1) | ||
expect(wrapper.find("div").text()).toEqual("hello!") | ||
}) | ||
|
||
it("renders children for an OpenAPI 3.1.0 definition", function(){ | ||
// When | ||
let wrapper = shallow( | ||
<VersionPragmaFilter isSwagger2={false} isOAS3={false} isOAS31={true}> | ||
hello! | ||
</VersionPragmaFilter> | ||
) | ||
|
||
// Then | ||
expect(wrapper.find("div").length).toEqual(1) | ||
expect(wrapper.find("div").text()).toEqual("hello!") | ||
}) | ||
|
||
it("renders children when a bypass prop is set", function(){ | ||
// When | ||
let wrapper = shallow( | ||
<VersionPragmaFilter bypass isSwagger2={false} isOAS3={false} isOAS31={false}> | ||
hello! | ||
</VersionPragmaFilter> | ||
) | ||
|
||
// Then | ||
expect(wrapper.find("div").length).toEqual(1) | ||
expect(wrapper.find("div").text()).toEqual("hello!") | ||
}) | ||
|
||
it("renders the correct message for an ambiguous-version definition", function(){ | ||
// When | ||
let wrapper = shallow( | ||
<VersionPragmaFilter isSwagger2={true} isOAS3={true} isOAS31={true}> | ||
hello! | ||
</VersionPragmaFilter> | ||
) | ||
|
||
// Then | ||
expect(wrapper.find("div.version-pragma__message--ambiguous").length).toEqual(1) | ||
expect(wrapper.find("div.version-pragma__message--missing").length).toEqual(0) | ||
}) | ||
|
||
it("renders the correct message for a missing-version definition", function(){ | ||
// When | ||
let wrapper = shallow( | ||
<VersionPragmaFilter isSwagger2={false} isOAS3={false} isOAS31={false}> | ||
hello! | ||
</VersionPragmaFilter> | ||
) | ||
|
||
// Then | ||
expect(wrapper.find("div.version-pragma__message--missing").length).toEqual(1) | ||
expect(wrapper.find("div.version-pragma__message--ambiguous").length).toEqual(0) | ||
}) | ||
|
||
}) |