Story #3472

Updated by daviddavis almost 2 years ago

Working on the Ansible plugin, we have multiple content types (roles, role versions, and more in the future). For role, I was thinking about defining my content viewset to be 'role' which pulpcore automatically sets up as "/api/v3/content/role/". See:

That got me thinking: what if another plugin has a role type?

Apparently if I have two viewsets that define type 'role', the application just selects one of the two. I can't make out which it prefers though.

By convention (meaning, in the plugin docs), plugins are encouraged to namespace their "Detail" endpoints by plugin name.

This is done in the viewset:

<pre><code class="python">
class AnsibleRoleViewSet(ContentViewSet):

# the endpoint becomes v3/content/ansible/roles
endpoint_name = 'ansible/roles'
queryset = AnsibleRole.objects.all()
model = AnsibleRole
serializer_class = AnsibleRoleSerializer

For some plugins, this is awkward because they only have one type, like the file plugin. Following this convention, the endpoint will be v3/content/file/files/. v3/content/file/file/. If the file plugin chooses, they can keep v3/content/file/, but if they do this, they should be aware that adding other content types later will either create inconsistency or will be backwards incompatible. v3/content/file/newfile/.