use dummy json file. not working
This commit is contained in:
parent
32f0ed27a7
commit
122f33eae9
3 changed files with 50 additions and 21 deletions
|
@ -6,18 +6,8 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# Compiling actix-server v2.2.0
|
||||
# Compiling actix-http v3.3.1
|
||||
# Compiling actix-web v4.3.1
|
||||
actix-web ="4"
|
||||
|
||||
# Compiling actix-rt v2.8.0
|
||||
actix-rt = "*"
|
||||
|
||||
#actix-swagger = "*"
|
||||
serde = "*"
|
||||
#utoipa = { version = "3", features = ["actix_extras"] }
|
||||
# Compiling utoipa-swagger-ui v3.1.4
|
||||
actix-files = "*"
|
||||
utoipa-swagger-ui = { version = "3", features = ["actix-web"] }
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -1,10 +1,30 @@
|
|||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.service(
|
||||
SwaggerUi::new("/swagger-ui/{_:.*}")
|
||||
.url("/api-docs/openapi.json", ApiDoc::openapi()),
|
||||
)
|
||||
})
|
||||
.bind((Ipv4Addr::UNSPECIFIED, 8000)).unwrap()
|
||||
.run();
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
use utoipa_swagger_ui::{get_swagger_ui, DefaultConfig};
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
let swagger_config = DefaultConfig::new("http://localhost:8080", "/openapi.json");
|
||||
App::new()
|
||||
.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
19
backend/openapi.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue