The issue in the provided code is that the endpoints variable is a list, whereas it is expected to be a dictionary with endpoint paths as keys and their corresponding view functions as values.

To fix this, you can modify the get_endpoints method to return a dictionary instead of a list of endpoints:

class CustomSchemaGenerator(OpenAPISchemaGenerator):
    def get_endpoints(self, request):
        endpoints = super().get_endpoints(request)
        # Remove the endpoint with the path '/example/'
        # endpoints = {path: endpoint for path, endpoint in endpoints.items() if path != "/example/"}
        new_endpoints = dict()
        for path, endpoint in endpoints.items():
            new_endpoints[path] = endpoint
        return new_endpoints

Note that you can use a dictionary comprehension to filter out the endpoint with the path /example/ instead of the for loop.

Also, the prefix variable is not used in the provided code and can be removed.

class CustomSchemaGeneratorOpenAPISchemaGenerator def get_endpointsself request endpoints = superget_endpointsrequest # Remove the endpoint with the path example # endpoint

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

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