Skip to content

Commit

Permalink
Merge pull request #1807 from dandi/fix-swagger-types
Browse files Browse the repository at this point in the history
Generate correct docs for dandisets endpoint
  • Loading branch information
waxlamp authored Jan 4, 2024
2 parents b9efde8 + 3e172d5 commit 6b5641f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dandiapi/api/views/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.conf import settings
from django.contrib.auth.validators import UnicodeUsernameValidator
from django.db.models.query_utils import Q
from drf_yasg.utils import swagger_serializer_method
from rest_framework import serializers

from dandiapi.api.models import Asset, AssetBlob, AssetPath, Dandiset, Version
Expand Down Expand Up @@ -122,13 +123,15 @@ class DandisetListSerializer(DandisetSerializer):
class Meta(DandisetSerializer.Meta):
fields = [*DandisetSerializer.Meta.fields, 'most_recent_published_version', 'draft_version']

@swagger_serializer_method(serializer_or_field=DandisetVersionSerializer)
def get_draft_version(self, dandiset):
draft = self.context['dandisets'].get(dandiset.id, {}).get('draft')
if draft is None:
return None

return DandisetVersionSerializer(draft).data

@swagger_serializer_method(serializer_or_field=DandisetVersionSerializer)
def get_most_recent_published_version(self, dandiset):
version = self.context['dandisets'].get(dandiset.id, {}).get('published')
if version is None:
Expand Down

0 comments on commit 6b5641f

Please sign in to comment.