Skip to content

Commit

Permalink
doc: add tags to api extend_schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bidaya0 committed Jul 4, 2023
1 parent 0685399 commit b7da1cf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 29 deletions.
7 changes: 0 additions & 7 deletions dongtai_protocol/views/report_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions dongtai_web/dongtai_sca/views/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions dongtai_web/threshold/config_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
38 changes: 23 additions & 15 deletions dongtai_web/views/vul_request_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:{
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions static/i18n/views/setlang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions test/debug/management/commands/check_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b7da1cf

Please sign in to comment.