marcgibbons / django-rest-swagger

Swagger Documentation Generator for Django REST Framework: deprecated
https://marcgibbons.com/django-rest-swagger/
BSD 2-Clause "Simplified" License
2.59k stars 600 forks source link

Certain endpoints not visible in swagger BUT are fully functional #704

Open pjedur opened 7 years ago

pjedur commented 7 years ago

The endpoints are not visible in swagger but they still work and I can do CRUD requests to those endpoints. I'm using an GenericViewset and it seems that the cause is the queryset sending a get_object_or_404 object to the filter query.

serializer_class = CustomerCommunicationSerializer

def get_queryset(self): customer = get_object_or_404(Customer, pk=self.kwargs.get("customer_pk")) return CustomerCommunication.objects.filter(customer=customer)

Changing the code above to the code below causes the endpoints to show up in swagger

serializer_class = CustomerCommunicationSerializer queryset = CustomerCommunication.objects.all()

craiga commented 7 years ago

I haven't quite got my head around exactly how this works, but DRF somehow builds a schema based on whether it can invoke endpoints or not, and this is the schema that django-rest-swagger displays.

I guess what's happening here is:

You probably just want to have the following:

def get_queryset(self):
    return CustomerCommunication.objects.filter(customer_id= self.kwargs.get("customer_pk"))

I'm pretty sure this isn't an issue in django-rest-swagger through.

pjedur commented 7 years ago

I've already tried that but it returns an empty list when the customer does not exist which is not what I want. I implemented the list method to get the desired results but the code is not nearly as sexy.