我正在尝试基于OpenAPI JSON获取所有 API端点的计时信息,因此我想在setup
方法中执行以下操作:
for api_path in self.client.get('/api/doc/?format=openapi').json()['paths'].keys():
self.get_[api_path] = [@task decorated method which retrieves the API path]
还是有另一种在运行时生成任务的方法?
答案 0 :(得分:0)
在API docs中找到了它:
def setup(self) -> None:
for api_path in self.client.get('/api/doc/?format=openapi').json()['paths'].keys():
self.schedule_task(self.api_task, args=[api_path])
def api_task(self, path: str) -> None:
response = self.client.get("/api{}?limit=1000".format(path))
assert response.status_code == HTTPStatus.OK, response.content.decode()