MCPcopy
hub / github.com/encode/starlette / get_endpoints

Method get_endpoints

starlette/schemas.py:40–87  ·  view source on GitHub ↗

Given the routes, yields the following information: - path eg: /users/ - http_method one of 'get', 'post', 'put', 'patch', 'delete', 'options' - func method ready to extract the docstring

(self, routes: list[BaseRoute])

Source from the content-addressed store, hash-verified

38 raise NotImplementedError() # pragma: no cover
39
40 def get_endpoints(self, routes: list[BaseRoute]) -> list[EndpointInfo]:
41 """
42 Given the routes, yields the following information:
43
44 - path
45 eg: /users/
46 - http_method
47 one of 'get', 'post', 'put', 'patch', 'delete', 'options'
48 - func
49 method ready to extract the docstring
50 """
51 endpoints_info: list[EndpointInfo] = []
52
53 for route in routes:
54 if isinstance(route, Mount | Host):
55 routes = route.routes or []
56 if isinstance(route, Mount):
57 path = self._remove_converter(route.path)
58 else:
59 path = ""
60 sub_endpoints = [
61 EndpointInfo(
62 path="".join((path, sub_endpoint.path)),
63 http_method=sub_endpoint.http_method,
64 func=sub_endpoint.func,
65 )
66 for sub_endpoint in self.get_endpoints(routes)
67 ]
68 endpoints_info.extend(sub_endpoints)
69
70 elif not isinstance(route, Route) or not route.include_in_schema:
71 continue
72
73 elif inspect.isfunction(route.endpoint) or inspect.ismethod(route.endpoint):
74 path = self._remove_converter(route.path)
75 for method in route.methods or ["GET"]:
76 if method == "HEAD":
77 continue
78 endpoints_info.append(EndpointInfo(path, method.lower(), route.endpoint))
79 else:
80 path = self._remove_converter(route.path)
81 for method in ["get", "post", "put", "patch", "delete", "options"]:
82 if not hasattr(route.endpoint, method):
83 continue
84 func = getattr(route.endpoint, method)
85 endpoints_info.append(EndpointInfo(path, method.lower(), func))
86
87 return endpoints_info
88
89 def _remove_converter(self, path: str) -> str:
90 """

Callers 1

get_schemaMethod · 0.80

Calls 3

_remove_converterMethod · 0.95
EndpointInfoClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected