There seems to be an option for ApiView
swagger_schema = None
I'd like to prevent some endpoints being generated (it's just too many of them)
Hello,
As mentioned in the docs (https://drf-yasg.readthedocs.io/en/stable/custom_spec.html#excluding-endpoints), you'd have to decorate the excluded endpoints with swagger_auto_schema and pass it auto_schema=None.
Example:
class MyViewSet(viewsets.ModelViewSet):
@swagger_auto_schema(auto_schema=None)
def list(self, request, *args, **kwargs):
# ....
This way, the get operation on your viewset list will not be output in the resulting swagger.
Oh great, is it possible to exclude entire viewset?
You could decorate all of your viewset's methods the same way to exclude them all (you can use Django's method_decorator as described in swagger_auto_schema's docs).
If this seems a bit tedious, I think you can also
endpoint_enumerator_class with your own EndpointEnumeratorI haven't tried that solution, but I guess it would be cleaner to avoid decorating every method for every unwanted viewset.
For me, using schema = None works fine:
class SomeViewSet(GenericViewSet):
schema = None
Most helpful comment
Hello,
As mentioned in the docs (https://drf-yasg.readthedocs.io/en/stable/custom_spec.html#excluding-endpoints), you'd have to decorate the excluded endpoints with
swagger_auto_schemaand pass itauto_schema=None.Example:
This way, the
getoperation on your viewset list will not be output in the resulting swagger.