From 4a9b4b27433a40b163517882526caa0eef09547c Mon Sep 17 00:00:00 2001 From: Brian Pandola Date: Fri, 9 Sep 2022 02:14:03 -0700 Subject: [PATCH] APIGateway: Fix `openapi-spec-validator` import error (#5458) --- .github/workflows/test_outdated_versions.yml | 2 ++ moto/apigateway/models.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_outdated_versions.yml b/.github/workflows/test_outdated_versions.yml index 63eabd7bd..4a58d08db 100644 --- a/.github/workflows/test_outdated_versions.yml +++ b/.github/workflows/test_outdated_versions.yml @@ -17,6 +17,7 @@ jobs: responses-version: ["0.13.0", "0.15.0", "0.17.0", "0.19.0", "0.20.0" ] mock-version: [ "3.0.5", "4.0.0", "4.0.3" ] werkzeug-version: ["2.0.1", "2.1.1"] + openapi-spec-validator-version: ["0.4.0", "0.5.0"] steps: - name: Checkout repository @@ -37,6 +38,7 @@ jobs: pip install responses==${{ matrix.responses-version }} pip install mock==${{ matrix.mock-version }} pip install werkzeug==${{ matrix.werkzeug-version }} + pip install openapi-spec-validator==${{ matrix.openapi-spec-validator-version }} - name: Run tests run: | diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py index c729b1d31..24d966c85 100644 --- a/moto/apigateway/models.py +++ b/moto/apigateway/models.py @@ -12,7 +12,11 @@ import time from urllib.parse import urlparse import responses -from openapi_spec_validator.exceptions import OpenAPIValidationError +try: + from openapi_spec_validator.validation.exceptions import OpenAPIValidationError +except ImportError: + # OpenAPI Spec Validator < 0.5.0 + from openapi_spec_validator.exceptions import OpenAPIValidationError from moto.core import BaseBackend, BaseModel, CloudFormationModel from .utils import create_id, to_path from moto.core.utils import path_url, BackendDict