diff --git a/templates/zerver/api/fixtures.json b/templates/zerver/api/fixtures.json deleted file mode 100644 index 1eca176a32..0000000000 --- a/templates/zerver/api/fixtures.json +++ /dev/null @@ -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": "

@Outgoing Webhook Test Zulip is the world\u2019s most productive group chat!

", - "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" - } -} diff --git a/templates/zerver/api/outgoing-webhooks.md b/templates/zerver/api/outgoing-webhooks.md index 6e6284c51e..f8c4fdbc4c 100644 --- a/templates/zerver/api/outgoing-webhooks.md +++ b/templates/zerver/api/outgoing-webhooks.md @@ -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 diff --git a/zerver/lib/bugdown/api_code_examples.py b/zerver/lib/bugdown/api_code_examples.py index f60600984c..fb59d21d26 100644 --- a/zerver/lib/bugdown/api_code_examples.py +++ b/zerver/lib/bugdown/api_code_examples.py @@ -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=(',', ': ')) diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.py index 9130c2a421..c66a8c487a 100644 --- a/zerver/openapi/python_examples.py +++ b/zerver/openapi/python_examples.py @@ -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 diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index ebe75e72a8..49c6725782 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -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": "

@Outgoing Webhook Test Zulip is the world\u2019s most productive group chat!

", + "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: ####################### diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py index 68e4b3d2e5..5a21ec3019 100644 --- a/zerver/tests/test_openapi.py +++ b/zerver/tests/test_openapi.py @@ -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',