openapi: Add missing __init__.py; fix type errors hidden by its absence.

The absence of __init__.py was preventing mypy from following any of
the zerver.openapi imports.  These errors were being silenced by
ignore_missing_imports.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-07-02 22:37:59 -07:00 committed by Tim Abbott
parent 985e95041d
commit 24c239d991
5 changed files with 7 additions and 7 deletions

View File

@ -40,9 +40,7 @@ class APIReturnValuesTablePreprocessor(Preprocessor):
doc_name = match.group(2)
endpoint, method = doc_name.rsplit(":", 1)
return_values: Dict[str, Any] = {}
return_values = get_openapi_return_values(endpoint, method)
text: List[str] = []
if doc_name == "/events:get":
return_values = copy.deepcopy(return_values)
events = return_values["events"].pop("items", None)

View File

View File

@ -474,7 +474,7 @@ class APICodeExamplesPreprocessor(Preprocessor):
done = True
return lines
def render_fixture(self, function: str, name: Optional[str] = None) -> List[str]:
def render_fixture(self, function: str, name: str) -> List[str]:
path, method = function.rsplit(":", 1)
return generate_openapi_fixture(path, method, name)

View File

@ -8,7 +8,7 @@
import json
import os
import re
from typing import Any, Dict, List, Optional, Set, Tuple
from typing import Any, Dict, List, Mapping, Optional, Set, Tuple, Union
from jsonschema.exceptions import ValidationError as JsonSchemaValidationError
from openapi_core import create_spec
@ -320,7 +320,7 @@ def get_openapi_parameters(
return parameters
def get_openapi_return_values(endpoint: str, method: str) -> List[Dict[str, Any]]:
def get_openapi_return_values(endpoint: str, method: str) -> Dict[str, Any]:
operation = openapi_spec.openapi()["paths"][endpoint][method.lower()]
schema = operation["responses"]["200"]["content"]["application/json"]["schema"]
# In cases where we have used oneOf, the schemas only differ in examples
@ -491,7 +491,7 @@ def likely_deprecated_parameter(parameter_description: str) -> bool:
return "**Deprecated**" in parameter_description
def check_deprecated_consistency(argument: Dict[str, Any], description: str) -> None:
def check_deprecated_consistency(argument: Mapping[str, Any], description: str) -> None:
# Test to make sure deprecated parameters are marked so.
if likely_deprecated_parameter(description):
assert argument["deprecated"]
@ -510,7 +510,7 @@ SKIP_JSON = {
def validate_request(
url: str,
method: str,
data: Dict[str, Any],
data: Union[str, bytes, Dict[str, Any]],
http_headers: Dict[str, Any],
json_url: bool,
status_code: str,

View File

@ -153,6 +153,8 @@ class MarkdownDirectoryView(ApiURLView):
documentation_article.endpoint_path,
documentation_article.endpoint_method,
)
assert endpoint_name is not None
assert endpoint_method is not None
article_title = get_openapi_summary(endpoint_name, endpoint_method)
elif self.path_template == "/zerver/api/%s.md" and "{generate_api_title(" in first_line:
api_operation = context["OPEN_GRAPH_URL"].split("/api/")[1].replace("-", "_")