Skip to content

Commit

Permalink
Problem: created resources OpenAPI schema is not specific enough
Browse files Browse the repository at this point in the history
Solution: strongly type created resources as an array of strings

This patch changes the CreatedResource serializer to inherit from the RelatedField serializer. This lets the
OpenAPI schema generator know that created resources are URI strings.

closes: #4053
https://pulp.plan.io/issues/4053
  • Loading branch information
dkliban committed Oct 5, 2018
1 parent 13c7e1a commit bb6a217
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pulpcore/pulpcore/app/serializers/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .base import viewset_for_model


class CreatedResourceSerializer(ModelSerializer):
class CreatedResourceSerializer(RelatedField):

def to_representation(self, data):
# If the content object was deleted
Expand Down Expand Up @@ -79,7 +79,8 @@ class TaskSerializer(ModelSerializer):
created_resources = CreatedResourceSerializer(
help_text=_('Resources created by this task.'),
many=True,
read_only=True
read_only=True,
view_name='None' # This is a polymorphic field. The serializer does not need a view name.
)

class Meta:
Expand Down

0 comments on commit bb6a217

Please sign in to comment.