import { isUrl } from "./isUrl.js";
import { json, yaml } from "@scalar/oas-utils/helpers";
//#region src/libs/getOpenApiDocumentDetails.ts
/** Try to extract details from the info */
function tryGetInfo(info) {
	return { title: typeof info?.title === "string" ? `${info?.title}` : void 0 };
}
/**
* Get the base Swagger/OpenAPI details from the given string
*/
function getOpenApiDocumentDetails(input) {
	if (!input || isUrl(input)) return;
	try {
		const result = json.parse(input ?? "");
		if (typeof result?.openapi === "string") return {
			version: `OpenAPI ${result.openapi}`,
			type: "json",
			...tryGetInfo(result.info)
		};
		if (typeof result?.swagger === "string") return {
			version: `Swagger ${result.swagger}`,
			type: "json",
			...tryGetInfo(result.info)
		};
		return;
	} catch {}
	try {
		const result = yaml.parse(input ?? "");
		if (typeof result?.openapi === "string") return {
			version: `OpenAPI ${result.openapi}`,
			type: "yaml",
			...tryGetInfo(result.info)
		};
		if (typeof result?.swagger === "string") return {
			version: `Swagger ${result.swagger}`,
			type: "yaml",
			...tryGetInfo(result.info)
		};
		return;
	} catch {}
}
//#endregion
export { getOpenApiDocumentDetails };

//# sourceMappingURL=getOpenApiDocumentDetails.js.map