@scalar/api-client
Version:
the open source API testing client
41 lines (40 loc) • 977 B
JavaScript
import { json as n, yaml as o } from "@scalar/oas-utils/helpers";
import { isUrl as i } from "./isUrl.js";
function t(r) {
return {
title: typeof r?.title == "string" ? `${r?.title}` : void 0
};
}
function a(r) {
if (!(!r || i(r))) {
try {
const e = n.parse(r ?? "");
return typeof e?.openapi == "string" ? {
version: `OpenAPI ${e.openapi}`,
type: "json",
...t(e.info)
} : typeof e?.swagger == "string" ? {
version: `Swagger ${e.swagger}`,
type: "json",
...t(e.info)
} : void 0;
} catch {
}
try {
const e = o.parse(r ?? "");
return typeof e?.openapi == "string" ? {
version: `OpenAPI ${e.openapi}`,
type: "yaml",
...t(e.info)
} : typeof e?.swagger == "string" ? {
version: `Swagger ${e.swagger}`,
type: "yaml",
...t(e.info)
} : void 0;
} catch {
}
}
}
export {
a as getOpenApiDocumentDetails
};