Skip to content

Commit

Permalink
Merge branch 'master' into forman-xxx-allow_computing_mldataset_2
Browse files Browse the repository at this point in the history
  • Loading branch information
forman committed Dec 14, 2022
2 parents 7e2b5d0 + 5a217bd commit 8e04dde
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion test/server/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_basic_props(self):
self.assertIsInstance(api_ctx.config, FrozenDict)
self.assertEqual(config, api_ctx.config)
self.assertEqual((), api_ctx.apis)
self.assertIsInstance(api_ctx.open_api_doc, dict)
self.assertIsInstance(api_ctx.get_open_api_doc(), dict)

def test_async_exec(self):
framework = MockFramework()
Expand Down
4 changes: 2 additions & 2 deletions test/server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_basic_props(self):
self.assertIs(framework, server.framework)
self.assertIsInstance(server.apis, tuple)
self.assertIs(server.apis, server.apis)
self.assertIsInstance(server.open_api_doc, dict)
self.assertIsInstance(server.get_open_api_doc(), dict)
self.assertIsInstance(server.ctx, ServerContext)
self.assertIs(server.ctx, server.ctx)

Expand Down Expand Up @@ -406,7 +406,7 @@ def test_basic_props(self):
self.assertIsInstance(server_ctx.config, FrozenDict)
self.assertEqual(config, server_ctx.config)
self.assertEqual((), server_ctx.apis)
self.assertIsInstance(server_ctx.open_api_doc, dict)
self.assertIsInstance(server_ctx.get_open_api_doc(), dict)

def test_on_update_and_on_dispose(self):
server = mock_server()
Expand Down
3 changes: 1 addition & 2 deletions test/server/webservers/test_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,7 @@ def __init__(self):
def apis(self) -> Tuple[Api]:
return self._api,

@property
def open_api_doc(self) -> Dict[str, Any]:
def get_open_api_doc(self, include_all: bool = False) -> Dict[str, Any]:
return {}

@property
Expand Down
2 changes: 1 addition & 1 deletion xcube/cli/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def list_apis():
print(f'{api.name} - {api.description}')

def show_open_api():
output_fn(server.ctx.open_api_doc)
output_fn(server.ctx.get_open_api_doc())

def show_config():
output_fn(server.ctx.config.defrost())
Expand Down
8 changes: 3 additions & 5 deletions xcube/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,8 @@ class Context(AsyncExecution, ABC):
def apis(self) -> Tuple[Api]:
"""The APIs used by the server."""

@property
@abstractmethod
def open_api_doc(self) -> Dict[str, Any]:
def get_open_api_doc(self, include_all: bool = False) -> Dict[str, Any]:
"""The OpenAPI JSON document for the server."""

@property
Expand Down Expand Up @@ -408,10 +407,9 @@ def apis(self) -> Tuple[Api]:
"""Return the server context's ``apis`` property."""
return self.server_ctx.apis

@property
def open_api_doc(self) -> Dict[str, Any]:
def get_open_api_doc(self, include_all: bool = False) -> Dict[str, Any]:
"""Return the server context's ``apis`` property."""
return self.server_ctx.open_api_doc
return self.server_ctx.get_open_api_doc(include_all=include_all)

@property
def config(self) -> ServerConfig:
Expand Down
11 changes: 6 additions & 5 deletions xcube/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ def _update_config_schema(cls,
config_schema_update.required
)

@property
def open_api_doc(self) -> Dict[str, Any]:
def get_open_api_doc(self, include_all: bool = False) -> Dict[str, Any]:
"""Get the OpenAPI JSON document for this server."""
error_schema = {
"type": "object",
Expand Down Expand Up @@ -394,6 +393,9 @@ def open_api_doc(self) -> Dict[str, Any]:
"description": other_api.description or ""
})
for route in other_api.routes:
if not include_all \
and route.path.startswith('/maintenance/'):
continue
path = dict(
description=getattr(
route.handler_cls, "__doc__", ""
Expand Down Expand Up @@ -473,9 +475,8 @@ def server(self) -> Server:
def apis(self) -> Tuple[Api]:
return self._server.apis

@property
def open_api_doc(self) -> Dict[str, Any]:
return self._server.open_api_doc
def get_open_api_doc(self, include_all: bool = False) -> Dict[str, Any]:
return self._server.get_open_api_doc(include_all=include_all)

@property
def config(self) -> ServerConfig:
Expand Down
10 changes: 8 additions & 2 deletions xcube/webapi/meta/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ class OpenApiHtmlHandler(ApiHandler):
summary='Show API documentation'
)
def get(self):
include_all = self.request.get_query_arg('all', default=False)
html_template = pkgutil.get_data('xcube.webapi.meta',
'res/openapi.html').decode('utf-8')
self.response.finish(Template(html_template).substitute(
open_api_url=self.request.url_for_path('openapi.json')
open_api_url=self.request.url_for_path(
'openapi.json' + ('?all=1' if include_all else '')
)
))


Expand All @@ -60,7 +63,10 @@ class OpenApiJsonHandler(ApiHandler):
summary='Get API documentation as OpenAPI 3.0 JSON document'
)
def get(self):
self.response.finish(self.ctx.open_api_doc)
include_all = self.request.get_query_arg('all', default=False)
self.response.finish(self.ctx.get_open_api_doc(
include_all=include_all
))


@api.route("/maintenance/fail")
Expand Down

0 comments on commit 8e04dde

Please sign in to comment.