From 18b4c698fc081f97bf810a08efdfbafc3393b1e8 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Mon, 23 May 2022 18:00:45 +0200 Subject: [PATCH] add openapi specification for http server --- openapi.yml | 29 +++++++++++++++++++++++++++++ src/Http.cpp | 8 +++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 openapi.yml diff --git a/openapi.yml b/openapi.yml new file mode 100644 index 0000000..191177b --- /dev/null +++ b/openapi.yml @@ -0,0 +1,29 @@ +openapi: "3.0.2" +info: + title: API Title + version: "1.0" +servers: + - url: https://localhost:8000/v1 +paths: + /health: + get: + responses: + "200": + description: OK + content: + "application/json": + schema: + type: object + properties: + healthy: + type: boolean + good: + type: array + items: + type: string + example: "Heartbeat" + bad: + type: array + items: + type: string + example: "ResourceManager" diff --git a/src/Http.cpp b/src/Http.cpp index e1fecd3..828ab22 100644 --- a/src/Http.cpp +++ b/src/Http.cpp @@ -160,6 +160,8 @@ void Http::Server::THttpServerInstance::operator()() try { HttpLibServerInstance->Get(API_V1 "/health", [](const httplib::Request&, httplib::Response& res) { size_t SystemsGood = 0; size_t SystemsBad = 0; + json Good = json::array(); + json Bad = json::array(); auto Statuses = Application::GetSubsystemStatuses(); for (const auto& NameStatusPair : Statuses) { switch (NameStatusPair.second) { @@ -167,16 +169,20 @@ void Http::Server::THttpServerInstance::operator()() try { case Application::Status::ShuttingDown: case Application::Status::Shutdown: case Application::Status::Good: + Good.push_back(NameStatusPair.first); SystemsGood++; break; case Application::Status::Bad: + Bad.push_back(NameStatusPair.first); SystemsBad++; break; } } res.set_content( json { - { "ok", SystemsBad == 0 }, + { "healthy", SystemsBad == 0 }, + { "good", Good }, + { "bad", Bad }, } .dump(), "application/json");