Skip to content

Commit

Permalink
wip Try upgrading to Connexion 3
Browse files Browse the repository at this point in the history
  • Loading branch information
juhoinkinen committed Apr 28, 2023
1 parent 3451bd3 commit 79648cd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
57 changes: 51 additions & 6 deletions annif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import os.path

import connexion

# from flask import Flask
from flask_cors import CORS

from annif.openapi.validation import CustomRequestBodyValidator
# from annif.openapi.validation import CustomRequestBodyValidator

logging.basicConfig()
logger = logging.getLogger("annif")
Expand All @@ -21,7 +23,8 @@ def create_app(config_name=None):
# as a property (cxapp.app)

specdir = os.path.join(os.path.dirname(__file__), "openapi")
cxapp = connexion.App(__name__, specification_dir=specdir)
# cxapp = connexion.App(__name__, specification_dir=specdir)
cxapp = connexion.FlaskApp(__name__, specification_dir=specdir)
if config_name is None:
config_name = os.environ.get("ANNIF_CONFIG")
if config_name is None:
Expand All @@ -33,10 +36,10 @@ def create_app(config_name=None):
cxapp.app.config.from_object(config_name)
cxapp.app.config.from_envvar("ANNIF_SETTINGS", silent=True)

validator_map = {
"body": CustomRequestBodyValidator,
}
cxapp.add_api("annif.yaml", validator_map=validator_map)
# validator_map = {
# "body": CustomRequestBodyValidator,
# }
cxapp.add_api("annif.yaml") # validator_map=validator_map)

# add CORS support
CORS(cxapp.app)
Expand All @@ -52,3 +55,45 @@ def create_app(config_name=None):

# return the Flask app
return cxapp.app


# def create_app(config_name=None):
# # 'cxapp' here is the Connexion application that has a normal Flask app
# # as a property (cxapp.app)

# specdir = os.path.join(os.path.dirname(__file__), "openapi")
# app = Flask(__name__)

# if config_name is None:
# config_name = os.environ.get("ANNIF_CONFIG")
# if config_name is None:
# if os.environ.get("FLASK_RUN_FROM_CLI") == "true":
# config_name = "annif.default_config.Config"
# else:
# config_name = "annif.default_config.ProductionConfig"
# logger.debug("creating app with configuration %s", config_name)
# app.config.from_object(config_name)
# app.config.from_envvar("ANNIF_SETTINGS", silent=True)

# cxapp = connexion.ConnexionMiddleware(
# app,
# specification_dir=specdir,
# )
# cxapp.add_api(
# "annif.yaml"
# )

# if cxapp.app.config["INITIALIZE_PROJECTS"]:
# annif.registry.initialize_projects(cxapp.app)
# logger.info("finished initializing projects")

# # add CORS support
# CORS(cxapp.app)

# # register the views via blueprints
# from annif.views import bp

# cxapp.app.register_blueprint(bp)

# # return the Flask app
# return cxapp.app
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ classifiers=[
[tool.poetry.dependencies]
python = ">=3.8,<3.11"

connexion = {version = "2.14.*", extras = ["swagger-ui"]}
flask = ">=1.0.4,<3"
connexion = {version = "3.0.0a6", allow-prereleases = true, extras = ["flask"]}
# flask = ">=1.0.4,<3"
flask-cors = "3.0.*"
click = "8.1.*"
click-log = "0.4.*"
Expand Down

0 comments on commit 79648cd

Please sign in to comment.