api: Document POST ../messages/{message_id}/reactions endpoint.

This refactors add_reaction in python_examples.py to use the
openapi_test_function decorator and validate result with
validate_against_openapi_schema. Minor changes have been made to the
OpenAPI format data for /messages/{message_id}/reactions endpoint.

This also adds add-emoji.md to templates/zerver/api and adds
add-emoji to rest-endpoints.md (templates/zerver/help/include).
This commit is contained in:
akashaviator
2020-02-29 19:32:34 +05:30
committed by Tim Abbott
parent 9c63976da5
commit 5dd1a1fc83
4 changed files with 73 additions and 20 deletions

View File

@@ -0,0 +1,32 @@
# Add an emoji reaction
Add an [emoji reaction](/help/emoji-reactions) to a message.
`POST {{ api_url }}/v1/messages/{message_id}/reactions`
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages/{message_id}/reactions:post|example}
{tab|curl}
{generate_code_example(curl, exclude=["emoji_code","reaction_type"])|/messages/{message_id}/reactions:post|example}
{end_tabs}
## Arguments
{generate_api_arguments_table|zulip.yaml|/messages/{message_id}/reactions:post}
## Response
#### Example response
A typical successful JSON response may look like:
{generate_code_example|/messages/{message_id}/reactions:post|fixture(200)}

View File

@@ -4,6 +4,7 @@
* [Get a raw message](/api/get-raw-message) * [Get a raw message](/api/get-raw-message)
* [Send a message](/api/send-message) * [Send a message](/api/send-message)
* [Update a message](/api/update-message) * [Update a message](/api/update-message)
* [Add an emoji reaction](/api/add-emoji-reaction)
* [Render a message](/api/render-message) * [Render a message](/api/render-message)
* [Upload a file](/api/upload-file) * [Upload a file](/api/upload-file)
* [Delete a message](/api/delete-message) * [Delete a message](/api/delete-message)

View File

@@ -698,25 +698,26 @@ def send_message(client):
return message_id return message_id
@openapi_test_function("/messages/{message_id}/reactions:post")
def add_reaction(client, message_id): def add_reaction(client, message_id):
# type: (Client, int) -> None # type: (Client, int) -> None
# {code_example|start}
# Add an emoji reaction
request = { request = {
'message_id': str(message_id), 'message_id': str(message_id),
'emoji_name': 'joy', 'emoji_name': 'octopus',
'emoji_code': '1f602',
'emoji_type': 'unicode_emoji'
} }
result = client.add_reaction(request)
assert result['result'] == 'success' result = client.add_reaction(request)
# {code_example|end}
validate_against_openapi_schema(result, '/messages/{message_id}/reactions', 'post', '200')
@openapi_test_function("/messages/{message_id}/reactions:delete") @openapi_test_function("/messages/{message_id}/reactions:delete")
def remove_reaction(client, message_id): def remove_reaction(client, message_id):
# type: (Client, int) -> None # type: (Client, int) -> None
request = { request = {
'message_id': str(message_id), 'message_id': str(message_id),
'emoji_name': 'joy', 'emoji_name': 'octopus',
'emoji_code': '1f602',
'reaction_type': 'unicode_emoji' 'reaction_type': 'unicode_emoji'
} }

View File

@@ -845,17 +845,26 @@ paths:
you want, and note that emoji's text name. you want, and note that emoji's text name.
schema: schema:
type: string type: string
example: '**:slight smile:**' example: 'octopus'
required: true required: true
- name: emoji_code - name: emoji_code
in: query in: query
description: | description: |
An encoded version of the unicode codepoint. Used only An encoded version of the unicode codepoint. For
in rare corner cases to consolidate identical reactions most clients, you won't need this; it's used to
to the same emoji name. handle a rare corner case when upvoting a unicode
emoji reaction added previously by another user.
If the existing reaction was added when the Zulip
server was using a previous version of the emoji
data mapping from codepoints to human-readable
names, sending the `emoji_code` in the data for
the original reaction allows the Zulip server to
correctly consider your upvote as an upvote
rather than a reaction with a "diffenent" emoji.
schema: schema:
type: string type: string
example: '**foo**' example: '1f419'
required: false required: false
- name: reaction_type - name: reaction_type
in: query in: query
@@ -864,7 +873,7 @@ paths:
set `reaction_type` to `realm_emoji`. set `reaction_type` to `realm_emoji`.
schema: schema:
type: string type: string
example: '**realm_emoji**' example: 'unicode_emoji'
required: false required: false
responses: responses:
'200': '200':
@@ -874,16 +883,26 @@ paths:
schema: schema:
allOf: allOf:
- $ref: '#/components/schemas/JsonSuccess' - $ref: '#/components/schemas/JsonSuccess'
- properties:
rendered:
type: string
description: The rendered HTML.
- example: - example:
{ {
"msg": "", "result": "success",
"rendered": "<p><strong>foo</strong></p>", "msg": ""
"result": "success"
} }
'400':
description: Bad request.
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/CodedError'
- example:
{
"result": "error",
"msg": "Invalid emoji code",
"code": "BAD_REQUEST"
}
delete: delete:
description: Delete an emoji reaction from a message. description: Delete an emoji reaction from a message.
parameters: parameters: