From 65f50770959c0d877d8f138d44f10884cc973905 Mon Sep 17 00:00:00 2001 From: Tiara Rodney Date: Sun, 3 Apr 2022 16:15:14 +0200 Subject: [PATCH] fix(init): add importlib context to connexion init connexion openapi spec reference now provided through importlib context manager, since file will exist inside of python egg, therefore not being accesible through package file path chore: upgrade version --- setup.cfg | 2 +- src/httpaste/__init__.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index af12e9a..0382db4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = httpaste-victorykit -version = 1.0.6-alpha +version = 1.0.7-alpha author = Tiara Rodney author_email = t.rodney@victoryk.it description = a versatile HTTP pastebin diff --git a/src/httpaste/__init__.py b/src/httpaste/__init__.py index 3a4cb21..ca5aeff 100755 --- a/src/httpaste/__init__.py +++ b/src/httpaste/__init__.py @@ -144,6 +144,7 @@ from configparser import ConfigParser from ast import literal_eval from io import StringIO from os import environ +from importlib.resources import path as pkg_resource_path from connexion import FlaskApp from connexion.resolver import RestyResolver @@ -301,13 +302,15 @@ def get_flask_app( options = {"swagger_ui": server_config.swagger_ui} - application = FlaskApp(__name__, specification_dir='schema/') + #context manager returns a pathlib.Path object + with pkg_resource_path('httpaste.schema', 'httpaste.openapi.json') as path: + application = FlaskApp(__name__, specification_dir=path.parent) - application.add_api( - 'httpaste.openapi.json', - options=options, - resolver=RestyResolver('httpaste.controller') - ) + application.add_api( + path.name, + options=options, + resolver=RestyResolver('httpaste.controller') + ) for err_cls in [ BadRequestError,