Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django drf-spectacular - Can you exclude specific paths?

We have a bunch of api's with different versions in urls.py, eg

  • api/v1
  • api/v2
  • api/v3

. We want to implement swagger with drf-spectacular, but we only want to expose api/v3 endpoints.

Is there a way to do this? I cannot make sense of the documentation.

Thanks

like image 377
Gareth Avatar asked Jan 21 '26 22:01

Gareth


1 Answers

This works for me:

def preprocessing_filter_spec(endpoints):
    filtered = []
    for (path, path_regex, method, callback) in endpoints:
        # Remove all but DRF API endpoints
        if path.startswith("/api/"):
            filtered.append((path, path_regex, method, callback))
    return filtered

In settings:

"PREPROCESSING_HOOKS": ["common.openapi.preprocessing_filter_spec"],
like image 177
Chris Avatar answered Jan 23 '26 19:01

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!