mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-23 00:17:00 +00:00
add openapi specification for http server
This commit is contained in:
29
openapi.yml
Normal file
29
openapi.yml
Normal file
@@ -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"
|
||||||
@@ -160,6 +160,8 @@ void Http::Server::THttpServerInstance::operator()() try {
|
|||||||
HttpLibServerInstance->Get(API_V1 "/health", [](const httplib::Request&, httplib::Response& res) {
|
HttpLibServerInstance->Get(API_V1 "/health", [](const httplib::Request&, httplib::Response& res) {
|
||||||
size_t SystemsGood = 0;
|
size_t SystemsGood = 0;
|
||||||
size_t SystemsBad = 0;
|
size_t SystemsBad = 0;
|
||||||
|
json Good = json::array();
|
||||||
|
json Bad = json::array();
|
||||||
auto Statuses = Application::GetSubsystemStatuses();
|
auto Statuses = Application::GetSubsystemStatuses();
|
||||||
for (const auto& NameStatusPair : Statuses) {
|
for (const auto& NameStatusPair : Statuses) {
|
||||||
switch (NameStatusPair.second) {
|
switch (NameStatusPair.second) {
|
||||||
@@ -167,16 +169,20 @@ void Http::Server::THttpServerInstance::operator()() try {
|
|||||||
case Application::Status::ShuttingDown:
|
case Application::Status::ShuttingDown:
|
||||||
case Application::Status::Shutdown:
|
case Application::Status::Shutdown:
|
||||||
case Application::Status::Good:
|
case Application::Status::Good:
|
||||||
|
Good.push_back(NameStatusPair.first);
|
||||||
SystemsGood++;
|
SystemsGood++;
|
||||||
break;
|
break;
|
||||||
case Application::Status::Bad:
|
case Application::Status::Bad:
|
||||||
|
Bad.push_back(NameStatusPair.first);
|
||||||
SystemsBad++;
|
SystemsBad++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.set_content(
|
res.set_content(
|
||||||
json {
|
json {
|
||||||
{ "ok", SystemsBad == 0 },
|
{ "healthy", SystemsBad == 0 },
|
||||||
|
{ "good", Good },
|
||||||
|
{ "bad", Bad },
|
||||||
}
|
}
|
||||||
.dump(),
|
.dump(),
|
||||||
"application/json");
|
"application/json");
|
||||||
|
|||||||
Reference in New Issue
Block a user