2020-02-21 16:25:10 +00:00
|
|
|
"""OpenAPI core templating paths util module"""
|
2018-07-28 22:51:36 +00:00
|
|
|
from six.moves.urllib.parse import urlparse
|
2018-07-15 21:19:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def is_absolute(url):
|
|
|
|
return url.startswith('//') or '://' in url
|
|
|
|
|
|
|
|
|
|
|
|
def path_qs(url):
|
|
|
|
pr = urlparse(url)
|
|
|
|
result = pr.path
|
|
|
|
if pr.query:
|
|
|
|
result += '?' + pr.query
|
|
|
|
return result
|
2018-04-17 12:38:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_operation_pattern(server_url, request_url_pattern):
|
|
|
|
"""Return an updated request URL pattern with the server URL removed."""
|
|
|
|
if server_url[-1] == "/":
|
|
|
|
# operations have to start with a slash, so do not remove it
|
|
|
|
server_url = server_url[:-1]
|
2018-07-15 21:19:36 +00:00
|
|
|
if is_absolute(server_url):
|
2018-04-17 12:38:23 +00:00
|
|
|
return request_url_pattern.replace(server_url, "", 1)
|
2018-07-15 21:19:36 +00:00
|
|
|
return path_qs(request_url_pattern).replace(server_url, "", 1)
|