openapi: Automatically add python tab whenever required.

As a part of goal of moving towards a common template,
the hardcoded python tabs need to be removed to ensure
that endpoints which don't have python examples can be
covered by the common template as well.

This commit also modifies the markdown extension for python
examples to render empty string in case the examples don't
exist, which would allow it to be called whether the endpoint
has python examples or not.
This commit is contained in:
Suyash Vardhan Mathur 2021-06-23 17:23:52 +05:30 committed by Tim Abbott
parent fab6a5192c
commit 0c4330f926
60 changed files with 3 additions and 62 deletions

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/playgrounds:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/filters:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages/{message_id}/reactions:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/streams/{stream_id}:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages/matches_narrow:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/profile_fields:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/user_groups/create:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/me:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/{user_id}:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages/{message_id}:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/events:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/attachments:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/emoji:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/profile_fields:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/linkifiers:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages/{message_id}/history:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/me:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages/{message_id}:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/server_settings:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/get_stream_id:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/me/{stream_id}/topics:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/streams:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/{user_id}/subscriptions/{stream_id}:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/me/subscriptions:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/{email}:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/user_groups:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/{user_id_or_email}/presence:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/{user_id}:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users:get|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/mark_all_as_read:post|example}
@ -42,7 +41,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/mark_stream_as_read:post|example}
@ -80,7 +78,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/mark_topic_as_read:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/me/subscriptions/muted_topics:patch|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/me/muted_users/{muted_user_id}:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/{user_id}/reactivate:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/register:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/playgrounds/{playground_id}:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/filters/{filter_id}:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages/{message_id}/reactions:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/user_groups/{user_group_id}:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages/render:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/profile_fields:patch|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/typing:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/me/subscriptions:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/me/muted_users/{muted_user_id}:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/me/subscriptions:delete|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/settings/display:patch|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/filters/{filter_id}:patch|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages/flags:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/messages/{message_id}:patch|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/settings/notifications:patch|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/streams/{stream_id}:patch|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/me/subscriptions/properties:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/user_groups/{user_group_id}/members:post|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/user_groups/{user_group_id}:patch|example}

View File

@ -5,7 +5,6 @@
## Usage examples
{start_tabs}
{tab|python}
{generate_code_example(python)|/users/{user_id}:patch|example}

View File

@ -6,7 +6,6 @@
{start_tabs}
{tab|python}
{generate_code_example(python)|/realm/emoji/{emoji_name}:post|example}

View File

@ -6,7 +6,6 @@
{start_tabs}
{tab|python}
{generate_code_example(python)|/user_uploads:post|example}

View File

@ -129,6 +129,8 @@ def extract_code_example(
def render_python_code_example(
function: str, admin_config: bool = False, **kwargs: Any
) -> List[str]:
if function not in zerver.openapi.python_examples.TEST_FUNCTIONS:
return []
method = zerver.openapi.python_examples.TEST_FUNCTIONS[function]
function_source_lines = inspect.getsourcelines(method)[0]
@ -139,7 +141,7 @@ def render_python_code_example(
snippets = extract_code_example(function_source_lines, [], PYTHON_EXAMPLE_REGEX)
code_example = []
code_example = ["{tab|python}\n"]
code_example.append("```python")
code_example.extend(config)