@alova/wormhole
Version:
More modern openAPI generating solution for alova.js
56 lines (55 loc) • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.apifox = apifox;
function apifox({ projectId, locale = 'zh-CN', apifoxVersion = '2024-03-28', scopeType = 'ALL', selectedEndpointIds = [], selectedTags = [], selectedFolderIds = [], excludedByTags = [], apifoxToken, oasVersion = '3.0', exportFormat = 'JSON', includeApifoxExtensionProperties = false, addFoldersToTags = false, environmentIds, branchId, moduleId, }) {
const body = {
scope: {
type: scopeType,
excludedByTags,
},
options: {
includeApifoxExtensionProperties,
addFoldersToTags,
},
oasVersion,
exportFormat,
environmentIds,
branchId,
moduleId,
};
// 根据不同的 scope 类型设置相应的参数
switch (scopeType) {
case 'ALL':
// 导出全部不需要额外参数
break;
case 'SELECTED_ENDPOINTS':
body.scope.selectedEndpointIds = selectedEndpointIds;
break;
case 'SELECTED_TAGS':
body.scope.selectedTags = selectedTags;
break;
case 'SELECTED_FOLDERS':
body.scope.selectedFolderIds = selectedFolderIds;
break;
}
return {
name: 'apifox',
config(config) {
const base = 'https://api.apifox.com/v1/projects';
if (projectId && apifoxToken) {
config.input = `${base}/${encodeURIComponent(projectId)}/export-openapi?locale=${encodeURIComponent(locale)}`;
config.fetchOptions = {
...config.fetchOptions,
headers: {
'X-Apifox-Api-Version': apifoxVersion,
'Authorization': `Bearer ${apifoxToken}`,
},
method: 'POST',
data: body,
};
}
return config;
},
};
}
exports.default = apifox;