mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +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:
		@@ -1,12 +1,14 @@
 | 
				
			|||||||
"""InvenTree API version information."""
 | 
					"""InvenTree API version information."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# InvenTree API version
 | 
					# 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."""
 | 
					"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INVENTREE_API_TEXT = """
 | 
					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
 | 
					v340 -> 2025-04-15 : https://github.com/inventree/InvenTree/pull/9546
 | 
				
			||||||
    - Add nullable to various fields to make them not required
 | 
					    - Add nullable to various fields to make them not required
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@ from drf_spectacular.drainage import warn
 | 
				
			|||||||
from drf_spectacular.openapi import AutoSchema
 | 
					from drf_spectacular.openapi import AutoSchema
 | 
				
			||||||
from drf_spectacular.plumbing import ComponentRegistry
 | 
					from drf_spectacular.plumbing import ComponentRegistry
 | 
				
			||||||
from drf_spectacular.utils import _SchemaType
 | 
					from drf_spectacular.utils import _SchemaType
 | 
				
			||||||
 | 
					from rest_framework.pagination import LimitOffsetPagination
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from InvenTree.permissions import OASTokenMixin
 | 
					from InvenTree.permissions import OASTokenMixin
 | 
				
			||||||
from users.oauth2_scopes import oauth2_scopes
 | 
					from users.oauth2_scopes import oauth2_scopes
 | 
				
			||||||
@@ -80,6 +81,16 @@ class ExtendedAutoSchema(AutoSchema):
 | 
				
			|||||||
            operation['requestBody'] = request_body
 | 
					            operation['requestBody'] = request_body
 | 
				
			||||||
            self.method = original_method
 | 
					            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
 | 
					        return operation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user