Skip to content

Commit 07908d3

Browse files
authored
Clean up openapi compat and warnings (#368)
1 parent 6c688f6 commit 07908d3

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

jupyterlab_server/spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

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

1919
openapi_spec_dict = get_openapi_spec_dict()
20-
return create_spec(openapi_spec_dict)
20+
return Spec.from_dict(openapi_spec_dict)
2121

2222

2323
def get_openapi_spec_dict():

jupyterlab_server/test_utils.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212

1313
import tornado.httpclient
1414
import tornado.web
15+
16+
try:
17+
from openapi_core import V30RequestValidator, V30ResponseValidator # type:ignore[attr-defined]
18+
except ImportError:
19+
V30RequestValidator = None
20+
V30ResponseValidator = None
21+
from openapi_core import openapi_request_validator, openapi_response_validator
1522
from openapi_core.spec.paths import Spec
16-
from openapi_core.validation.request import openapi_request_validator
1723
from openapi_core.validation.request.datatypes import RequestParameters
18-
from openapi_core.validation.response import openapi_response_validator
1924
from tornado.httpclient import HTTPRequest, HTTPResponse
2025
from werkzeug.datastructures import Headers, ImmutableMultiDict
2126

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

96101
@property
97102
def body(self) -> Optional[str]:
103+
if self.request.body is None:
104+
return None
98105
if not isinstance(self.request.body, bytes):
99106
raise AssertionError('Request body is invalid')
100107
return self.request.body.decode("utf-8")
@@ -142,11 +149,17 @@ def validate_request(response):
142149
openapi_spec = get_openapi_spec()
143150

144151
request = TornadoOpenAPIRequest(response.request, openapi_spec)
145-
result = openapi_request_validator.validate(openapi_spec, request)
152+
if V30RequestValidator:
153+
result = V30RequestValidator(openapi_spec).validate(request)
154+
else:
155+
result = openapi_request_validator.validate(openapi_spec, request)
146156
result.raise_for_errors()
147157

148158
response = TornadoOpenAPIResponse(response)
149-
result2 = openapi_response_validator.validate(openapi_spec, request, response)
159+
if V30ResponseValidator:
160+
result2 = V30ResponseValidator(openapi_spec).validate(request, response)
161+
else:
162+
result2 = openapi_response_validator.validate(openapi_spec, request, response)
150163
result2.raise_for_errors()
151164

152165

pyproject.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,10 @@ timeout = 300
143143
# timeout_method = "thread"
144144
filterwarnings = [
145145
"error",
146-
"module:make_current is deprecated:DeprecationWarning",
147-
"module:clear_current is deprecated:DeprecationWarning",
148-
"module:There is no current event loop:DeprecationWarning",
149146
"ignore:ServerApp.preferred_dir config is deprecated:FutureWarning",
150-
"ignore:Passing a schema to Validator.iter_errors:DeprecationWarning",
151-
"module:Subclassing validator classes is not intended to be part of their public API:DeprecationWarning"
147+
# From openapi_schema_validator
148+
"module:write property is deprecated:DeprecationWarning",
149+
"module:read property is deprecated:DeprecationWarning",
152150
]
153151

154152
[tool.coverage.report]

tests/test_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def test_watch_helper():
3333
helper.wait()
3434

3535

36-
async def test_process_app():
36+
def test_process_app():
3737
class TestApp(ProcessApp):
3838
name = "tests"
3939

0 commit comments

Comments
 (0)