use dummy json file. not working

This commit is contained in:
Frank Denzer 2023-07-19 11:02:28 +02:00
parent 32f0ed27a7
commit 122f33eae9
3 changed files with 50 additions and 21 deletions

View file

@ -6,18 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
# Compiling actix-server v2.2.0
# Compiling actix-http v3.3.1
# Compiling actix-web v4.3.1
actix-web ="4" actix-web ="4"
actix-files = "*"
# Compiling actix-rt v2.8.0
actix-rt = "*"
#actix-swagger = "*"
serde = "*"
#utoipa = { version = "3", features = ["actix_extras"] }
# Compiling utoipa-swagger-ui v3.1.4
utoipa-swagger-ui = { version = "3", features = ["actix-web"] } utoipa-swagger-ui = { version = "3", features = ["actix-web"] }
[[bin]] [[bin]]

View file

@ -1,10 +1,30 @@
HttpServer::new(move || { use actix_web::{web, App, HttpResponse, HttpServer};
App::new() use utoipa_swagger_ui::{get_swagger_ui, DefaultConfig};
.service(
SwaggerUi::new("/swagger-ui/{_:.*}") #[actix_web::main]
.url("/api-docs/openapi.json", ApiDoc::openapi()), async fn main() -> std::io::Result<()> {
) HttpServer::new(|| {
}) let swagger_config = DefaultConfig::new("http://localhost:8080", "/openapi.json");
.bind((Ipv4Addr::UNSPECIFIED, 8000)).unwrap() App::new()
.run(); .service(get_swagger_ui(&swagger_config))
.route("/openapi.json", web::get().to(get_openapi_spec))
})
.bind("0.0.0.0:8080")?
.run()
.await
}
async fn get_openapi_spec() -> HttpResponse {
let openapi_spec = r#"
{
"openapi": "3.0.0",
"info": {
"title": "Dummy API",
"version": "1.0"
},
"paths": {}
}
"#;
HttpResponse::Ok().body(openapi_spec)
}

19
backend/openapi.json Normal file
View file

@ -0,0 +1,19 @@
{
"openapi": "3.0.0",
"info": {
"title": "My API",
"version": "1.0"
},
"paths": {
"/example": {
"get": {
"summary": "Get example",
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}