From d1ccf15cd3dfb6b7ed8acbbbe5cd2b16e44d5b4f Mon Sep 17 00:00:00 2001 From: Suyash Vardhan Mathur Date: Thu, 3 Jun 2021 16:33:54 +0530 Subject: [PATCH] apidocs: Fix invalid API page bug. The current logic to get API pages' title using OperationID should be used when the first line of the file explicitly mentions so. In cases where the files didn't begin with `#` but also didn't need to get title from OpenAPI summary, this logic fails and causes Server error. This particularly happens when the article is invalid, and the `missing.md` file doesn't need title to be generated, but doesn't start with `#` either. This commit fixes the logic of using the generated title and covers the bug. --- zerver/views/documentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zerver/views/documentation.py b/zerver/views/documentation.py index 062d9fd8d0..4d61f8af55 100644 --- a/zerver/views/documentation.py +++ b/zerver/views/documentation.py @@ -106,7 +106,7 @@ class MarkdownDirectoryView(ApiURLView): with open(article_path) as article_file: first_line = article_file.readlines()[0] # Strip the header and then use the first line to get the article title - if self.path_template == "/zerver/api/%s.md" and first_line[0] != "#": + if self.path_template == "/zerver/api/%s.md" and "{generate_api_title(" in first_line: api_operation = context["OPEN_GRAPH_URL"].split("/api/")[1].replace("-", "_") endpoint_path, endpoint_method = get_endpoint_from_operationid(api_operation) article_title = get_openapi_summary(endpoint_path, endpoint_method)