1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2025-05-08 22:26:04 +02:00

Add Swagger UI on /swagger

This includes a Swagger UI with an OpenAPI 3.0 JSON schema for easy
interactive demonstration and testing of the API. The JSON schema
was created with the standalone swagger-editor. Includes tests to
make sure that the /swagger and /docs/openapi.json paths are acce-
ssible.
This commit is contained in:
2020-12-22 11:18:47 +02:00
parent 3e271c7852
commit a35ecf2394
5 changed files with 705 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import falcon
import psycopg2.extras
from falcon_swagger_ui import register_swaggerui_app
from .database import DatabaseManager
from .stats import get_downloads, get_views
@ -14,6 +15,14 @@ class RootResource:
resp.body = f.read()
class OpenAPIJSONResource:
def on_get(self, req, resp):
resp.status = falcon.HTTP_200
resp.content_type = "text/html"
with open("dspace_statistics_api/docs/openapi.json", "r") as f:
resp.body = f.read()
class AllStatisticsResource:
@falcon.before(set_statistics_scope)
def on_get(self, req, resp):
@ -178,4 +187,18 @@ api.add_route("/community/{id_:uuid}", SingleStatisticsResource())
api.add_route("/collections", AllStatisticsResource())
api.add_route("/collection/{id_:uuid}", SingleStatisticsResource())
# Swagger configuration
SWAGGERUI_URL = "/swagger" # without trailing slash
SCHEMA_URL = "/docs/openapi.json"
api.add_route("/docs/openapi.json", OpenAPIJSONResource())
register_swaggerui_app(
api,
SWAGGERUI_URL,
SCHEMA_URL,
config={
"supportedSubmitMethods": ["get", "post"],
},
)
# vim: set sw=4 ts=4 expandtab: