diff --git a/templates/zerver/api/upload-custom-emoji.md b/templates/zerver/api/upload-custom-emoji.md index b76dfa1b4e..e914c0459f 100644 --- a/templates/zerver/api/upload-custom-emoji.md +++ b/templates/zerver/api/upload-custom-emoji.md @@ -16,11 +16,7 @@ organization. Access to this endpoint depends on the {tab|curl} -``` curl -curl -X POST {{ api_url }}/v1/realm/emoji/{emoji_name} \ - -F "data=@/path/to/img.png" \ - -u USER_EMAIL:API_KEY -``` +{generate_code_example(curl)|/realm/emoji/{emoji_name}:post|example} {end_tabs} diff --git a/zerver/lib/bugdown/api_code_examples.py b/zerver/lib/bugdown/api_code_examples.py index 496c3d4858..df99315cd0 100644 --- a/zerver/lib/bugdown/api_code_examples.py +++ b/zerver/lib/bugdown/api_code_examples.py @@ -188,6 +188,11 @@ def generate_curl_example(endpoint: str, method: str, curl_argument=True) lines.append(example_value) + if "requestBody" in openapi_entry: + properties = openapi_entry["requestBody"]["content"]["multipart/form-data"]["schema"]["properties"] + for key, property in properties.items(): + lines.append(' -F "{}=@{}"'.format(key, property["example"])) + for i in range(1, len(lines)-1): lines[i] = lines[i] + " \\" diff --git a/zerver/openapi/test_curl_examples.py b/zerver/openapi/test_curl_examples.py index 13631012ac..e861899b78 100644 --- a/zerver/openapi/test_curl_examples.py +++ b/zerver/openapi/test_curl_examples.py @@ -35,6 +35,8 @@ exclude_list = [ 'remove-linkifiers.md', # Endpoint does not accept bot requests 'get-user-groups.md', + # Example files do not exist + 'upload-custom-emoji.md', ] def test_generated_curl_examples_for_success(client: Client) -> None: diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index bcf4705e61..efe7b81f73 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -1747,6 +1747,7 @@ paths: filename: type: string format: binary + example: /path/to/img.png security: - basicAuth: [] responses: