import yaml from "js-yaml";
import { v4 } from "uuid";
export const OPERATION_PATH_MERGE_DELIMITER = ">";
export const OPEN_API_FILE_TYPES = [".json", ".yml", ".yaml"];
export const parseOpenApiFile = async (extName, fileText) => {
    if (!OPEN_API_FILE_TYPES.includes(extName)) {
        throw new Error(`Invalid file type. Supported file types are: ${OPEN_API_FILE_TYPES.join(", ")}`);
    }
    if (extName.includes("json")) {
        return JSON.parse(fileText);
    }
    return yaml.load(fileText);
};
export const addOperationIdsAsNecessary = (openApi) => {
    const paths = openApi.paths;
    if (!paths) {
        return;
    }
    for (const path of Object.keys(paths)) {
        const pathItem = paths[path];
        if (!pathItem) {
            continue;
        }
        const methods = [
            "get",
            "put",
            "post",
            "delete",
            "options",
            "head",
            "patch",
            "trace",
        ];
        for (const method of methods) {
            const operation = pathItem[method];
            if (operation && !operation.operationId) {
                operation.operationId = v4();
            }
        }
    }
};
//# sourceMappingURL=utils.js.map