diff --git a/Cargo.lock b/Cargo.lock index a0330bf..5dd58db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1920,6 +1920,7 @@ dependencies = [ "serde", "tokio", "utoipa", + "utoipa-scalar", ] [[package]] @@ -2470,6 +2471,17 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "utoipa-scalar" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3ab4b7269d14d93626b0bfedf212f1b0995cb7d13d35daba21d579511e7fae8" +dependencies = [ + "serde", + "serde_json", + "utoipa", +] + [[package]] name = "version_check" version = "0.9.5" @@ -2504,7 +2516,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.77", "wasm-bindgen-shared", ] @@ -2526,7 +2538,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/sbv2_api/Cargo.toml b/sbv2_api/Cargo.toml index 01b4a3a..989302e 100644 --- a/sbv2_api/Cargo.toml +++ b/sbv2_api/Cargo.toml @@ -13,6 +13,7 @@ sbv2_core = { version = "0.2.0-alpha", path = "../sbv2_core" } serde = { version = "1.0.210", features = ["derive"] } tokio = { version = "1.40.0", features = ["full"] } utoipa = { version = "4.2.3", features = ["axum_extras"] } +utoipa-scalar = "0.1.0" [features] coreml = ["sbv2_core/coreml"] diff --git a/sbv2_api/src/main.rs b/sbv2_api/src/main.rs index e94a625..3fb9f59 100644 --- a/sbv2_api/src/main.rs +++ b/sbv2_api/src/main.rs @@ -12,6 +12,7 @@ use std::sync::Arc; use tokio::fs; use tokio::sync::Mutex; use utoipa::{OpenApi, ToSchema}; +use utoipa_scalar::{Scalar, Servable}; mod error; use crate::error::AppResult; @@ -23,17 +24,6 @@ use crate::error::AppResult; )] struct ApiDoc; -#[utoipa::path( - get, - path = "/docs/openapi.json", - responses( - (status = 200, description = "JSON file", body = ()) - ) -)] -async fn openapi() -> Json { - Json(ApiDoc::openapi()) -} - #[utoipa::path( get, path = "/models", @@ -173,7 +163,8 @@ async fn main() -> anyhow::Result<()> { .route("/", get(|| async { "Hello, World!" })) .route("/synthesize", post(synthesize)) .route("/models", get(models)) - .with_state(AppState::new().await?); + .with_state(AppState::new().await?) + .merge(Scalar::with_url("/docs", ApiDoc::openapi())) let addr = env::var("ADDR").unwrap_or("0.0.0.0:3000".to_string()); let listener = tokio::net::TcpListener::bind(&addr).await?; log::info!("Listening on {addr}");