Skip to content

Commit

Permalink
Adding two distinct schemas.
Browse files Browse the repository at this point in the history
  • Loading branch information
augustjohnson committed Oct 19, 2024
1 parent 88da113 commit 640c201
Show file tree
Hide file tree
Showing 4 changed files with 22,604 additions and 3,516 deletions.
17 changes: 9 additions & 8 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ def __init__(self, *args, **kwargs):

# The request doesn't exist when generating an OAS file, so we have to check that first
if 'request' in self.context:
fields = self.context['request'].query_params.get('fields')
if fields:
fields = fields.split(',')
# Drop any fields that are not specified in the `fields` argument.
allowed = set(fields)
existing = set(self.fields.keys())
for field_name in existing - allowed:
self.fields.pop(field_name)
if self.context['request'] is not None:
fields = self.context['request'].query_params.get('fields')
if fields:
fields = fields.split(',')
# Drop any fields that are not specified in the `fields` argument.
allowed = set(fields)
existing = set(self.fields.keys())
for field_name in existing - allowed:
self.fields.pop(field_name)

class DynamicFieldsHyperlinkedModelSerializer(
DynamicFieldsModelSerializer, serializers.HyperlinkedModelSerializer
Expand Down
Loading

0 comments on commit 640c201

Please sign in to comment.