3

I'm trying to get timing information for all my API endpoints based on the OpenAPI JSON, so I would like to do something like this in the setup method:

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]

Or is there another way to generate tasks at runtime?

l0b0
  • 55,365
  • 30
  • 138
  • 223

1 Answers1

3

Found it in the 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()
l0b0
  • 55,365
  • 30
  • 138
  • 223