2025-04-16 04:50:44 +00:00
|
|
|
# coding=utf-8
|
2025-04-18 08:04:58 +00:00
|
|
|
from drf_spectacular.types import OpenApiTypes
|
|
|
|
|
from drf_spectacular.utils import OpenApiParameter
|
2025-04-16 04:50:44 +00:00
|
|
|
|
|
|
|
|
from common.mixins.api_mixin import APIMixin
|
2025-04-18 11:10:45 +00:00
|
|
|
from common.result import ResultSerializer, DefaultResultSerializer
|
2025-05-14 06:35:13 +00:00
|
|
|
from tools.serializers.tool import ToolModelSerializer, ToolCreateRequest, ToolDebugRequest, ToolEditRequest, \
|
|
|
|
|
PylintInstance
|
2025-04-16 04:50:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolCreateResponse(ResultSerializer):
|
|
|
|
|
def get_data(self):
|
|
|
|
|
return ToolModelSerializer()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolCreateAPI(APIMixin):
|
2025-04-18 08:04:58 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
2025-04-16 04:50:44 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return ToolCreateRequest
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return ToolCreateResponse
|
2025-04-18 08:04:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolReadAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="tool_id",
|
|
|
|
|
description="工具id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return ToolCreateResponse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolEditAPI(ToolReadAPI):
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
2025-04-23 03:34:19 +00:00
|
|
|
return ToolEditRequest
|
2025-04-18 08:04:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolDeleteAPI(ToolReadAPI):
|
2025-04-18 11:10:45 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
2025-04-18 09:46:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolTreeReadAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
2025-04-28 02:39:23 +00:00
|
|
|
name="folder_id",
|
|
|
|
|
description="文件夹id",
|
2025-04-18 09:46:20 +00:00
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='query',
|
2025-04-21 02:45:04 +00:00
|
|
|
required=False,
|
2025-04-18 09:46:20 +00:00
|
|
|
)
|
|
|
|
|
]
|
2025-04-22 06:24:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolDebugApi(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return ToolDebugRequest
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolExportAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="tool_id",
|
|
|
|
|
description="工具id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolImportAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
2025-05-08 02:42:00 +00:00
|
|
|
|
2025-04-22 06:24:44 +00:00
|
|
|
]
|
|
|
|
|
|
2025-05-08 02:42:00 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return {
|
|
|
|
|
'multipart/form-data': {
|
|
|
|
|
'type': 'object',
|
|
|
|
|
'properties': {
|
|
|
|
|
'file': {
|
|
|
|
|
'type': 'string',
|
|
|
|
|
'format': 'binary' # Tells Swagger it's a file
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 06:24:44 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolPageAPI(ToolReadAPI):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="current_page",
|
|
|
|
|
description="当前页码",
|
|
|
|
|
type=OpenApiTypes.INT,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="page_size",
|
|
|
|
|
description="每页大小",
|
|
|
|
|
type=OpenApiTypes.INT,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
2025-04-22 09:34:19 +00:00
|
|
|
OpenApiParameter(
|
2025-04-28 02:39:23 +00:00
|
|
|
name="folder_id",
|
|
|
|
|
description="文件夹id",
|
2025-04-22 09:34:19 +00:00
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='query',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
2025-05-15 03:02:41 +00:00
|
|
|
OpenApiParameter(
|
|
|
|
|
name="user_id",
|
|
|
|
|
description="创建者id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='query',
|
|
|
|
|
required=False,
|
|
|
|
|
),
|
2025-04-22 09:34:19 +00:00
|
|
|
OpenApiParameter(
|
2025-06-05 08:27:54 +00:00
|
|
|
name="scope",
|
2025-04-22 09:34:19 +00:00
|
|
|
description="工具类型",
|
|
|
|
|
type=OpenApiTypes.STR,
|
2025-06-05 08:27:54 +00:00
|
|
|
enum=["SHARED", "WORKSPACE"],
|
2025-04-22 09:34:19 +00:00
|
|
|
location='query',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
2025-04-22 06:24:44 +00:00
|
|
|
OpenApiParameter(
|
|
|
|
|
name="name",
|
|
|
|
|
description="工具名称",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='query',
|
|
|
|
|
required=False,
|
|
|
|
|
),
|
|
|
|
|
]
|
2025-05-14 06:35:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class PylintAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
2025-06-04 03:09:58 +00:00
|
|
|
|
2025-05-14 06:35:13 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return PylintInstance
|
2025-06-04 11:00:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class EditIconAPI(APIMixin):
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_parameters():
|
|
|
|
|
return [
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
OpenApiParameter(
|
|
|
|
|
name="tool_id",
|
|
|
|
|
description="工具id",
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
location='path',
|
|
|
|
|
required=True,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_request():
|
|
|
|
|
return {
|
|
|
|
|
'multipart/form-data': {
|
|
|
|
|
'type': 'object',
|
|
|
|
|
'properties': {
|
|
|
|
|
'icon': {
|
|
|
|
|
'type': 'string',
|
|
|
|
|
'format': 'binary' # Tells Swagger it's a file
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_response():
|
|
|
|
|
return DefaultResultSerializer
|