add scalar

This commit is contained in:
tuna2134
2024-09-27 12:35:33 +00:00
parent f5609035b7
commit 395f5b0004
3 changed files with 18 additions and 14 deletions

16
Cargo.lock generated
View File

@@ -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",
]

View File

@@ -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"]

View File

@@ -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<utoipa::openapi::OpenApi> {
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}");