From b7da1cf71b2696ba6f349b6141f4c6d1ab113f50 Mon Sep 17 00:00:00 2001 From: bidaya0 Date: Tue, 4 Jul 2023 18:00:15 +0800 Subject: [PATCH] doc: add tags to api extend_schema. --- dongtai_protocol/views/report_upload.py | 7 ---- dongtai_web/dongtai_sca/views/package.py | 10 +++++ dongtai_web/threshold/config_setting.py | 9 +++++ dongtai_web/views/vul_request_replay.py | 38 +++++++++++-------- static/i18n/views/setlang.py | 14 ++++--- .../debug/management/commands/check_schema.py | 5 ++- 6 files changed, 54 insertions(+), 29 deletions(-) diff --git a/dongtai_protocol/views/report_upload.py b/dongtai_protocol/views/report_upload.py index f021c2530..a40eaa38f 100644 --- a/dongtai_protocol/views/report_upload.py +++ b/dongtai_protocol/views/report_upload.py @@ -25,16 +25,9 @@ class ReportUploadEndPoint(OpenApiEndPoint): description = "agent上传报告" @extend_schema( - description='Pull Agent Engine Hook Rule', - parameters=[ - DongTaiParameter.LANGUAGE, - ], - responses=R, - methods=['GET'], summary="Agent 上传报告", tags=['Agent服务端交互协议'], ) - @csrf_exempt def post(self, request): try: report = parse_data(request.read()) diff --git a/dongtai_web/dongtai_sca/views/package.py b/dongtai_web/dongtai_sca/views/package.py index 8bc95a833..bf1dc510f 100644 --- a/dongtai_web/dongtai_sca/views/package.py +++ b/dongtai_web/dongtai_sca/views/package.py @@ -17,6 +17,11 @@ class PackageList(AnonymousAndUserEndPoint): + @extend_schema( + tags=[_('Component')], + summary="组件列表", + deprecated=True, + ) def get(self, request): filter_fields = ['hash', 'aql', 'ecosystem', 'name', 'version'] _filter = Package.objects.filter().order_by("-updated_at") @@ -54,6 +59,11 @@ class AssetAggrDetailAssetIds(UserEndPoint): name = "api-v1-sca-aggr-assets" description = "" + @extend_schema( + tags=[_('Component')], + summary="组件详情", + deprecated=True, + ) def get(self, request, aggr_id): try: auth_users = self.get_auth_users(request.user) diff --git a/dongtai_web/threshold/config_setting.py b/dongtai_web/threshold/config_setting.py index c8283a8d0..7a5a7a437 100644 --- a/dongtai_web/threshold/config_setting.py +++ b/dongtai_web/threshold/config_setting.py @@ -291,6 +291,9 @@ def create(self, request): config_create(ser.data, request.user) return R.success() + @extend_schema_with_envcheck( + summary=_('AgentThresholdConfig Detail'), + tags=[_('AgentThresholdConfigV2')]) def retrieve(self, request, pk): obj = IastCircuitConfig.objects.filter(pk=pk, is_deleted=0).values().first() @@ -304,6 +307,9 @@ def retrieve(self, request, pk): circuit_config_id=pk).values().all()) return R.success(data=obj) + @extend_schema_with_envcheck( + summary=_('AgentThresholdConfig List'), + tags=[_('AgentThresholdConfigV2')]) def list(self, request): # page = request.query_params.get('page', 1) # page_size = request.query_params.get("page_size", 10) @@ -388,6 +394,9 @@ def enum(self, request, enumname): return R.success(data=convert_choices_to_value_dict( able_to_search_dict.get(enumname))) + @extend_schema_with_envcheck( + summary=_('获取 AgentThresholdConfig 所有枚举'), + tags=[_('AgentThresholdConfigV2')]) def enumall(self, request): able_to_search = (TargetType, MetricType, MetricGroup, TargetOperator, MetricOperator, DealType, SystemMetricType, diff --git a/dongtai_web/views/vul_request_replay.py b/dongtai_web/views/vul_request_replay.py index aec1cb057..919052daa 100644 --- a/dongtai_web/views/vul_request_replay.py +++ b/dongtai_web/views/vul_request_replay.py @@ -167,12 +167,16 @@ def send_request_to_replay_queue(relation_id, agent_id, replay_request, return replay_queue.id @extend_schema_with_envcheck( - [], { + [], + { 'methodPoolId': 'int', 'replayRequest': 'str', 'agent_id': 'int', 'replay_type': 'int' - }) + }, + tags=['重放'], + summary="请求包重放", + ) def post(self, request): """ :param request:{ @@ -255,19 +259,23 @@ def parse_response(header, body): e))) return '{header}\n\n{body}'.format(header=_data, body=body) - @extend_schema_with_envcheck([ - { - 'name': "replayid", - 'type': int, - 'required': True, - }, - { - 'name': "replay_type", - 'type': int, - 'required': False, - 'description': "available options are (2,3)", - }, - ]) + @extend_schema_with_envcheck( + [ + { + 'name': "replayid", + 'type': int, + 'required': True, + }, + { + 'name': "replay_type", + 'type': int, + 'required': False, + 'description': "available options are (2,3)", + }, + ], + tags=['重放'], + summary="获取请求包重放详情", + ) def get(self, request): replay_id = request.query_params.get('replayId') # auth_agents = self.get_auth_agents_with_user(request.user) diff --git a/static/i18n/views/setlang.py b/static/i18n/views/setlang.py index c167cbdf8..5b95f7449 100644 --- a/static/i18n/views/setlang.py +++ b/static/i18n/views/setlang.py @@ -18,11 +18,15 @@ class LanguageSetting(AnonymousAndUserEndPoint): - @extend_schema_with_envcheck([{ - 'name': LANGUAGE_QUERY_PARAMETER, - 'type': str, - 'description': 'The options are (en,zh)' - }]) + @extend_schema_with_envcheck( + [{ + 'name': LANGUAGE_QUERY_PARAMETER, + 'type': str, + 'description': 'The options are (en,zh)' + }], + tags=['i18n'], + summary="切换语言", + ) def get(self, request): lang_code = request.GET.get(LANGUAGE_QUERY_PARAMETER) if lang_code not in ALLOWED_LANG_CODE: diff --git a/test/debug/management/commands/check_schema.py b/test/debug/management/commands/check_schema.py index 3af8db52e..ad5a09bfe 100644 --- a/test/debug/management/commands/check_schema.py +++ b/test/debug/management/commands/check_schema.py @@ -11,18 +11,19 @@ def handle(self, *args, **options): n = count(0) for view, schema in VIEW_CLASS_TO_SCHEMA.items(): for method, schema in schema.items(): - _, _, schema, filepath = schema + path, path_regex, schema, filepath = schema if schema is None: self.stdout.write(self.style.ERROR(f"No schema: {view}")) continue has_error = False + schema_field_check = {schema_field: schema_field in schema for schema_field in ("tags", "summary")} if not all(schema_field_check.values()): has_error = True missing_fields = [schema_field for schema_field, exists in schema_field_check.items()] self.stdout.write( self.style.ERROR( - f'[{next(n)}]Miss "{missing_fields}" schema: {method} {view} {filepath}' + f'[{next(n)}]Miss "{missing_fields}" schema: {method} {view} {filepath} {path} {path_regex}' ) ) if not has_error: