diff --git a/nova/api/validation/__init__.py b/nova/api/validation/__init__.py index d12d2cfac19f..9d581e2d53a6 100644 --- a/nova/api/validation/__init__.py +++ b/nova/api/validation/__init__.py @@ -193,6 +193,9 @@ def query_schema(query_params_schema, min_version=None, # those additional parameters. _strip_additional_query_parameters(query_params_schema, req) return func(*args, **kwargs) + + wrapper._query_schema = query_params_schema + return wrapper return add_validator diff --git a/nova/tests/unit/api/openstack/compute/test_schemas.py b/nova/tests/unit/api/openstack/compute/test_schemas.py index a3d59a55ecd5..0812a0970d06 100644 --- a/nova/tests/unit/api/openstack/compute/test_schemas.py +++ b/nova/tests/unit/api/openstack/compute/test_schemas.py @@ -25,19 +25,29 @@ class SchemaTest(test.NoDBTestCase): self.meta_schema = validators._SchemaValidator.validator_org def test_schemas(self): - missing_schemas = set() + missing_request_schemas = set() + missing_query_schemas = set() invalid_schemas = set() def _validate_func(func, method): if method in ("POST", "PUT", "PATCH"): # request body validation if not hasattr(func, '_request_schema'): - missing_schemas.add(func.__qualname__) + missing_request_schemas.add(func.__qualname__) else: try: self.meta_schema.check_schema(func._request_schema) except jsonschema.exceptions.SchemaError: invalid_schemas.add(func.__qualname__) + elif method in ("GET",): + # request query string validation + if not hasattr(func, '_query_schema'): + missing_query_schemas.add(func.__qualname__) + else: + try: + self.meta_schema.check_schema(func._query_schema) + except jsonschema.exceptions.SchemaError: + invalid_schemas.add(func.__qualname__) for route in self.router.map.matchlist: if 'controller' not in route.defaults: @@ -109,10 +119,16 @@ class SchemaTest(test.NoDBTestCase): func = getattr(controller.controller, action) _validate_func(func, method) - if missing_schemas: + if missing_request_schemas: raise test.TestingException( f"Found API resources without schemas: " - f"{sorted(missing_schemas)}" + f"{sorted(missing_request_schemas)}" + ) + + if missing_query_schemas: + raise test.TestingException( + f"Found API resources without query schemas: " + f"{sorted(missing_query_schemas)}" ) if invalid_schemas: