feat(apifox): 为接口查询方法添加projectId参数支持

允许在查询接口详情时指定项目ID,提高多项目环境下的灵活性
This commit is contained in:
zhangguoyun committed 2025-12-02 16:53:17 +08:00
1 parent ae684d83b1
commit 4386beea66
2 files changed
+14 -6

No files matched your search

+8 -2
View File
@@ -276,7 +276,10 @@ export class ApifoxService {
};
}
async getApiDetailByPath(path) {
async getApiDetailByPath(path, projectId) {
if (projectId) {
this.projectId = projectId;
}
const apiDetails = await this.getApiDetails();
const apiDetail = apiDetails.find((item) => item.path === path);
if (!apiDetail) {
@@ -285,7 +288,10 @@ export class ApifoxService {
return this.getApiDetailResp(apiDetail);
}
async getApiDetailsById(apiId) {
async getApiDetailsById(apiId, projectId) {
if (projectId) {
this.projectId = projectId;
}
const apiDetails = await this.getApiDetails();
const apiDetail = apiDetails.find((item) => item.id === apiId);
if (!apiDetail) {
+6 -4
View File
@@ -32,13 +32,14 @@ server.registerTool(
description: "根据接口path获取Apifox接口定义数据",
inputSchema: z.object({
path: z.string().describe("接口路径"),
projectId: z.number().optional().describe("Apifox项目ID"),
}),
},
async ({ path }) => {
async ({ path, projectId }) => {
try {
const apiData = await apifoxService.getApiDetailByPath(path);
const apiData = await apifoxService.getApiDetailByPath(path, projectId);
return {
content: [
@@ -68,13 +69,14 @@ server.registerTool(
description: "根据接口目录获取Apifox目录下所有接口定义数据",
inputSchema: z.object({
folderName: z.string().describe("接口路径"),
projectId: z.number().optional().describe("Apifox项目ID"),
}),
},
async ({ folderName }) => {
async ({ folderName, projectId }) => {
try {
const apiData = await apifoxService.getApiListByFolderName(folderName);
const apiData = await apifoxService.getApiListByFolderName(folderName, projectId);
return {
content: [