UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

47 lines (46 loc) 1.68 kB
import { KindEnums } from "@apic/api-model/common/StudioEnums.js"; import { checkForNullOrUndefined, isNullOrUndefined, } from "../../common/data-helper.js"; import { showWarning } from "../../common/message-helper.js"; const addAssetRefValuesForPlanKind = (refObjects, kind, result) => { if (!isNullOrUndefined(refObjects)) { refObjects.forEach((endpoint) => { if (!isNullOrUndefined(endpoint.$ref)) { result.push({ kind, ref: endpoint.$ref, isNewlyAdded: true, }); } }); } }; const getRefsFromPlanAsset = (asset) => { const planAsset = asset; const spec = planAsset.spec; const result = []; try { checkForNullOrUndefined(planAsset, "Asset is null or undefined"); // withRateLimit check if (spec.qos) { if (Array.isArray(spec.qos["withRateLimit"])) { const requestLimitRefs = spec.qos["withRateLimit"].map((reqLimit) => ({ $ref: reqLimit.$ref || "", })); addAssetRefValuesForPlanKind(requestLimitRefs, KindEnums.RequestLimit, result); } // withQuota check if (spec.qos["withQuota"]) { const withQuota = spec.qos["withQuota"]; if (withQuota.$ref) { addAssetRefValuesForPlanKind([{ $ref: withQuota.$ref }], KindEnums.RequestLimit, result); } } } return result; } catch (error) { showWarning(error.message); return []; } }; export { getRefsFromPlanAsset };