openapi / actix-swagger

Swagger code generator for actix-web framework
https://crates.io/crates/cargo-swagg
MIT License
113 stars 8 forks source link

Usage issue #21

Closed Cyrelb closed 4 years ago

Cyrelb commented 4 years ago

Hi, I have issue to integrate the library. My code is the following:

Main:

fn main() {
    HttpServer::new(move || {
        App::new()
            .data(AppState {
                pool: pool.clone(),
                log: log.clone(),
            })
            .wrap(middleware::Logger::default())
            .route("/", web::get().to(status))
            .route("/test{_:/?}", web::get().to(test))
    })
    .bind(format!("{}:{}", config.server.host, config.server.port))?
    .run()
    .await
}

Handler:

pub async fn status() -> Result<impl Responder, AppError> {
    Ok(web::HttpResponse::Ok().json(Status {
        status: "Up".to_string(),
    }))
}

pub async fn test(state: web::Data<AppState>) -> Result<impl Responder, AppError> {
    let sublog = state.log.new(o!("handler" => "test"));

    let client: Client = get_client(state.pool.clone(), sublog.clone()).await?;

    let result = db::get_test(&client).await;

    result
        .map(|test| HttpResponse::Ok().json(test))
        .map_err(log_error(sublog))
}
sergeysova commented 4 years ago

@Cyrelb What kind of issue do you have? Is it issue about actix-swagger? Not about actix-web?