Skip to content

Commit

Permalink
consolidate sort fix for enum sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Mar 1, 2023
1 parent 15012d9 commit bc58f8f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions drf_spectacular/contrib/django_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ def resolve_filter_field(self, auto_schema, model, filterset_class, field_name,
# explicit filter choices may disable enum retrieved from model
if not schema_from_override and filter_choices is not None:
enum = filter_choices
if enum:
schema['enum'] = sorted(enum, key=str)

description = schema.pop('description', None)
if filter_field.extra.get('help_text', None):
Expand Down Expand Up @@ -194,6 +192,7 @@ def resolve_filter_field(self, auto_schema, model, filterset_class, field_name,
location=OpenApiParameter.QUERY,
description=description,
schema=schema,
enum=enum,
explode=explode,
style=style
)
Expand Down
4 changes: 2 additions & 2 deletions drf_spectacular/plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ def build_parameter_type(
if enum:
# in case of array schema, enum makes little sense on the array itself
if schema['schema'].get('type') == 'array':
schema['schema']['items']['enum'] = sorted(enum)
schema['schema']['items']['enum'] = sorted(enum, key=str)
else:
schema['schema']['enum'] = sorted(enum)
schema['schema']['enum'] = sorted(enum, key=str)
if pattern is not None:
# in case of array schema, pattern only makes sense on the items
if schema['schema'].get('type') == 'array':
Expand Down

0 comments on commit bc58f8f

Please sign in to comment.