2024-08-15 09:17:25 +00:00
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
"""
|
|
|
|
|
|
@project: MaxKB
|
|
|
|
|
|
@Author:虎
|
|
|
|
|
|
@file: function_lib_api.py
|
|
|
|
|
|
@date:2024/8/2 17:11
|
|
|
|
|
|
@desc:
|
|
|
|
|
|
"""
|
|
|
|
|
|
from drf_yasg import openapi
|
|
|
|
|
|
|
|
|
|
|
|
from common.mixins.api_mixin import ApiMixin
|
2025-01-13 03:15:51 +00:00
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-08-15 09:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FunctionLibApi(ApiMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_response_body_api():
|
|
|
|
|
|
return openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_OBJECT,
|
|
|
|
|
|
required=['id', 'name', 'desc', 'code', 'input_field_list', 'create_time',
|
|
|
|
|
|
'update_time'],
|
|
|
|
|
|
properties={
|
2025-01-13 03:15:51 +00:00
|
|
|
|
'id': openapi.Schema(type=openapi.TYPE_STRING, title="", description=_('ID')),
|
|
|
|
|
|
'name': openapi.Schema(type=openapi.TYPE_STRING, title=_('function name'),
|
|
|
|
|
|
description=_('function name')),
|
|
|
|
|
|
'desc': openapi.Schema(type=openapi.TYPE_STRING, title=_('function description'),
|
|
|
|
|
|
description=_('function description')),
|
|
|
|
|
|
'code': openapi.Schema(type=openapi.TYPE_STRING, title=_('function content'),
|
|
|
|
|
|
description=_('function content')),
|
|
|
|
|
|
'input_field_list': openapi.Schema(type=openapi.TYPE_STRING, title=_('input field'),
|
|
|
|
|
|
description=_('input field')),
|
|
|
|
|
|
'create_time': openapi.Schema(type=openapi.TYPE_STRING, title=_('create time'),
|
|
|
|
|
|
description=_('create time')),
|
|
|
|
|
|
'update_time': openapi.Schema(type=openapi.TYPE_STRING, title=_('update time'),
|
|
|
|
|
|
description=_('update time')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Query(ApiMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_params_api():
|
|
|
|
|
|
return [openapi.Parameter(name='name',
|
|
|
|
|
|
in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=False,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('function name')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
openapi.Parameter(name='desc',
|
|
|
|
|
|
in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=False,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('function description')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class Debug(ApiMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_body_api():
|
|
|
|
|
|
return openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_OBJECT,
|
|
|
|
|
|
required=[],
|
|
|
|
|
|
properties={
|
|
|
|
|
|
'debug_field_list': openapi.Schema(type=openapi.TYPE_ARRAY,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('Input variable list'),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
items=openapi.Schema(type=openapi.TYPE_OBJECT,
|
|
|
|
|
|
required=[],
|
|
|
|
|
|
properties={
|
|
|
|
|
|
'name': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('variable name'),
|
|
|
|
|
|
description=_('variable name')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
'value': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('variable value'),
|
|
|
|
|
|
description=_('variable value')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
})),
|
2025-01-13 03:15:51 +00:00
|
|
|
|
'code': openapi.Schema(type=openapi.TYPE_STRING, title=_('function content'),
|
|
|
|
|
|
description=_('function content')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
'input_field_list': openapi.Schema(type=openapi.TYPE_ARRAY,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('Input variable list'),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
items=openapi.Schema(type=openapi.TYPE_OBJECT,
|
|
|
|
|
|
required=['name', 'is_required', 'source'],
|
|
|
|
|
|
properties={
|
|
|
|
|
|
'name': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('variable name'),
|
|
|
|
|
|
description=_('variable name')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
'is_required': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_BOOLEAN,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('required'),
|
|
|
|
|
|
description=_('required')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
'type': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('type'),
|
|
|
|
|
|
description=_(
|
|
|
|
|
|
'Field type string|int|dict|array|float')
|
2024-08-15 09:17:25 +00:00
|
|
|
|
),
|
|
|
|
|
|
'source': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('source'),
|
|
|
|
|
|
description=_(
|
|
|
|
|
|
'The source only supports custom|reference')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Edit(ApiMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_body_api():
|
|
|
|
|
|
return openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_OBJECT,
|
|
|
|
|
|
required=[],
|
|
|
|
|
|
properties={
|
2025-01-13 03:15:51 +00:00
|
|
|
|
'name': openapi.Schema(type=openapi.TYPE_STRING, title=_('function name'),
|
|
|
|
|
|
description=_('function name')),
|
|
|
|
|
|
'desc': openapi.Schema(type=openapi.TYPE_STRING, title=_('function description'),
|
|
|
|
|
|
description=_('function description')),
|
|
|
|
|
|
'code': openapi.Schema(type=openapi.TYPE_STRING, title=_('function content'),
|
|
|
|
|
|
description=_('function content')),
|
|
|
|
|
|
'permission_type': openapi.Schema(type=openapi.TYPE_STRING, title=_('permission'),
|
|
|
|
|
|
description=_('permission')),
|
|
|
|
|
|
'is_active': openapi.Schema(type=openapi.TYPE_BOOLEAN, title=_('Is active'),
|
|
|
|
|
|
description=_('Is active')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
'input_field_list': openapi.Schema(type=openapi.TYPE_ARRAY,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('Input variable list'),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
items=openapi.Schema(type=openapi.TYPE_OBJECT,
|
|
|
|
|
|
required=[],
|
|
|
|
|
|
properties={
|
|
|
|
|
|
'name': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('variable name'),
|
|
|
|
|
|
description=_('variable name')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
'is_required': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_BOOLEAN,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('required'),
|
|
|
|
|
|
description=_('required')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
'type': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('type'),
|
|
|
|
|
|
description=_(
|
|
|
|
|
|
'Field type string|int|dict|array|float')
|
2024-08-15 09:17:25 +00:00
|
|
|
|
),
|
|
|
|
|
|
'source': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('source'),
|
|
|
|
|
|
description=_(
|
|
|
|
|
|
'The source only supports custom|reference')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Create(ApiMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_body_api():
|
|
|
|
|
|
return openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_OBJECT,
|
2024-09-14 07:30:22 +00:00
|
|
|
|
required=['name', 'code', 'input_field_list', 'permission_type'],
|
2024-08-15 09:17:25 +00:00
|
|
|
|
properties={
|
2025-01-13 03:15:51 +00:00
|
|
|
|
'name': openapi.Schema(type=openapi.TYPE_STRING, title=_('function name'),
|
|
|
|
|
|
description=_('function name')),
|
|
|
|
|
|
'desc': openapi.Schema(type=openapi.TYPE_STRING, title=_('function description'),
|
|
|
|
|
|
description=_('function description')),
|
|
|
|
|
|
'code': openapi.Schema(type=openapi.TYPE_STRING, title=_('function content'),
|
|
|
|
|
|
description=_('function content')),
|
|
|
|
|
|
'permission_type': openapi.Schema(type=openapi.TYPE_STRING, title=_('permission'),
|
|
|
|
|
|
description=_('permission')),
|
|
|
|
|
|
'is_active': openapi.Schema(type=openapi.TYPE_BOOLEAN, title=_('Is active'),
|
|
|
|
|
|
description=_('Is active')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
'input_field_list': openapi.Schema(type=openapi.TYPE_ARRAY,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('Input variable list'),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
items=openapi.Schema(type=openapi.TYPE_OBJECT,
|
|
|
|
|
|
required=['name', 'is_required', 'source'],
|
|
|
|
|
|
properties={
|
|
|
|
|
|
'name': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('variable name'),
|
|
|
|
|
|
description=_('variable name')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
'is_required': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_BOOLEAN,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('required'),
|
|
|
|
|
|
description=_('required')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
'type': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('type'),
|
|
|
|
|
|
description=_(
|
|
|
|
|
|
'Field type string|int|dict|array|float')
|
2024-08-15 09:17:25 +00:00
|
|
|
|
),
|
|
|
|
|
|
'source': openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('source'),
|
|
|
|
|
|
description=_(
|
|
|
|
|
|
'The source only supports custom|reference')),
|
2024-08-15 09:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|