Skip to content

Commit

Permalink
do not set enums of fields on endpoint if more than 100 fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mstingl committed Sep 29, 2024
1 parent 528e017 commit 2137113
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions djfapi/routing/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def _create_route_list(self):
response_model=self.list,
summary=f'{self.model.__name__} list',
responses=self._additional_responses(Method.GET_LIST),
openapi_extra={'_djfapi_query_fields': self.search_filter_fields},
openapi_extra={'_djfapi_query_fields': self.search_filter_fields} if len(self.model_fields) < 100 else {},
)

def _create_route_aggregate(self):
Expand Down Expand Up @@ -755,14 +755,15 @@ def create_depends_search(self):
return forge.sign(forge.kwarg('_request', type=Request))(self.search_filter)

def _depends_search(self):
order_fields = self.order_fields if len(self.model_fields) < 100 else str
yield forge.kwarg('search', type=models.Q, default=Depends(self.create_depends_search()))
yield forge.kwarg(
'pagination',
type=Pagination,
default=Depends(
forge.modify(
'order_by',
type=Optional[List[self.order_fields]],
type=Optional[List[order_fields]],
default=Query(
self.pagination_options.get('default_order_by', list()),
include_in_schema=self.do_include_query_fields_in_schema,
Expand All @@ -778,7 +779,7 @@ def get_endpoint_description(self, method: Method):
if scopes:
description += "Scopes: " + ", ".join([f'`{scope}`' for scope in scopes]) + "\n\n"

if not self.do_include_query_fields_in_schema:
if not self.do_include_query_fields_in_schema and len(self.search_filter_fields) <= 100:
description += (
"<details><summary>Query fields</summary>Search query for every field can be negated by prepending <code>!</code><br><br>"
+ "".join(
Expand Down Expand Up @@ -861,13 +862,16 @@ def endpoint_aggregate(
)

def _create_endpoint_aggregate(self):
aggregated_fields = self.aggregated_fields if len(self.model_fields) < 100 else str
get_aggregate_group_by = self.get_aggregate_group_by if len(self.model_fields) < 100 else str

return self.endpoint(
Method.GET_AGGREGATE,
signature=[
forge.kwarg('aggregation_function', type=AggregationFunction, default=Path(...)),
forge.kwarg('field', type=self.aggregated_fields, default=Path(...)),
forge.kwarg('field', type=aggregated_fields, default=Path(...)),
(
forge.kwarg('group_by', type=Optional[List[self.get_aggregate_group_by]], default=Query(None))
forge.kwarg('group_by', type=Optional[List[get_aggregate_group_by]], default=Query(None))
if self.aggregate_group_by is not ...
else None
),
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = djfapi
version = 0.0.72b23
version = 0.0.72b24
author = Manuel Stingl
author_email = [email protected]
description = Utilities for use with FastAPI and django
Expand Down

0 comments on commit 2137113

Please sign in to comment.