Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
api-docs: Move markdown files to top level directory.
Lauryn Menarddbacc00f0f4a
diff --git a/.prettierignore b/.prettierignoreindex 0457e60a3ee..641a993f58e 100644--- a/.prettierignore+++ b/.prettierignore@@ -1,3 +1,4 @@+/api_docs/**/*.md/corporate/tests/stripe_fixtures/help/**/*.md/localediff --git a/templates/zerver/api/api-doc-template.md b/api_docs/api-doc-template.mdsimilarity index 100%rename from templates/zerver/api/api-doc-template.mdrename to api_docs/api-doc-template.mddiff --git a/templates/zerver/api/api-keys.md b/api_docs/api-keys.mdsimilarity index 100%rename from templates/zerver/api/api-keys.mdrename to api_docs/api-keys.mddiff --git a/templates/zerver/api/changelog.md b/api_docs/changelog.mdsimilarity index 100%rename from templates/zerver/api/changelog.mdrename to api_docs/changelog.mddiff --git a/templates/zerver/api/client-libraries.md b/api_docs/client-libraries.mdsimilarity index 100%rename from templates/zerver/api/client-libraries.mdrename to api_docs/client-libraries.mddiff --git a/templates/zerver/api/configuring-python-bindings.md b/api_docs/configuring-python-bindings.mdsimilarity index 100%rename from templates/zerver/api/configuring-python-bindings.mdrename to api_docs/configuring-python-bindings.mddiff --git a/templates/zerver/api/construct-narrow.md b/api_docs/construct-narrow.mdsimilarity index 100%rename from templates/zerver/api/construct-narrow.mdrename to api_docs/construct-narrow.mddiff --git a/templates/zerver/api/create-stream.md b/api_docs/create-stream.mdsimilarity index 100%rename from templates/zerver/api/create-stream.mdrename to api_docs/create-stream.mddiff --git a/templates/zerver/api/deploying-bots.md b/api_docs/deploying-bots.mdsimilarity index 100%rename from templates/zerver/api/deploying-bots.mdrename to api_docs/deploying-bots.mddiff --git a/templates/zerver/api/include/api-admin-only.md b/api_docs/include/api-admin-only.mdsimilarity index 100%rename from templates/zerver/api/include/api-admin-only.mdrename to api_docs/include/api-admin-only.mddiff --git a/templates/zerver/api/include/empty.md b/api_docs/include/empty.mdsimilarity index 100%rename from templates/zerver/api/include/empty.mdrename to api_docs/include/empty.mddiff --git a/templates/zerver/api/include/rest-endpoints.md b/api_docs/include/rest-endpoints.mdsimilarity index 100%rename from templates/zerver/api/include/rest-endpoints.mdrename to api_docs/include/rest-endpoints.mddiff --git a/templates/zerver/api/incoming-webhooks-overview.md b/api_docs/incoming-webhooks-overview.mdsimilarity index 100%rename from templates/zerver/api/incoming-webhooks-overview.mdrename to api_docs/incoming-webhooks-overview.mddiff --git a/templates/zerver/api/incoming-webhooks-walkthrough.md b/api_docs/incoming-webhooks-walkthrough.mdsimilarity index 100%rename from templates/zerver/api/incoming-webhooks-walkthrough.mdrename to api_docs/incoming-webhooks-walkthrough.mddiff --git a/templates/zerver/api/index.md b/api_docs/index.mdsimilarity index 100%rename from templates/zerver/api/index.mdrename to api_docs/index.mddiff --git a/templates/zerver/api/installation-instructions.md b/api_docs/installation-instructions.mdsimilarity index 100%rename from templates/zerver/api/installation-instructions.mdrename to api_docs/installation-instructions.mddiff --git a/templates/zerver/api/integrations-overview.md b/api_docs/integrations-overview.mdsimilarity index 100%rename from templates/zerver/api/integrations-overview.mdrename to api_docs/integrations-overview.mddiff --git a/templates/zerver/api/mark-all-as-read.md b/api_docs/mark-all-as-read.mdsimilarity index 100%rename from templates/zerver/api/mark-all-as-read.mdrename to api_docs/mark-all-as-read.mddiff --git a/templates/zerver/api/missing.md b/api_docs/missing.mdsimilarity index 100%rename from templates/zerver/api/missing.mdrename to api_docs/missing.mddiff --git a/templates/zerver/api/non-webhook-integrations.md b/api_docs/non-webhook-integrations.mdsimilarity index 100%rename from templates/zerver/api/non-webhook-integrations.mdrename to api_docs/non-webhook-integrations.mddiff --git a/templates/zerver/api/outgoing-webhooks.md b/api_docs/outgoing-webhooks.mdsimilarity index 100%rename from templates/zerver/api/outgoing-webhooks.mdrename to api_docs/outgoing-webhooks.mddiff --git a/templates/zerver/api/real-time-events.md b/api_docs/real-time-events.mdsimilarity index 100%rename from templates/zerver/api/real-time-events.mdrename to api_docs/real-time-events.mddiff --git a/templates/zerver/api/rest-error-handling.md b/api_docs/rest-error-handling.mdsimilarity index 100%rename from templates/zerver/api/rest-error-handling.mdrename to api_docs/rest-error-handling.mddiff --git a/templates/zerver/api/rest.md b/api_docs/rest.mdsimilarity index 100%rename from templates/zerver/api/rest.mdrename to api_docs/rest.mddiff --git a/templates/zerver/api/roles-and-permissions.md b/api_docs/roles-and-permissions.mdsimilarity index 100%rename from templates/zerver/api/roles-and-permissions.mdrename to api_docs/roles-and-permissions.mddiff --git a/templates/zerver/api/running-bots.md b/api_docs/running-bots.mdsimilarity index 100%rename from templates/zerver/api/running-bots.mdrename to api_docs/running-bots.mddiff --git a/templates/zerver/api/send-message.md b/api_docs/send-message.mdsimilarity index 100%rename from templates/zerver/api/send-message.mdrename to api_docs/send-message.mddiff --git a/templates/zerver/api/sidebar_index.md b/api_docs/sidebar_index.mdsimilarity index 100%rename from templates/zerver/api/sidebar_index.mdrename to api_docs/sidebar_index.mddiff --git a/templates/zerver/api/writing-bots.md b/api_docs/writing-bots.mdsimilarity index 100%rename from templates/zerver/api/writing-bots.mdrename to api_docs/writing-bots.mddiff --git a/docs/documentation/api.md b/docs/documentation/api.mdindex 29bf51071e6..f4f78788171 100644--- a/docs/documentation/api.md+++ b/docs/documentation/api.md@@ -33,11 +33,10 @@ Our API documentation is defined by a few sets of files:our [help center docs](helpcenter.md), with some specialextensions for rendering nice code blocks and exampleresponses. Most API endpoints share a common template,- `templates/zerver/api/api-doc-template.md`, which renders the+ `api_docs/api-doc-template.md`, which renders theOpenAPI description of the API endpoint. A handful of endpoints thatrequire special content, as well as pages that document general API- details rather than specific endpoints, live at- `templates/zerver/api/*.md`.+ details rather than specific endpoints, live at `api_docs/*.md`.- We have an extensive set of tests designed to validate that the datain the OpenAPI file matching the implementation. Specifically,`zerver/tests/test_openapi.py` compares every endpoint's accepted@@ -57,8 +56,8 @@ Our API documentation is defined by a few sets of files:- The cURL examples are generated and tested using`zerver/openapi/curl_param_value_generators.py`.- The REST API index- (`templates/zerver/api/include/rest-endpoints.md`) in the broader- /api left sidebar (`templates/zerver/api/sidebar_index.md`).+ (`api_docs/include/rest-endpoints.md`) in the broader+ /api left sidebar (`api_docs/sidebar_index.md`).This first section is focused on explaining how the API documentationsystem is put together; when actually documenting an endpoint, you'll@@ -67,7 +66,7 @@ want to also read the [Step by step guide](#step-by-step-guide).## How it worksTo understand how this documentation system works, start by reading an-existing doc file (`templates/zerver/api/render-message.md` is a good+existing doc file (`api_docs/render-message.md` is a goodexample; accessible live[here](https://zulip.com/api/render-message) or in the developmentenvironment at `http://localhost:9991/api/render-message`).@@ -180,7 +179,7 @@ wherever that string appears in the API documentation.We have a separate Markdown extension to document the parameters thatan API endpoint supports. You'll see this in files like-`templates/zerver/api/render-message.md` via the following Markdown+`api_docs/render-message.md` via the following Markdowndirective (implemented in`zerver/lib/markdown/api_arguments_table_generator.py`):@@ -290,13 +289,13 @@ above.1. Finally, if the API docs page of the endpoint doesn't follow thecommon API docs template in- `templates/zerver/api/api-docs-template.md`, then add its custom- Markdown file under `templates/zerver/api/`. However, it is a goal+ `api_docs/api-docs-template.md`, then add its custom+ Markdown file under `api_docs/`. However, it is a goalto minimize the number of files that diverse from the commontemplate, so only do this if there's a good reason.1. Add the endpoint to the index in- `templates/zerver/api/include/rest-endpoints.md`. The URL should+ `api_docs/include/rest-endpoints.md`. The URL shouldmatch the `operationId` for the endpoint, and the link text shouldmatch the title of the endpoint from the OpenAPI `summary` field.@@ -307,14 +306,12 @@ above.make sure that copy-pasting the code in your examples works, andpost an example of the output in the pull request.-1. Document the new API in `templates/zerver/api/changelog.md` and+1. Document the new API in `api_docs/changelog.md` andbump the `API_FEATURE_LEVEL` in `version.py`. Also, make sure toadd a `**Changes**` entry in the description of the new API/eventin `zerver/openapi/zulip.yaml`, which mentions the API feature levelat which they were added.-[javascript-examples]: https://github.com/zulip/zulip-js/tree/main/examples-## Why a custom system?Given that our documentation is written in large part using thediff --git a/docs/tutorials/new-feature-tutorial.md b/docs/tutorials/new-feature-tutorial.mdindex 56ef7aa2c41..d52379ece40 100644--- a/docs/tutorials/new-feature-tutorial.md+++ b/docs/tutorials/new-feature-tutorial.md@@ -67,7 +67,7 @@ organization in Zulip). The following files are involved in the process:**Documentation**- `zerver/openapi/zulip.yaml`: OpenAPI definitions for the Zulip REST API.-- `templates/zerver/api/changelog.md`: documentation listing all changes to the Zulip Server API.+- `api_docs/changelog.md`: documentation listing all changes to the Zulip Server API.- `help/...`: end user facing documentation (Help Center) for the application.### Adding a field to the database@@ -164,7 +164,7 @@ provides more detailed information about writing and editing feature**API documentation:** A new feature will probably impact the REST APIdocumentation as well, which will mean updating `zerver/openapi/zulip.yaml`-and modifying `templates/zerver/api/changelog.md` for a new feature+and modifying `api_docs/changelog.md` for a new featurelevel. [Documenting REST API endpoints](../documentation/api.md)explains Zulip's API documentation system and provides a step by stepguide to adding or updating documentation for an API endpoint.@@ -714,7 +714,7 @@ documentation is to read more about Zulip'sand [OpenAPI configuration](../documentation/openapi.md).In particular, if there is an API change, **make sure** you document-your new feature in `templates/zerver/api/changelog.md` and bump the+your new feature in `api_docs/changelog.md` and bump the`API_FEATURE_LEVEL` in `version.py`. The API feature level allows thedevelopers of mobile clients and other tools using the Zulip API toprogrammatically determine whether the Zulip server they arediff --git a/templates/zerver/documentation_main.html b/templates/zerver/documentation_main.htmlindex 20d5fa1515c..be5a678156e 100644--- a/templates/zerver/documentation_main.html+++ b/templates/zerver/documentation_main.html@@ -20,7 +20,7 @@{% elif page_is_help_center %}{{ render_markdown_path(sidebar_index, pure_markdown=True) }}{% else %}- {{ render_markdown_path(sidebar_index, api_uri_context) }}+ {{ render_markdown_path(sidebar_index, context=api_uri_context, pure_markdown=True) }}{% endif %}{% if not page_is_policy_center %}@@ -40,7 +40,7 @@{% elif page_is_help_center %}{{ render_markdown_path(article, context=api_uri_context, help_center=True, pure_markdown=True) }}{% else %}- {{ render_markdown_path(article, api_uri_context) }}+ {{ render_markdown_path(article, context=api_uri_context, pure_markdown=True) }}{% endif %}<div id="footer" class="documentation-footer">diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.pyindex e15de04c6e0..e8e6327c38d 100644--- a/tools/linter_lib/custom_check.py+++ b/tools/linter_lib/custom_check.py@@ -826,6 +826,7 @@ markdown_rules = RuleList({"pattern": "https://zulip.readthedocs.io/en/latest/[a-zA-Z0-9]","exclude": {+ "api_docs/","docs/contributing/contributing.md","docs/overview/readme.md","docs/README.md",@@ -857,7 +858,6 @@ markdown_rules = RuleList("description": "Don't link directly to line numbers",},],- exclude_files_in="help/",)help_markdown_rules = RuleList(diff --git a/tools/release b/tools/releaseindex c2b63e522ca..8410cfb6c21 100755--- a/tools/release+++ b/tools/release@@ -98,8 +98,8 @@ if [ -z "$is_prerelease" ]; thenchanged_api_level=$(git diff-tree -G API_FEATURE_LEVEL HEAD -- version.py)[ -n "$changed_api_level" ] || fail "$version did not adjust API_FEATURE_LEVEL in version.py"feature_level="$(extract_version "API_FEATURE_LEVEL")"- grep -q -F -x "**Feature level $feature_level**" templates/zerver/api/changelog.md \- || fail "Feature level $feature_level is not documented in templates/zerver/api/changelog.md"+ grep -q -F -x "**Feature level $feature_level**" api_docs/changelog.md \+ || fail "Feature level $feature_level is not documented in api_docs/changelog.md"fifidiff --git a/version.py b/version.pyindex d1b28e4f55b..5f6ed3ff067 100644--- a/version.py+++ b/version.py@@ -31,8 +31,8 @@ DESKTOP_WARNING_VERSION = "5.4.3"# use the new feature/API until the bump.## Changes should be accompanied by documentation explaining what the-# new level means in templates/zerver/api/changelog.md, as well as-# "**Changes**" entries in the endpoint's documentation in `zulip.yaml`.+# new level means in api_docs/changelog.md, as well as "**Changes**"+# entries in the endpoint's documentation in `zulip.yaml`.API_FEATURE_LEVEL = 159# Bump the minor PROVISION_VERSION to indicate that folks should provisiondiff --git a/zerver/lib/templates.py b/zerver/lib/templates.pyindex b80e7c2793f..5a3e9f45dec 100644--- a/zerver/lib/templates.py+++ b/zerver/lib/templates.py@@ -151,7 +151,7 @@ def render_markdown_path(md_macro_extension = zerver.lib.markdown.include.makeExtension(base_path="help/include/")else:md_macro_extension = zerver.lib.markdown.include.makeExtension(- base_path="templates/zerver/api/include/"+ base_path="api_docs/include/")if not any(doc in markdown_file_path for doc in docs_without_macros):extensions = [md_macro_extension, *extensions]diff --git a/zerver/openapi/test_curl_examples.py b/zerver/openapi/test_curl_examples.pyindex 85e40020841..6e1c1d827b2 100644--- a/zerver/openapi/test_curl_examples.py+++ b/zerver/openapi/test_curl_examples.py@@ -38,9 +38,7 @@ def test_generated_curl_examples_for_success(client: Client) -> None:# on "add" tests coming before "remove" tests in some cases. We# should try to either avoid ordering dependencies or make them# very explicit.- rest_endpoints_path = os.path.join(- settings.DEPLOY_ROOT, "templates/zerver/api/include/rest-endpoints.md"- )+ rest_endpoints_path = os.path.join(settings.DEPLOY_ROOT, "api_docs/include/rest-endpoints.md")with open(rest_endpoints_path) as f:rest_endpoints_raw = f.read()ENDPOINT_REGEXP = re.compile(r"/api/\s*(.*?)\)")@@ -48,7 +46,7 @@ def test_generated_curl_examples_for_success(client: Client) -> None:for endpoint in endpoint_list:article_name = endpoint + ".md"- file_name = os.path.join(settings.DEPLOY_ROOT, "templates/zerver/api/", article_name)+ file_name = os.path.join(settings.DEPLOY_ROOT, "api_docs/", article_name)curl_commands_to_test = []if os.path.exists(file_name):diff --git a/zerver/views/documentation.py b/zerver/views/documentation.pyindex 0b8a0dbe88a..2211447a055 100644--- a/zerver/views/documentation.py+++ b/zerver/views/documentation.py@@ -69,6 +69,7 @@ class MarkdownDirectoryView(ApiURLView):path_template = ""policies_view = Falsehelp_view = False+ api_doc_view = Falsedef get_path(self, article: str) -> DocumentationArticle:http_status = 200@@ -91,27 +92,33 @@ class MarkdownDirectoryView(ApiURLView):endpoint_name = Noneendpoint_method = None- # Absolute path cases- if (self.policies_view or self.help_view) and self.path_template.startswith("/"):- if not os.path.exists(path):- article = "missing"- http_status = 404- path = self.path_template % (article,)-- return DocumentationArticle(- article_path=path,- article_http_status=http_status,- endpoint_path=None,- endpoint_method=None,- )+ if not self.path_template.startswith("/"):+ # Relative paths only used for policies documentation+ # when it is not configured or in the dev environment+ assert self.policies_view++ try:+ loader.get_template(path)+ return DocumentationArticle(+ article_path=path,+ article_http_status=http_status,+ endpoint_path=endpoint_name,+ endpoint_method=endpoint_method,+ )+ except loader.TemplateDoesNotExist:+ return DocumentationArticle(+ article_path=self.path_template % ("missing",),+ article_http_status=404,+ endpoint_path=None,+ endpoint_method=None,+ )- if self.path_template == "/zerver/api/%s.md":- # Hack: `self.path_template` has a leading `/`, so we use + to add directories.- api_documentation_path = os.path.join(settings.DEPLOY_ROOT, "templates") + path- if not os.path.exists(api_documentation_path):+ if not os.path.exists(path):+ if self.api_doc_view:try:+ # API endpoints documented in zerver/openapi/zulip.yamlendpoint_name, endpoint_method = get_endpoint_from_operationid(article)- path = "/zerver/api/api-doc-template.md"+ path = self.path_template % ("api-doc-template",)except AssertionError:return DocumentationArticle(article_path=self.path_template % ("missing",),@@ -119,22 +126,19 @@ class MarkdownDirectoryView(ApiURLView):endpoint_path=None,endpoint_method=None,)+ elif self.help_view or self.policies_view:+ article = "missing"+ http_status = 404+ path = self.path_template % (article,)+ else:+ raise AssertionError("Invalid documentation view type")- try:- loader.get_template(path)- return DocumentationArticle(- article_path=path,- article_http_status=http_status,- endpoint_path=endpoint_name,- endpoint_method=endpoint_method,- )- except loader.TemplateDoesNotExist:- return DocumentationArticle(- article_path=self.path_template % ("missing",),- article_http_status=404,- endpoint_path=None,- endpoint_method=None,- )+ return DocumentationArticle(+ article_path=path,+ article_http_status=http_status,+ endpoint_path=endpoint_name,+ endpoint_method=endpoint_method,+ )def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:article = kwargs["article"]@@ -149,12 +153,8 @@ class MarkdownDirectoryView(ApiURLView):):# Absolute path casearticle_absolute_path = documentation_article.article_path- elif documentation_article.article_path.startswith("/"):- # Hack: `context["article"] has a leading `/`, so we use + to add directories.- article_absolute_path = (- os.path.join(settings.DEPLOY_ROOT, "templates") + documentation_article.article_path- )else:+ # Relative path casearticle_absolute_path = os.path.join(settings.DEPLOY_ROOT, "templates", documentation_article.article_path)@@ -173,13 +173,15 @@ class MarkdownDirectoryView(ApiURLView):sidebar_article = self.get_path("sidebar_index")sidebar_index = sidebar_article.article_pathtitle_base = "Zulip terms and policies"- else:+ elif self.api_doc_view:context["page_is_api_center"] = Truecontext["doc_root"] = "/api/"context["doc_root_title"] = "API documentation"sidebar_article = self.get_path("sidebar_index")sidebar_index = sidebar_article.article_pathtitle_base = "Zulip API documentation"+ else:+ raise AssertionError("Invalid documentation view type")# The following is a somewhat hacky approach to extract titles from articles.endpoint_name = None@@ -187,7 +189,7 @@ class MarkdownDirectoryView(ApiURLView):if os.path.exists(article_absolute_path):with open(article_absolute_path) as article_file:first_line = article_file.readlines()[0]- if context["article"] == "/zerver/api/api-doc-template.md":+ if self.api_doc_view and context["article"].endswith("api-doc-template.md"):endpoint_name, endpoint_method = (documentation_article.endpoint_path,documentation_article.endpoint_method,@@ -195,9 +197,7 @@ class MarkdownDirectoryView(ApiURLView):assert endpoint_name is not Noneassert endpoint_method is not Nonearticle_title = get_openapi_summary(endpoint_name, endpoint_method)- elif (- self.path_template == "/zerver/api/%s.md" and "{generate_api_header(" in first_line- ):+ elif self.api_doc_view and "{generate_api_header(" in first_line:api_operation = context["PAGE_METADATA_URL"].split("/api/")[1]endpoint_name, endpoint_method = get_endpoint_from_operationid(api_operation)article_title = get_openapi_summary(endpoint_name, endpoint_method)diff --git a/zproject/urls.py b/zproject/urls.pyindex a808058708c..5216a53d112 100644--- a/zproject/urls.py+++ b/zproject/urls.py@@ -786,7 +786,9 @@ help_documentation_view = MarkdownDirectoryView.as_view(help_view=True,)api_documentation_view = MarkdownDirectoryView.as_view(- template_name="zerver/documentation_main.html", path_template="/zerver/api/%s.md"+ template_name="zerver/documentation_main.html",+ path_template=f"{settings.DEPLOY_ROOT}/api_docs/%s.md",+ api_doc_view=True,)policy_documentation_view = MarkdownDirectoryView.as_view(template_name="zerver/documentation_main.html",