Skip to content

Commit 46efb72

Browse files
committed
websocket: fix OpenAPI docs registration in AttachedRuntime
1 parent 7e7ce73 commit 46efb72

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ if (WEBSOCKET_SOURCES)
153153
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
154154
)
155155
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
156-
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")
156+
FILES_MATCHING
157+
PATTERN "*.hpp"
158+
PATTERN "*.h"
159+
PATTERN "*.inc")
157160

158161
# HEADER-ONLY
159162
else()

include/vix/websocket/AttachedRuntime.hpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#include <vix/config/Config.hpp>
2020
#include <vix/utils/ServerPrettyLogs.hpp>
2121
#include <vix/experimental/ThreadPoolExecutor.hpp>
22+
#include <vix/console.hpp>
2223

23-
// WebSocket OpenAPI docs (router-based)
2424
#include <vix/websocket/openapi_docs.hpp>
25+
#include <vix/openapi/register_docs.hpp>
2526

2627
#include <atomic>
2728
#include <chrono>
@@ -137,20 +138,28 @@ namespace vix
137138
*/
138139
inline void run_http_and_ws(vix::App &app, vix::websocket::Server &ws, int port = 8080)
139140
{
140-
// Register docs once (global registry). No router needed.
141141
register_ws_openapi_docs_once();
142-
142+
auto r = app.router();
143+
if (r)
144+
vix::openapi::register_openapi_and_docs(*r, "Vix API", "0.0.0");
143145
vix::websocket::AttachedRuntime runtime{app, ws};
144146

145-
app.listen(port, [&](const vix::utils::ServerReadyInfo &base)
147+
app.listen(port, [&]()
148+
{
149+
if (!app.has_server_ready_info())
146150
{
147-
vix::utils::ServerReadyInfo info = base;
148-
info.show_ws = true;
149-
info.ws_scheme = "ws";
150-
info.ws_host = "localhost";
151-
info.ws_port = ws.port();
152-
info.ws_path = "/";
153-
vix::utils::RuntimeBanner::emit_server_ready(info); });
151+
console.warn("server ready info not available");
152+
return;
153+
}
154+
155+
auto info = app.server_ready_info();
156+
info.show_ws = true;
157+
info.ws_scheme = "ws";
158+
info.ws_host = "localhost";
159+
info.ws_port = ws.port();
160+
info.ws_path = "/";
161+
162+
vix::utils::RuntimeBanner::emit_server_ready(info); });
154163

155164
app.wait();
156165
app.close();

0 commit comments

Comments
 (0)