@apistudio/apim-cli
Version:
CLI for API Management Products
37 lines (36 loc) • 1.45 kB
JavaScript
import { checkForNullOrUndefined } from "../helpers/common/data-helper.js";
import { showWarning } from "../helpers/common/message-helper.js";
import { KindEnums } from "@apic/api-model/common/StudioEnums.js";
const getRefsFromApiAsset = (asset) => {
const apiAsset = asset;
const dependentAssets = [];
const dependentPolicySequenceAssets = checkPolicySequence(apiAsset);
dependentAssets.push(...dependentPolicySequenceAssets);
return dependentAssets;
};
const getAPIDefPath = (asset) => {
const apiAsset = asset;
const spec = checkForNullOrUndefined(apiAsset.spec, `Spec is not defined for the asset with kind 'API' and name '${apiAsset.metadata?.name}'`);
const apiSpec = checkForNullOrUndefined(spec["api-spec"], `Attribute 'api-spec' is not defined
for kind 'API' and name '${apiAsset.metadata?.name}'`);
return apiSpec.$path;
};
const checkPolicySequence = (apiAsset) => {
let spec = null;
try {
spec = checkForNullOrUndefined(apiAsset.spec, `Spec is not defined for the asset with kind 'API' and name '${apiAsset.metadata?.name}'`);
}
catch (error) {
showWarning(error.message);
return [];
}
const policySeq = spec["policy-sequence"];
return policySeq.map((pSeq) => {
return {
kind: KindEnums.PolicySequence,
ref: pSeq.$ref,
isNewlyAdded: true,
};
});
};
export { getRefsFromApiAsset, getAPIDefPath };