in src/lib/util/utils.ts [46:74]
export async function parseJson(specPath: string) {
if (!specPath || (specPath && typeof specPath.valueOf() !== "string")) {
throw new Error("A (github) url or a local file path to the swagger spec is required and must be of type string.")
}
if (docCache[specPath]) {
return docCache[specPath]
}
// url
if (specPath.match(/^http.*/gi) !== null) {
// If the spec path is a url starting with https://github then let us auto convert it to an https://raw.githubusercontent url.
if (specPath.startsWith("https://github")) {
specPath = specPath.replace(/^https:\/\/(github.com)(.*)blob\/(.*)/gi, "https://raw.githubusercontent.com$2$3")
}
const res = makeRequest({ url: specPath, errorOnNon200Response: true })
docCache[specPath] = res
return res
} else {
// local filepath
try {
const fileContent = stripBOM(fs.readFileSync(specPath, "utf8"))
const result = parseContent(specPath, fileContent)
docCache[specPath] = result
return result
} catch (err) {
log.error(err)
return err
}
}
}