Skip to content

Commit

Permalink
Clean up openapi compat and warnings (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Jan 28, 2023
1 parent 6c688f6 commit 07908d3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions jupyterlab_server/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

def get_openapi_spec() -> "Spec":
"""Get the OpenAPI spec object."""
from openapi_core.spec.shortcuts import create_spec
from openapi_core.spec.paths import Spec

openapi_spec_dict = get_openapi_spec_dict()
return create_spec(openapi_spec_dict)
return Spec.from_dict(openapi_spec_dict)


def get_openapi_spec_dict():
Expand Down
21 changes: 17 additions & 4 deletions jupyterlab_server/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@

import tornado.httpclient
import tornado.web

try:
from openapi_core import V30RequestValidator, V30ResponseValidator # type:ignore[attr-defined]
except ImportError:
V30RequestValidator = None
V30ResponseValidator = None
from openapi_core import openapi_request_validator, openapi_response_validator
from openapi_core.spec.paths import Spec
from openapi_core.validation.request import openapi_request_validator
from openapi_core.validation.request.datatypes import RequestParameters
from openapi_core.validation.response import openapi_response_validator
from tornado.httpclient import HTTPRequest, HTTPResponse
from werkzeug.datastructures import Headers, ImmutableMultiDict

Expand Down Expand Up @@ -95,6 +100,8 @@ def method(self) -> str:

@property
def body(self) -> Optional[str]:
if self.request.body is None:
return None
if not isinstance(self.request.body, bytes):
raise AssertionError('Request body is invalid')
return self.request.body.decode("utf-8")
Expand Down Expand Up @@ -142,11 +149,17 @@ def validate_request(response):
openapi_spec = get_openapi_spec()

request = TornadoOpenAPIRequest(response.request, openapi_spec)
result = openapi_request_validator.validate(openapi_spec, request)
if V30RequestValidator:
result = V30RequestValidator(openapi_spec).validate(request)
else:
result = openapi_request_validator.validate(openapi_spec, request)
result.raise_for_errors()

response = TornadoOpenAPIResponse(response)
result2 = openapi_response_validator.validate(openapi_spec, request, response)
if V30ResponseValidator:
result2 = V30ResponseValidator(openapi_spec).validate(request, response)
else:
result2 = openapi_response_validator.validate(openapi_spec, request, response)
result2.raise_for_errors()


Expand Down
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,10 @@ timeout = 300
# timeout_method = "thread"
filterwarnings = [
"error",
"module:make_current is deprecated:DeprecationWarning",
"module:clear_current is deprecated:DeprecationWarning",
"module:There is no current event loop:DeprecationWarning",
"ignore:ServerApp.preferred_dir config is deprecated:FutureWarning",
"ignore:Passing a schema to Validator.iter_errors:DeprecationWarning",
"module:Subclassing validator classes is not intended to be part of their public API:DeprecationWarning"
# From openapi_schema_validator
"module:write property is deprecated:DeprecationWarning",
"module:read property is deprecated:DeprecationWarning",
]

[tool.coverage.report]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def test_watch_helper():
helper.wait()


async def test_process_app():
def test_process_app():
class TestApp(ProcessApp):
name = "tests"

Expand Down

0 comments on commit 07908d3

Please sign in to comment.