diff --git a/connexion/decorators/validation.py b/connexion/decorators/validation.py index e30f90a03..30e9ea72c 100644 --- a/connexion/decorators/validation.py +++ b/connexion/decorators/validation.py @@ -8,9 +8,14 @@ import logging from typing import AnyStr, Union -import pkg_resources +try: + from importlib.metadata import version +except ImportError: + from importlib_metadata import version + from jsonschema import Draft4Validator, ValidationError, draft4_format_checker from jsonschema.validators import extend +from packaging.version import Version from werkzeug.datastructures import FileStorage from ..exceptions import (BadRequestProblem, ExtraParameterProblem, @@ -20,9 +25,7 @@ from ..lifecycle import ConnexionResponse from ..utils import all_json, boolean, is_json_mimetype, is_null, is_nullable -_jsonschema_3_or_newer = pkg_resources.parse_version( - pkg_resources.get_distribution("jsonschema").version) >= \ - pkg_resources.parse_version("3.0.0") +_jsonschema_3_or_newer = Version(version("jsonschema")) >= Version("3.0.0") logger = logging.getLogger('connexion.decorators.validation') diff --git a/connexion/spec.py b/connexion/spec.py index 7ac7a9c4d..5b0a1a24f 100644 --- a/connexion/spec.py +++ b/connexion/spec.py @@ -6,12 +6,12 @@ import copy import json import pathlib +import pkgutil from collections.abc import Mapping from urllib.parse import urlsplit import jinja2 import jsonschema -import pkg_resources import yaml from jsonschema import Draft4Validator from jsonschema.validators import extend as extend_validator @@ -206,9 +206,9 @@ class Swagger2Specification(Specification): yaml_name = 'swagger.yaml' operation_cls = Swagger2Operation - schema_string = pkg_resources.resource_string('connexion', 'resources/schemas/v2.0/schema.json') - openapi_schema = json.loads(schema_string.decode('utf-8')) - del schema_string + openapi_schema = json.loads( + pkgutil.get_data('connexion', 'resources/schemas/v2.0/schema.json') + ) @classmethod def _set_defaults(cls, spec): @@ -259,9 +259,9 @@ class OpenAPISpecification(Specification): yaml_name = 'openapi.yaml' operation_cls = OpenAPIOperation - schema_string = pkg_resources.resource_string('connexion', 'resources/schemas/v3.0/schema.json') - openapi_schema = json.loads(schema_string.decode('utf-8')) - del schema_string + openapi_schema = json.loads( + pkgutil.get_data('connexion', 'resources/schemas/v3.0/schema.json') + ) @classmethod def _set_defaults(cls, spec): diff --git a/setup.py b/setup.py index 3814ce3ec..9b8d7b72e 100755 --- a/setup.py +++ b/setup.py @@ -26,6 +26,8 @@ def read_version(package): 'requests>=2.9.1,<3', 'inflection>=0.3.1,<0.6', 'werkzeug>=1.0,<3', + 'importlib-metadata>=1 ; python_version<"3.8"', + 'packaging>=20', ] swagger_ui_require = 'swagger-ui-bundle>=0.0.2,<0.1'