api: Add runtime check for query additionalProperties

We also fix some types.

Change-Id: Ie1bf7b55f21cafdd311b1c58018a4c815cf7cc65
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane
2025-08-29 11:44:18 +01:00
parent 405948b06d
commit 36cd19b168
+19 -7
View File
@@ -57,7 +57,7 @@ class Schemas:
def add_schema(
self,
schema: tuple[dict[str, object]],
schema: dict[str, object],
min_version: str | None,
max_version: str | None,
) -> None:
@@ -261,10 +261,12 @@ def schema(
)
return func(*args, **kwargs)
# we need to use setattr/getattr here else we see attr-defined errors
# since this is not an attribute of Callable
if not hasattr(wrapper, 'request_body_schemas'):
wrapper.request_body_schemas = Schemas()
setattr(wrapper, 'request_body_schemas', Schemas())
wrapper.request_body_schemas.add_schema(
getattr(wrapper, 'request_body_schemas').add_schema(
request_body_schema, min_version, max_version
)
@@ -332,10 +334,12 @@ def response_body_schema(
raise
return response
# we need to use setattr/getattr here else we see attr-defined errors
# since this is not an attribute of Callable
if not hasattr(wrapper, 'response_body_schemas'):
wrapper.response_body_schemas = Schemas()
setattr(wrapper, 'response_body_schemas', Schemas())
wrapper.response_body_schemas.add_schema(
getattr(wrapper, 'response_body_schemas').add_schema(
response_body_schema, min_version, max_version
)
@@ -428,13 +432,21 @@ def query_schema(request_query_schema, min_version=None,
_strip_additional_query_parameters(request_query_schema, req)
return func(*args, **kwargs)
# we need to use setattr/getattr here else we see attr-defined errors
# since this is not an attribute of Callable
if not hasattr(wrapper, 'request_query_schemas'):
wrapper.request_query_schemas = Schemas()
setattr(wrapper, 'request_query_schemas', Schemas())
wrapper.request_query_schemas.add_schema(
getattr(wrapper, 'request_query_schemas').add_schema(
request_query_schema, min_version, max_version
)
return wrapper
if (
api_version_request.APIVersionRequest(min_version) >=
api_version_request.APIVersionRequest('2.102')
):
assert request_query_schema['additionalProperties'] is False
return add_validator