docs: add OpenAPI specification for Remote Control API

Add comprehensive OpenAPI 3.1 documentation covering all REST endpoints:
- Connection/auth endpoints (ping, cert)
- Playback control (play, pause, seek, volume, next, previous)
- Queue management (add, shuffle, repeat, play index)
- Search (tracks, albums, artists)
- Favorites management
- Library (album/artist details)
- Real-time updates (SSE and WebSocket)

Also add /api/docs endpoint to serve the spec when Remote Control is active.
This enables developers to build custom clients (web, CLI, mobile).
This commit is contained in:
vicrodh committed 2026-02-03 11:34:04 -06:00
1 parent 001cadcbe7
commit 8e7d9de754
2 files changed
+1203 -1

No files matched your search

+1189
View File
File diff suppressed because it is too large. Load diff
+14 -1
View File
@@ -414,6 +414,7 @@ fn build_router(ctx: ApiContext) -> Router {
Router::new() Router::new()
.route("/api/ping", get(ping)) .route("/api/ping", get(ping))
.route("/api/cert", get(get_certificate)) .route("/api/cert", get(get_certificate))
.route("/api/docs", get(get_openapi_spec))
.route("/api/status", get(now_playing)) .route("/api/status", get(now_playing))
.route("/api/now-playing", get(now_playing)) .route("/api/now-playing", get(now_playing))
.route("/api/playback/play", post(play)) .route("/api/playback/play", post(play))
@@ -472,6 +473,16 @@ async fn get_certificate() -> Result<impl IntoResponse, StatusCode> {
Ok((headers, pem)) Ok((headers, pem))
} }
async fn get_openapi_spec() -> impl IntoResponse {
let spec = include_str!("../../../docs/openapi.yaml");
let mut headers = header::HeaderMap::new();
headers.insert(
header::CONTENT_TYPE,
header::HeaderValue::from_static("text/yaml; charset=utf-8"),
);
(headers, spec)
}
async fn now_playing(State(ctx): State<ApiContext>) -> Result<Json<NowPlayingResponse>, StatusCode> { async fn now_playing(State(ctx): State<ApiContext>) -> Result<Json<NowPlayingResponse>, StatusCode> {
let app_state = ctx.app_handle.state::<AppState>(); let app_state = ctx.app_handle.state::<AppState>();
let playback = app_state let playback = app_state
@@ -983,7 +994,9 @@ async fn require_token(
return StatusCode::NO_CONTENT.into_response(); return StatusCode::NO_CONTENT.into_response();
} }
if req.uri().path() == "/api/cert" { // Public endpoints (no auth required)
let path = req.uri().path();
if path == "/api/cert" || path == "/api/docs" {
return next.run(req).await; return next.run(req).await;
} }