diff --git a/annif/openapi/validation.py b/annif/openapi/validation.py index f28086050..2fce37732 100644 --- a/annif/openapi/validation.py +++ b/annif/openapi/validation.py @@ -15,20 +15,16 @@ class CustomRequestBodyValidator(JSONRequestBodyValidator): """Custom request body validator that overrides the default error message for the - 'maxItems' validator for the 'documents' property.""" + 'maxItems' validator for the 'documents' property to prevent logging request body + with the contents of all documents.""" def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) def _validate(self, body: Any) -> dict | None: - if not self._nullable and body is None: - raise BadRequestProblem( - "Request body must not be empty" - ) # pragma: no cover try: return self._validator.validate(body) except ValidationError as exception: - # Prevent logging request body with contents of all documents if exception.validator == "maxItems" and list(exception.schema_path) == [ "properties", "documents", diff --git a/tests/test_openapi.py b/tests/test_openapi.py index d7f347809..76f33695f 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -83,15 +83,6 @@ def test_openapi_suggest_novocab(app_client): assert req.status_code == 503 -def test_openapi_suggest_emptybody(app_client): - data = {} - req = app_client.post( - "http://localhost:8000/v1/projects/dummy-fi/suggest", data=data - ) - assert req.status_code == 400 - assert req.json()["detail"] == "RequestBody is required" - - def test_openapi_suggest_batch(app_client): data = {"documents": [{"text": "A quick brown fox jumped over the lazy dog."}] * 32} req = app_client.post(