api_docs: Migrate POST /zulip-outgoing-webhook.

This commit migrates zulip outging webhook payload to
/zulip-outgoing-webhook:post in OpenAPI.

Since this migrates the last payloads from api/fixtures.json to
OpenAPI, this commit removes api/fixtures.json file and the functions
accessing the file.

Tweaked by tabbott to further remove an unnecessary conditional.
This commit is contained in:
shubhamgupta2956 2020-04-02 07:12:59 +05:30 committed by Tim Abbott
parent 6ebf408fc4
commit 793c3f25e7
6 changed files with 78 additions and 57 deletions

View File

@ -1,36 +0,0 @@
{
"zulip-outgoing-webhook-payload": {
"data": "@**Outgoing Webhook Test** Zulip is the world\u2019s most productive group chat!",
"trigger": "mention",
"token": "xvOzfurIutdRRVLzpXrIIHXJvNfaJLJ0",
"message": {
"subject": "Verona2",
"sender_email": "iago@zulip.com",
"timestamp": 1527876931,
"client": "website",
"submessages": [
],
"recipient_id": 20,
"topic_links": [
],
"sender_full_name": "Iago",
"avatar_url": "https://secure.gravatar.com/avatar/1f4f1575bf002ae562fea8fc4b861b09?d=identicon&version=1",
"rendered_content": "<p><span class=\"user-mention\" data-user-id=\"25\">@Outgoing Webhook Test</span> Zulip is the world\u2019s most productive group chat!</p>",
"sender_id": 5,
"stream_id": 5,
"content": "@**Outgoing Webhook Test** Zulip is the world\u2019s most productive group chat!",
"display_recipient": "Verona",
"type": "stream",
"id": 112,
"is_me_message": false,
"reactions": [
],
"sender_realm_str": "zulip",
"sender_short_name": "iago"
},
"bot_email": "outgoing-bot@localhost"
}
}

View File

@ -112,7 +112,7 @@ is helpful to distinguish deliberate non-responses from bugs.)
This is an example of the JSON payload that the Zulip server will `POST`
to your server:
{generate_code_example|zulip-outgoing-webhook-payload|fixture}
{generate_code_example|/zulip-outgoing-webhook:post|fixture(200)}
### Example response payloads

View File

@ -300,8 +300,6 @@ class APICodeExamplesPreprocessor(Preprocessor):
if key == 'fixture':
if argument:
text = self.render_fixture(function, name=argument)
else:
text = self.render_fixture(function)
elif key == 'example':
if argument == 'admin_config=True':
text = SUPPORTED_LANGUAGES[language]['render'](function, admin_config=True)
@ -325,15 +323,8 @@ class APICodeExamplesPreprocessor(Preprocessor):
def render_fixture(self, function: str, name: Optional[str]=None) -> List[str]:
fixture = []
# We assume that if the function we're rendering starts with a slash
# it's a path in the endpoint and therefore it uses the new OpenAPI
# format.
if function.startswith('/'):
path, method = function.rsplit(':', 1)
fixture_dict = get_openapi_fixture(path, method, name)
else:
fixture_dict = zerver.openapi.python_examples.FIXTURES[function]
path, method = function.rsplit(':', 1)
fixture_dict = get_openapi_fixture(path, method, name)
fixture_json = json.dumps(fixture_dict, indent=4, sort_keys=True,
separators=(',', ': '))

View File

@ -13,7 +13,6 @@ from zerver.models import get_realm, get_user
from zulip import Client
ZULIP_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
FIXTURE_PATH = os.path.join(ZULIP_DIR, 'templates', 'zerver', 'api', 'fixtures.json')
TEST_FUNCTIONS = dict() # type: Dict[str, Callable[..., None]]
REGISTERED_TEST_FUNCTIONS = set() # type: Set[str]
@ -46,14 +45,6 @@ def ensure_users(ids_list: List[int], user_names: List[str]) -> None:
assert ids_list == user_ids
def load_api_fixtures():
# type: () -> Dict[str, Any]
with open(FIXTURE_PATH, 'r') as fp:
json_dict = json.load(fp)
return json_dict
FIXTURES = load_api_fixtures()
@openapi_test_function("/users/me/subscriptions:post")
def add_subscriptions(client):
# type: (Client) -> None

View File

@ -3312,6 +3312,78 @@ paths:
"msg": "User not authorized for this query",
"result": "error"
}
/zulip-outgoing-webhook:
post:
description: |
Outgoing Webhooks allows to build or set up Zulip integrations which
are notified when certain types of messages are sent in Zulip.
responses:
'200':
description: |
Success
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/JsonSuccess'
- properties:
data:
type: string
description: |
It contains the content of the message (in Markdown).
trigger:
type: string
description: |
It contains the trigger method.
token:
type: string
description: |
A string of alphanumeric characters that can be use to authenticate
the webhook request (each bot user uses a fixed token).
message:
type: object
description: |
A dict containing details on the message which triggered the
outgoing webhook
bot_email:
type: string
description: |
Email of the bot user
- example:
{
"data": "@**Outgoing Webhook Test** Zulip is the world\u2019s most productive group chat!",
"trigger": "mention",
"token": "xvOzfurIutdRRVLzpXrIIHXJvNfaJLJ0",
"message": {
"subject": "Verona2",
"sender_email": "iago@zulip.com",
"timestamp": 1527876931,
"client": "website",
"submessages": [
],
"recipient_id": 20,
"topic_links": [
],
"sender_full_name": "Iago",
"avatar_url": "https://secure.gravatar.com/avatar/1f4f1575bf002ae562fea8fc4b861b09?d=identicon&version=1",
"rendered_content": "<p><span class=\"user-mention\" data-user-id=\"25\">@Outgoing Webhook Test</span> Zulip is the world\u2019s most productive group chat!</p>",
"sender_id": 5,
"stream_id": 5,
"content": "@**Outgoing Webhook Test** Zulip is the world\u2019s most productive group chat!",
"display_recipient": "Verona",
"type": "stream",
"id": 112,
"is_me_message": false,
"reactions": [
],
"sender_realm_str": "zulip",
"sender_short_name": "iago"
},
"bot_email": "outgoing-bot@localhost"
}
components:
#######################

View File

@ -206,6 +206,9 @@ class OpenAPIArgumentsTest(ZulipTestCase):
# Rest error handling endpoint
'/rest-error-handling',
# Zulip outgoing webhook payload
'/zulip-outgoing-webhook',
#### Mobile-app only endpoints; important for mobile developers.
# Mobile interface for fetching API keys
'/fetch_api_key',