From 1306849b5751bbcfca2486fdaac60867193529f5 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 25 Apr 2024 23:01:22 +0100 Subject: [PATCH] tests: Ensure API schemas are actually valid Signed-off-by: Stephen Finucane Change-Id: Ie085fbe965894a1cd5e78ba8d652ced50c77f3de Partially-implements: bp json-schema-validation --- manila/tests/api/test_schemas.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/manila/tests/api/test_schemas.py b/manila/tests/api/test_schemas.py index f9a113b5f3..bec7745401 100644 --- a/manila/tests/api/test_schemas.py +++ b/manila/tests/api/test_schemas.py @@ -10,7 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. +import jsonschema.exceptions + from manila.api.v2 import router +from manila.api.validation import validators from manila import test @@ -19,11 +22,19 @@ class SchemaTest(test.TestCase): def setUp(self): super().setUp() self.router = router.APIRouter() + self.meta_schema = validators._SchemaValidator.validator_org def test_schemas(self): missing_request_schemas = set() missing_query_schemas = set() missing_response_schemas = set() + invalid_schemas = set() + + def _validate_schema(func, schema): + try: + self.meta_schema.check_schema(schema) + except jsonschema.exceptions.SchemaError: + invalid_schemas.add(func.__qualname__) def _validate_func(func, method): if getattr(func, 'removed', False): @@ -33,14 +44,20 @@ class SchemaTest(test.TestCase): # request body validation if not hasattr(func, '_request_body_schema'): missing_request_schemas.add(func.__qualname__) + else: + _validate_schema(func, func._request_body_schema) elif method in ("GET",): # request query string validation if not hasattr(func, '_request_query_schema'): missing_query_schemas.add(func.__qualname__) + else: + _validate_schema(func, func._request_query_schema) # response body validation if not hasattr(func, '_response_body_schema'): missing_response_schemas.add(func.__qualname__) + else: + _validate_schema(func, func._response_body_schema) for route in self.router.map.matchlist: if 'controller' not in route.defaults: