in src/lambdas/modular_api_handler/handler.py [0:0]
def iter_endpoint(self) -> Generator[EndpointInfo, None, None]:
"""
For swagger. The collection of EndpointInfo(s) can be hardcoded or
generated some other way. I think this is quite convenient. Just add
a new endpoint and it will automatically appear in swagger
:return:
"""
for route in self.mapper.matchlist:
route: Route
kargs = route._kargs
controller, action = kargs['controller'], kargs['action']
handler = self._controllers[controller].get_action_handler(action)
annotations = handler.__annotations__
req = annotations.get('event')
if not isinstance(req, type) or not issubclass(req, BaseModel):
req = None
# expanding responses with common ones
responses = kargs.get('_responses') or []
existing = {r[0] for r in responses}
for code, model, description in common_responses:
if code in existing:
continue
responses.append((code, model, description))
if '{' in route.routepath and HTTPStatus.NOT_FOUND not in existing:
responses.append(
(HTTPStatus.NOT_FOUND, MessageModel, 'Entity is not found')
)
responses.sort(key=lambda x: x[0])
for method in route.conditions['method']:
yield EndpointInfo(
path=route.routepath,
method=method if isinstance(method, HTTPMethod) else HTTPMethod(method.upper()),
summary=kargs.get('_summary'),
description=kargs.get('_description'),
request_model=req,
responses=responses,
auth=kargs['_require_auth']
)