2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-27 19:16:44 +00:00

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 <code@mjmair.com>
This commit is contained in:
Joe Rogers 2025-04-22 02:02:03 +02:00 committed by GitHub
parent 89b3f91ded
commit 0bf1ab250f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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