From 0bf1ab250fddaa868c3dc694ad3af7a669cc806c Mon Sep 17 00:00:00 2001 From: Joe Rogers <1337joe@users.noreply.github.com> Date: Tue, 22 Apr 2025 02:02:03 +0200 Subject: [PATCH] Schema: Require pagination limit parameter (#9547) * Ensure pagination limit is set on schema list queries * Bump api version * Update api_version.py * Bump version again --------- Co-authored-by: Matthias Mair --- src/backend/InvenTree/InvenTree/api_version.py | 4 +++- src/backend/InvenTree/InvenTree/schema.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index bbf63ceff5..3e69a0e009 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,12 +1,14 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 340 +INVENTREE_API_VERSION = 341 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v341 -> 2025-04-21 : https://github.com/inventree/InvenTree/pull/9547 + - Require pagination limit on list queries v340 -> 2025-04-15 : https://github.com/inventree/InvenTree/pull/9546 - Add nullable to various fields to make them not required diff --git a/src/backend/InvenTree/InvenTree/schema.py b/src/backend/InvenTree/InvenTree/schema.py index 0750236308..f051af08e2 100644 --- a/src/backend/InvenTree/InvenTree/schema.py +++ b/src/backend/InvenTree/InvenTree/schema.py @@ -8,6 +8,7 @@ from drf_spectacular.drainage import warn from drf_spectacular.openapi import AutoSchema from drf_spectacular.plumbing import ComponentRegistry from drf_spectacular.utils import _SchemaType +from rest_framework.pagination import LimitOffsetPagination from InvenTree.permissions import OASTokenMixin from users.oauth2_scopes import oauth2_scopes @@ -80,6 +81,16 @@ class ExtendedAutoSchema(AutoSchema): operation['requestBody'] = request_body self.method = original_method + # If pagination limit is not set (default state) then all results will return unpaginated. This doesn't match + # what the schema defines to be the expected result. This forces limit to be present, producing the expected + # type. + pagination_class = getattr(self.view, 'pagination_class', None) + if pagination_class and pagination_class == LimitOffsetPagination: + parameters = operation.get('parameters', []) + for parameter in parameters: + if parameter['name'] == 'limit': + parameter['required'] = True + return operation