Commit 39e4f5d5 authored by Konstantin Schulz's avatar Konstantin Schulz

openAPI documentation is now accessible at /mc/api/v1.0/ui

parent 70e003f0
Pipeline #11606 passed with stages
in 2 minutes and 59 seconds
...@@ -61,17 +61,16 @@ def create_app(cfg: Type[Config] = Config) -> Flask: ...@@ -61,17 +61,16 @@ def create_app(cfg: Type[Config] = Config) -> Flask:
return app return app
def full_init(app: Flask, is_csm: bool) -> None: def full_init(app: Flask, cfg: Type[Config] = Config) -> None:
""" Fully initializes the application, including logging.""" """ Fully initializes the application, including logging."""
if is_csm: from mcserver.app.services import DatabaseService
from mcserver.app.services import DatabaseService DatabaseService.init_db_update_info()
DatabaseService.init_db_update_info() DatabaseService.update_exercises(is_csm=True)
DatabaseService.update_exercises(is_csm=is_csm) DatabaseService.init_db_corpus()
DatabaseService.init_db_corpus() if not cfg.TESTING:
if not app.config["TESTING"]: from mcserver.app.services.corpusService import CorpusService
from mcserver.app.services.corpusService import CorpusService CorpusService.init_graphannis_logging()
CorpusService.init_graphannis_logging() start_updater(app)
start_updater(app)
def init_app_common(cfg: Type[Config] = Config, is_csm: bool = False) -> Flask: def init_app_common(cfg: Type[Config] = Config, is_csm: bool = False) -> Flask:
...@@ -91,14 +90,13 @@ def init_app_common(cfg: Type[Config] = Config, is_csm: bool = False) -> Flask: ...@@ -91,14 +90,13 @@ def init_app_common(cfg: Type[Config] = Config, is_csm: bool = False) -> Flask:
if is_csm: if is_csm:
from mcserver.app.services.databaseService import DatabaseService from mcserver.app.services.databaseService import DatabaseService
DatabaseService.init_db_alembic() DatabaseService.init_db_alembic()
tables: List[str] = [Config.DATABASE_TABLE_ALEMBIC, Config.DATABASE_TABLE_CORPUS, Config.DATABASE_TABLE_EXERCISE, if is_csm or cfg.TESTING:
Config.DATABASE_TABLE_UPDATEINFO]
if any(not db.engine.dialect.has_table(db.engine, x) for x in tables):
db.create_all() db.create_all()
from mcserver.app.services.textService import TextService from mcserver.app.services.textService import TextService
TextService.init_proper_nouns_list() TextService.init_proper_nouns_list()
TextService.init_stop_words_latin() TextService.init_stop_words_latin()
full_init(app, is_csm) if is_csm:
full_init(app, cfg)
return app return app
......
"""The corpus list API. Add it to your REST API to provide users with a list of metadata for available texts.""" """The corpus list API. Add it to your REST API to provide users with a list of metadata for available texts."""
from datetime import datetime
from connexion.lifecycle import ConnexionResponse from connexion.lifecycle import ConnexionResponse
from flask import Response from flask import Response
from sqlalchemy.exc import OperationalError, InvalidRequestError from sqlalchemy.exc import OperationalError, InvalidRequestError
......
...@@ -758,7 +758,7 @@ class CsmTestCase(unittest.TestCase): ...@@ -758,7 +758,7 @@ class CsmTestCase(unittest.TestCase):
Mocks.app_dict[self.class_name].app.config["TESTING"] = False Mocks.app_dict[self.class_name].app.config["TESTING"] = False
with patch.object(CorpusService, "init_graphannis_logging"): with patch.object(CorpusService, "init_graphannis_logging"):
with patch.object(mcserver.app, "start_updater") as updater_mock: with patch.object(mcserver.app, "start_updater") as updater_mock:
full_init(Mocks.app_dict[self.class_name].app, True) full_init(Mocks.app_dict[self.class_name].app)
self.assertEqual(updater_mock.call_count, 1) self.assertEqual(updater_mock.call_count, 1)
Mocks.app_dict[self.class_name].app.config["TESTING"] = True Mocks.app_dict[self.class_name].app.config["TESTING"] = True
db.session.query(UpdateInfo).delete() db.session.query(UpdateInfo).delete()
......
...@@ -32,10 +32,17 @@ http { ...@@ -32,10 +32,17 @@ http {
index index.html index.htm; index index.html index.htm;
# enable CORS so the cordova files (config.xml) can be accessed from other domains # enable CORS so the cordova files (config.xml) can be accessed from other domains
add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Origin *;
rewrite ^(.*)mc-service(.*)^ http://localhost:5000$2 last;
try_files $uri $uri/ /index.html =404; try_files $uri $uri/ /index.html =404;
} }
# dirty hack to redirect the OpenAPI requests for their schema definition
location ~ /openapi.json$ {
resolver 127.0.0.11 valid=30s;
set $backend_host mcserver;
rewrite /(.*) /mc/$1 break;
proxy_pass http://$backend_host:5000;
}
location /mc-service/ { location /mc-service/ {
resolver 127.0.0.11 valid=30s; resolver 127.0.0.11 valid=30s;
set $backend_host mcserver; set $backend_host mcserver;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment