openapi: Suggest the -sS options to curl.

These options prevent curl from doing the downloading progress bar
(which is clutter).
This commit is contained in:
Tim Abbott 2019-08-07 14:25:41 +05:30
parent 2366490ffc
commit 26ac3ebd3e
3 changed files with 12 additions and 11 deletions

View File

@ -105,16 +105,17 @@ def render_python_code_example(function: str, admin_config: Optional[bool]=False
def curl_method_arguments(endpoint: str, method: str,
api_url: str) -> List[str]:
# We also include the -sS verbosity arguments here.
method = method.upper()
url = "{}/v1{}".format(api_url, endpoint)
valid_methods = ["GET", "POST", "DELETE", "PUT", "PATCH", "OPTIONS"]
if method == valid_methods[0]:
if method == "GET":
# Then we need to make sure that each -d option translates to becoming
# a GET parameter (in the URL) and not a POST parameter (in the body).
# TODO: remove the -X part by updating the linting rule. It's redundant.
return ["-X", "GET", "-G", url]
return ["-sSX", "GET", "-G", url]
elif method in valid_methods:
return ["-X", method, url]
return ["-sSX", method, url]
else:
msg = "The request method {} is not one of {}".format(method,
valid_methods)

View File

@ -116,7 +116,7 @@ Missing required -X argument in curl command:
""".strip()
for line in lines:
regex = r'curl [-]X "?(GET|DELETE|PATCH|POST)"?'
regex = r'curl [-](sS)?X "?(GET|DELETE|PATCH|POST)"?'
if line.startswith('curl'):
if re.search(regex, line) is None:
raise BugdownRenderingException(error_msg.format(command=line.strip()))

View File

@ -703,7 +703,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
generated_curl_example = self.curl_example("/get_stream_id", "GET")
expected_curl_example = [
"```curl",
"curl -X GET -G http://localhost:9991/api/v1/get_stream_id \\",
"curl -sSX GET -G http://localhost:9991/api/v1/get_stream_id \\",
" -u BOT_EMAIL_ADDRESS:BOT_API_KEY \\",
" -d 'stream=Denmark'",
"```"
@ -720,7 +720,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
generated_curl_example = self.curl_example("/dev_fetch_api_key", "POST")
expected_curl_example = [
"```curl",
"curl -X POST http://localhost:9991/api/v1/dev_fetch_api_key \\",
"curl -sSX POST http://localhost:9991/api/v1/dev_fetch_api_key \\",
" -d 'username=iago@zulip.com'",
"```"
]
@ -732,7 +732,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
generated_curl_example = self.curl_example("/mark_stream_as_read", "POST")
expected_curl_example = [
"```curl",
"curl -X POST http://localhost:9991/api/v1/mark_stream_as_read \\",
"curl -sSX POST http://localhost:9991/api/v1/mark_stream_as_read \\",
" -d 'stream_id=1' \\",
" -d 'bool_param=false'",
"```"
@ -749,7 +749,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
generated_curl_example = self.curl_example("/messages", "GET")
expected_curl_example = [
'```curl',
'curl -X GET -G http://localhost:9991/api/v1/messages \\',
'curl -sSX GET -G http://localhost:9991/api/v1/messages \\',
' -u BOT_EMAIL_ADDRESS:BOT_API_KEY \\',
" -d 'anchor=42' \\",
" -d 'use_first_unread_anchor=true' \\",
@ -768,7 +768,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
generated_curl_example = self.curl_example("/endpoint", "GET")
expected_curl_example = [
'```curl',
'curl -X GET -G http://localhost:9991/api/v1/endpoint \\',
'curl -sSX GET -G http://localhost:9991/api/v1/endpoint \\',
' --data-urlencode param1=\'{"key": "value"}\'',
'```'
]
@ -791,7 +791,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
api_url="https://zulip.example.com/api")
expected_curl_example = [
"```curl",
"curl -X GET -G https://zulip.example.com/api/v1/get_stream_id \\",
"curl -sSX GET -G https://zulip.example.com/api/v1/get_stream_id \\",
" -u email:key \\",
" -d 'stream=Denmark'",
"```"
@ -803,7 +803,7 @@ class TestCurlExampleGeneration(ZulipTestCase):
exclude=["client_gravatar", "apply_markdown"])
expected_curl_example = [
'```curl',
'curl -X GET -G http://localhost:9991/api/v1/messages \\',
'curl -sSX GET -G http://localhost:9991/api/v1/messages \\',
' -u BOT_EMAIL_ADDRESS:BOT_API_KEY \\',
" -d 'anchor=42' \\",
" -d 'use_first_unread_anchor=true' \\",