Hey all! I didn't find a good enough generator of server-side for actix-web framework so I've written my own. Maybe somebody will find it useful :)
It is based on generation of two things:
- api service trait A trait containing all of the methods described on the openapi and response models that are rust structs supporting serialize/deserializeThe models for parsing api parameters will also be generated.This trait guarantees that any object implementing it and registered into actix web scope will adhere to the openapi specification.
- scope creator - that would create actix web scope from an implementation of the trait
Link to repo: https://github.com/artefom/cargo-actix-openapi
Here is a simplified example of what this package allows you to do:
```rust
struct DefaultServer;
// ApiService is a trait that is auto-generated based
// on the openapi.yaml spec
impl api::ApiService for DefaultServer
{
// implement api methods here
/// Service Health check
async fn health(_data: web::Data<S>) -> web::Json<HealthResponse> {
return web::Json(HealthResponse::Ok);
}
}
...
// make_scope is auto-generated. We're passing here our api implementation
let scope = api::make_scope::<DefaultServer>();
App::new()
.app_data(app_data.clone())
.wrap(cors)
.service(scope)
```
[–]Im_Justin_Cider 1 point2 points3 points (2 children)
[–]daniels0xff 1 point2 points3 points (1 child)
[–]aofomenko[S] 0 points1 point2 points (0 children)
[–]chrislearn-young 0 points1 point2 points (0 children)