- New top-level field - `webhooks`. This allows describing out-of-band webhooks that are available as part of the API. - New top-level field - `jsonSchemaDialect`. This allows defining of a default `$schema` value for Schema Objects - The Info Object has a new `summary` field. - The License Object now has a new `identifier` field for SPDX licenses. This `identifier` field is mutually exclusive with the `url` field. Either can be used in OpenAPI 3.1 definitions. - Components Object now has a new entry `pathItems`, to allow for reusable Path Item Objects to be defined within a valid OpenAPI document. - `License` and `Contact` components are now exported and available via `getComponent` - New version predicates and selectors for `isOpenAPI30` and `isOpenAPI31`. This avoids needing to change the usage of `isOAS3` selector. - New OAS3 components: `Webhooks` - New OAS3 wrapped components: `Info`, `License`
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import React from "react"
|
|
|
|
export function isOpenAPI30(jsSpec) {
|
|
const oasVersion = jsSpec.get("openapi")
|
|
if (typeof oasVersion !== "string") {
|
|
return false
|
|
}
|
|
return oasVersion.startsWith("3.0.") && oasVersion.length > 4
|
|
}
|
|
|
|
export function isOpenAPI31(jsSpec) {
|
|
const oasVersion = jsSpec.get("openapi")
|
|
if (typeof oasVersion !== "string") {
|
|
return false
|
|
}
|
|
return oasVersion.startsWith("3.1.") && oasVersion.length > 4
|
|
}
|
|
|
|
export function isOAS3(jsSpec) {
|
|
const oasVersion = jsSpec.get("openapi")
|
|
if(typeof oasVersion !== "string") {
|
|
return false
|
|
}
|
|
return isOpenAPI30(jsSpec) || isOpenAPI31(jsSpec)
|
|
}
|
|
|
|
export function isSwagger2(jsSpec) {
|
|
const swaggerVersion = jsSpec.get("swagger")
|
|
if(typeof swaggerVersion !== "string") {
|
|
return false
|
|
}
|
|
|
|
return swaggerVersion.startsWith("2.0")
|
|
}
|
|
|
|
export function OAS3ComponentWrapFactory(Component) {
|
|
return (Ori, system) => (props) => {
|
|
if(system && system.specSelectors && system.specSelectors.specJson) {
|
|
const spec = system.specSelectors.specJson()
|
|
|
|
if(isOAS3(spec)) {
|
|
return <Component {...props} {...system} Ori={Ori}></Component>
|
|
} else {
|
|
return <Ori {...props}></Ori>
|
|
}
|
|
} else {
|
|
console.warn("OAS3 wrapper: couldn't get spec")
|
|
return null
|
|
}
|
|
}
|
|
}
|