From 122f33eae9ffc71165fcd246f2f8d71fe646b23a Mon Sep 17 00:00:00 2001 From: Frank Denzer Date: Wed, 19 Jul 2023 11:02:28 +0200 Subject: [PATCH] use dummy json file. not working --- backend/Cargo.toml | 12 +----------- backend/main.rs | 40 ++++++++++++++++++++++++++++++---------- backend/openapi.json | 19 +++++++++++++++++++ 3 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 backend/openapi.json diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 993e5bf..d3f83e5 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -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]] diff --git a/backend/main.rs b/backend/main.rs index 2c06644..df5cd7b 100644 --- a/backend/main.rs +++ b/backend/main.rs @@ -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(); - \ No newline at end of file +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) +} diff --git a/backend/openapi.json b/backend/openapi.json new file mode 100644 index 0000000..486410f --- /dev/null +++ b/backend/openapi.json @@ -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" + } + } + } + } + } +}