From 26ac3ebd3e6187a86717603db3c007d821b9913f Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 7 Aug 2019 14:25:41 +0530 Subject: [PATCH] openapi: Suggest the -sS options to curl. These options prevent curl from doing the downloading progress bar (which is clutter). --- zerver/lib/bugdown/api_code_examples.py | 7 ++++--- zerver/lib/bugdown/fenced_code.py | 2 +- zerver/tests/test_openapi.py | 14 +++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/zerver/lib/bugdown/api_code_examples.py b/zerver/lib/bugdown/api_code_examples.py index 83f1792c9d..66208d4bad 100644 --- a/zerver/lib/bugdown/api_code_examples.py +++ b/zerver/lib/bugdown/api_code_examples.py @@ -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) diff --git a/zerver/lib/bugdown/fenced_code.py b/zerver/lib/bugdown/fenced_code.py index 6c85db5ec3..437bd134e9 100644 --- a/zerver/lib/bugdown/fenced_code.py +++ b/zerver/lib/bugdown/fenced_code.py @@ -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())) diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py index 4f0826bc03..b22f91402e 100644 --- a/zerver/tests/test_openapi.py +++ b/zerver/tests/test_openapi.py @@ -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' \\",