Utility functions to detect OpenAPI 3.0 and Swagger 2.0 specs and wrap components accordingly.
// Source: https://github.com/swagger-api/swagger-ui | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
/**
* @prettier
*/
import React from "react"
export function isOAS30(jsSpec) {
const oasVersion = jsSpec.get("openapi")
return (
typeof oasVersion === "string" && /^3\.0\.(?:[1-9]\d*|0)$/.test(oasVersion)
)
}
export function isSwagger2(jsSpec) {
const swaggerVersion = jsSpec.get("swagger")
return typeof swaggerVersion === "string" && swaggerVersion === "2.0"
}
export function OAS3ComponentWrapFactory(Component) {
return (Ori, system) => (props) => {
if (typeof system.specSelectors?.isOAS3 === "function") {
if (system.specSelectors.isOAS3()) {
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key