Closed ipconfiger closed 2 days ago
Full cargo.toml
[package]
name = "utoipa-test"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = "0.7"
tokio = { version = "1", features = ["full"] }
tower = "0.5"
utoipa = { version = "4", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "7", features = ["axum"] }
Full rust code main.rs
use std::net::Ipv4Addr;
use axum::{routing, Router};
use tokio::net::TcpListener;
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let app: Router = Router::new()
.route("/health", routing::get(health))
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()));
let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 8080)).await?;
axum::serve(listener, app).await
}
#[derive(OpenApi)]
#[openapi(paths(health))]
struct ApiDoc;
#[utoipa::path(
get,
path = "/health",
responses(
(status = OK, description = "Success", body = str)
)
)]
async fn health() -> &'static str {
"OK"
}
The above will work as shown in the images.
Have you tried cargo clean
. That error indicates that the SwaggerUi
does not implement axum Router
trait. However the utoipa-swagger-ui
does provide this implementation with axum
feature flag.
Have you tried to debug with cargo tree --format "{p} {f}"
to see what features gets where?
OK, tks, will try it
@ipconfiger Can this be considered solved?
cargo clean works,tks
Cargo.toml
Code:
Build result:
What i miss?