Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9348348
D1247.id3938.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D1247.id3938.diff
View Options
diff --git a/swh/web/api/apidoc.py b/swh/web/api/apidoc.py
--- a/swh/web/api/apidoc.py
+++ b/swh/web/api/apidoc.py
@@ -255,6 +255,9 @@
noargs (boolean): set to True if the route has no arguments, and its
result should be displayed anytime its documentation
is requested. Default to False
+ need_params (boolean): specify the route requires query parameters
+ otherwise errors will occur. It enables to avoid displaying the
+ invalid response in its HTML documentation. Default to False.
tags (list): Further information on api endpoints. Two values are
possibly expected:
@@ -267,12 +270,13 @@
api_version (str): api version string
"""
- def __init__(self, route, noargs=False, tags=[], handle_response=False,
- api_version='1'):
+ def __init__(self, route, noargs=False, need_params=False, tags=[],
+ handle_response=False, api_version='1'):
super().__init__()
self.route = route
self.urlpattern = '^' + api_version + route + '$'
self.noargs = noargs
+ self.need_params = need_params
self.tags = set(tags)
self.handle_response = handle_response
@@ -306,7 +310,11 @@
try:
response = f(request, **kwargs)
except Exception as exc:
- return error_response(request, exc, doc_data)
+ if request.accepted_media_type == 'text/html' and \
+ self.need_params and not request.query_params:
+ response = None
+ else:
+ return error_response(request, exc, doc_data)
if self.handle_response:
return response
diff --git a/swh/web/api/views/origin.py b/swh/web/api/views/origin.py
--- a/swh/web/api/views/origin.py
+++ b/swh/web/api/views/origin.py
@@ -229,7 +229,7 @@
@api_route(r'/origin/metadata-search/',
'api-origin-metadata-search')
-@api_doc('/origin/metadata-search/', noargs=True)
+@api_doc('/origin/metadata-search/', noargs=True, need_params=True)
def api_origin_metadata_search(request):
"""
.. http:get:: /api/1/origin/metadata-search/
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Jul 3 2025, 6:25 PM (5 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3219130
Attached To
D1247: [swh-web] apidoc: Add new decorator parameter for routes requiring query parameters
Event Timeline
Log In to Comment