To remove an endpoint using the CustomSchemaGenerator class, you can override the get_paths method and remove the unwanted endpoint from the paths dictionary before it is added to the schema.

Here's an example:

from drf_yasg import openapi
from drf_yasg.generators import OpenAPISchemaGenerator

class CustomSchemaGenerator(OpenAPISchemaGenerator):
    def get_paths(self, endpoints, components, request):
        paths = super().get_paths(endpoints, components, request)
        
        # Remove the unwanted endpoint
        if '/path/to/remove/' in paths:
            del paths['/path/to/remove/']
        
        return paths

In this example, the get_paths method is overridden to remove an endpoint with the path '/path/to/remove/'. The super() method is used to call the original get_paths method and get the paths dictionary. The unwanted endpoint is then removed from the paths dictionary using the del statement. Finally, the modified paths dictionary is returned.

To use this CustomSchemaGenerator class in your Django project, you can set it as the default schema generator in your settings.py file:

SWAGGER_SETTINGS = {
    'DEFAULT_GENERATOR_CLASS': 'path.to.CustomSchemaGenerator',
    # ...
}

原文地址: http://www.cveoy.top/t/topic/bux0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录