To remove a particular endpoint from drf-yasg==1.21.4, you can use the 'exclude_url_patterns' attribute in your 'SwaggerUIRenderer' or 'ReDocRenderer' configuration.

For example, if you want to exclude the '/admin/' endpoint, you can add the following code to your 'settings.py' file:

SWAGGER_SETTINGS = {
    'DEFAULT_GENERATOR_CLASS': 'drf_yasg.generators.OpenAPISchemaGenerator',
    'SECURITY_DEFINITIONS': {
        'Token': {
            'type': 'apiKey',
            'name': 'Authorization',
            'in': 'header'
        }
    },
    'exclude_url_patterns': [
        r'^admin/', # exclude the admin endpoint
    ],
    'USE_SESSION_AUTH': False,
    'JSON_EDITOR': True,
}

This will exclude the '/admin/' endpoint from the generated Swagger documentation. You can add additional regular expressions to the 'exclude_url_patterns' list to exclude other endpoints.


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

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