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 @@ -3,7 +3,7 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information - +from collections import defaultdict import functools from functools import wraps import os @@ -50,10 +50,8 @@ status_code_roles = ('statuscode', 'status', 'code') - def __init__(self, document, urls, data): + def __init__(self, document, data): super().__init__(document) - self.urls = urls - self.url_idx = 0 self.data = data self.args_set = set() self.params_set = set() @@ -192,15 +190,6 @@ text not in self.data['description']): self.data['description'] += '\n\n' if self.data['description'] else '' # noqa self.data['description'] += text - # http methods - elif text.startswith('**Allowed HTTP Methods:**'): - text = text.replace('**Allowed HTTP Methods:**', '') - http_methods = text.strip().split(',') - http_methods = [m[m.find('`')+1:-1].upper() - for m in http_methods] - self.data['urls'].append({'rule': self.urls[self.url_idx], - 'methods': http_methods}) - self.url_idx += 1 def visit_literal_block(self, node): """ @@ -243,17 +232,6 @@ def unknown_visit(self, node): pass - def depart_document(self, node): - """ - End of parsing extra processing - """ - default_methods = ['GET', 'HEAD', 'OPTIONS'] - # ensure urls info is present and set default http methods - if not self.data['urls']: - for url in self.urls: - self.data['urls'].append({'rule': url, - 'methods': default_methods}) - def unknown_departure(self, node): pass @@ -261,7 +239,8 @@ def _parse_httpdomain_doc(doc, data): doc_lines = doc.split('\n') doc_lines_filtered = [] - urls = [] + urls = defaultdict(list) + default_http_methods = ['HEAD', 'OPTIONS'] # httpdomain is a sphinx extension that is unknown to docutils but # fortunately we can still parse its directives' content, # so remove lines with httpdomain directives before executing the @@ -273,7 +252,12 @@ url = doc_line[doc_line.find('/'):] # emphasize url arguments for html rendering url = re.sub(r'\((\w+)\)', r' **\(\1\)** ', url) - urls.append(url) + method = re.search(r'http:(\w+)::', doc_line).group(1) + urls[url].append(method.upper()) + + for url, methods in urls.items(): + data['urls'].append({'rule': url, + 'methods': methods + default_http_methods}) # parse the rst docstring and do not print system messages about # unknown httpdomain roles document = parse_rst('\n'.join(doc_lines_filtered), report_level=5) @@ -281,7 +265,7 @@ for node in document.traverse(docutils.nodes.system_message): node.parent.remove(node) # visit the document nodes to extract relevant endpoint info - visitor = _HTTPDomainDocVisitor(document, urls, data) + visitor = _HTTPDomainDocVisitor(document, data) document.walkabout(visitor) diff --git a/swh/web/api/views/content.py b/swh/web/api/views/content.py --- a/swh/web/api/views/content.py +++ b/swh/web/api/views/content.py @@ -42,8 +42,6 @@ {common_headers} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **hash_type** or **hash** has been provided :statuscode 404: requested content can not be found in the archive @@ -88,8 +86,6 @@ {common_headers} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **hash_type** or **hash** has been provided :statuscode 404: requested content can not be found in the archive @@ -132,8 +128,6 @@ {common_headers} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **hash_type** or **hash** has been provided :statuscode 404: requested content can not be found in the archive @@ -185,8 +179,6 @@ :resheader Content-Type: application/octet-stream - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **hash_type** or **hash** has been provided :statuscode 404: requested content can not be found in the archive @@ -279,8 +271,6 @@ :>json object search_stats: some statistics regarding the number of **sha1** provided and the percentage of those found in the archive - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **sha1** has been provided @@ -365,8 +355,6 @@ :>json string license_url: link to :http:get:`/api/1/content/[(hash_type):](hash)/license/` for getting information about the license of the content - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **hash_type** or **hash** has been provided :statuscode 404: requested content can not be found in the archive diff --git a/swh/web/api/views/directory.py b/swh/web/api/views/directory.py --- a/swh/web/api/views/directory.py +++ b/swh/web/api/views/directory.py @@ -49,8 +49,6 @@ or :http:get:`/api/1/directory/(sha1_git)/[(path)/]` depending on the directory entry type :>jsonarr string type: the type of the directory entry, can be either ``dir``, ``file`` or ``rev`` - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **hash_type** or **hash** has been provided :statuscode 404: requested directory can not be found in the archive diff --git a/swh/web/api/views/identifiers.py b/swh/web/api/views/identifiers.py --- a/swh/web/api/views/identifiers.py +++ b/swh/web/api/views/identifiers.py @@ -39,8 +39,6 @@ {common_headers} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid persistent identifier has been provided :statuscode 404: the pointed object does not exist in the archive 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 @@ -75,9 +75,6 @@ {common_headers} {resheader_link} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error **Example:** @@ -122,9 +119,6 @@ {common_headers} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 404: requested origin can not be found in the archive @@ -179,9 +173,6 @@ {common_headers} {resheader_link} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error **Example:** @@ -241,9 +232,6 @@ {common_headers} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error **Example:** @@ -290,9 +278,6 @@ {return_origin_visit_array} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 404: requested origin can not be found in the archive @@ -377,9 +362,6 @@ {return_origin_visit} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 404: requested origin or visit can not be found in the archive @@ -419,9 +401,6 @@ {return_origin_visit} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 404: requested origin or visit can not be found in the archive @@ -458,9 +437,6 @@ {common_headers} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 404: requested origin can not be found in the archive diff --git a/swh/web/api/views/origin_save.py b/swh/web/api/views/origin_save.py --- a/swh/web/api/views/origin_save.py +++ b/swh/web/api/views/origin_save.py @@ -68,9 +68,6 @@ either **not created**, **not yet scheduled**, **scheduled**, **succeed** or **failed** - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`post`, - :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid visit type or origin url has been provided :statuscode 403: the provided origin url is blacklisted diff --git a/swh/web/api/views/release.py b/swh/web/api/views/release.py --- a/swh/web/api/views/release.py +++ b/swh/web/api/views/release.py @@ -39,9 +39,6 @@ :>json string target_url: a link to the adequate api url based on the target type - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **sha1_git** value has been provided :statuscode 404: requested release can not be found in the archive diff --git a/swh/web/api/views/revision.py b/swh/web/api/views/revision.py --- a/swh/web/api/views/revision.py +++ b/swh/web/api/views/revision.py @@ -94,9 +94,6 @@ {return_revision} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **sha1_git** value has been provided :statuscode 404: requested revision can not be found in the archive @@ -156,9 +153,6 @@ :>json string revision: the unique revision identifier :>json string type: the type of the directory - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **sha1_git** value has been provided :statuscode 404: requested revision can not be found in the archive @@ -198,9 +192,6 @@ {return_revision_array} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid **sha1_git** value has been provided :statuscode 404: requested revision can not be found in the archive diff --git a/swh/web/api/views/snapshot.py b/swh/web/api/views/snapshot.py --- a/swh/web/api/views/snapshot.py +++ b/swh/web/api/views/snapshot.py @@ -54,9 +54,6 @@ given but also a link to get information about that target :>json string id: the unique identifier of the snapshot - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid snapshot identifier has been provided :statuscode 404: requested snapshot can not be found in the archive diff --git a/swh/web/api/views/stat.py b/swh/web/api/views/stat.py --- a/swh/web/api/views/stat.py +++ b/swh/web/api/views/stat.py @@ -39,9 +39,6 @@ {common_headers} - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error **Example:** diff --git a/swh/web/api/views/vault.py b/swh/web/api/views/vault.py --- a/swh/web/api/views/vault.py +++ b/swh/web/api/views/vault.py @@ -79,9 +79,6 @@ (either **new**, **pending**, **done** or **failed**) :>json string obj_id: the identifier of the object to cook - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`post`, - :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid directory identifier has been provided :statuscode 404: requested directory did not receive any cooking @@ -114,9 +111,6 @@ :resheader Content-Type: application/octet-stream - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid directory identifier has been provided :statuscode 404: requested directory did not receive any cooking @@ -181,9 +175,6 @@ :>json string status: the cooking task status (new/pending/done/failed) :>json string obj_id: the identifier of the object to cook - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`post`, - :http:method:`head`, :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid revision identifier has been provided :statuscode 404: requested directory did not receive any cooking @@ -216,9 +207,6 @@ :resheader Content-Type: application/octet-stream - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head`, - :http:method:`options` - :statuscode 200: no error :statuscode 400: an invalid revision identifier has been provided :statuscode 404: requested directory did not receive any cooking diff --git a/swh/web/tests/api/test_apidoc.py b/swh/web/tests/api/test_apidoc.py --- a/swh/web/tests/api/test_apidoc.py +++ b/swh/web/tests/api/test_apidoc.py @@ -59,8 +59,6 @@ about it :>json string type: the type of the revision - **Allowed HTTP Methods:** :http:method:`get`, :http:method:`head` - :statuscode 200: no error :statuscode 400: an invalid **sha1_git** value has been provided :statuscode 404: requested revision can not be found in the archive @@ -199,7 +197,7 @@ expected_urls = [{ 'rule': '/api/1/revision/ **\\(sha1_git\\)** /', - 'methods': ['GET', 'HEAD'] + 'methods': ['GET', 'HEAD', 'OPTIONS'] }] assert 'urls' in doc_data