improvement: handle more invalid Swagger/OpenAPI version values gracefully (#4699)

* improvement: handle more invalid version values gracefully

* use source maps in Mocha tests

yields accurate stack trace line numbers
This commit is contained in:
kyle
2018-07-05 12:23:36 -05:00
committed by GitHub
parent 3f06bb50fb
commit 21b0037529
3 changed files with 76 additions and 4 deletions

View File

@@ -2,16 +2,20 @@ import React from "react"
export function isOAS3(jsSpec) {
const oasVersion = jsSpec.get("openapi")
if(!oasVersion) {
if(typeof oasVersion !== "string") {
return false
}
return oasVersion.startsWith("3.0.")
// we gate against `3.1` becasue we want to explicitly opt into supporting it
// at some point in the future -- KS, 7/2018
// starts with, but is not `3.0.` exactly
return oasVersion.startsWith("3.0.") && oasVersion.length > 4
}
export function isSwagger2(jsSpec) {
const swaggerVersion = jsSpec.get("swagger")
if(!swaggerVersion) {
if(typeof swaggerVersion !== "string") {
return false
}