forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswagger.cc
More file actions
36 lines (31 loc) · 1.04 KB
/
swagger.cc
File metadata and controls
36 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "swagger.h"
#include "cortex_openapi.h"
#include "utils/cortex_utils.h"
Json::Value SwaggerController::GenerateOpenApiSpec() const {
Json::Value root;
Json::Reader reader;
reader.parse(CortexOpenApi::GetOpenApiJson(), root);
Json::Value server_url;
server_url["url"] = "http://" + host_ + ":" + port_;
Json::Value resp_data(Json::arrayValue);
resp_data.append(server_url);
root["servers"] = resp_data;
return root;
}
void SwaggerController::serveSwaggerUI(
const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& callback) const {
(void)req;
auto resp = cortex_utils::CreateCortexHttpResponse();
resp->setBody(ScalarUi);
resp->setContentTypeCode(drogon::CT_TEXT_HTML);
callback(resp);
}
void SwaggerController::serveOpenAPISpec(
const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& callback) const {
(void)req;
auto spec = GenerateOpenApiSpec();
auto resp = cortex_utils::CreateCortexHttpJsonResponse(spec);
callback(resp);
}