Utoipauto
Rust Macros to automate the addition of Paths/Schemas to Utoipa crate, simulating Reflection during the compilation phase
# Crate presentation
Utoipa is a great crate for generating documentation (openapi/swagger) via source code.
But since Rust is a static programming language, we don't have the possibility of automatically discovering paths and
dto in runtime and adding them to the documentation,
For APIs with just a few endpoints, it's not that much trouble to add controller functions one by one, and DTOs one by
one.
But, if you have hundreds or even thousands of endpoints, the code becomes very verbose and difficult to maintain.
Ex :
```rust
#[derive(OpenApi)]
#[openapi(
paths(
// <================================ All functions 1 to N
test_controller::service::func_get_1,
test_controller::service::func_get_2,
test_controller::service::func_get_3,
test_controller::service::func_get_4,
....
....
....
test_controller::service::func_get_N,
),
components(
// <====================== All DTO one by one
schemas(TestDTO_1, TestDTO_2, ........ , TestDTO_N)
),
tags(
(name = "todo", description = "Todo management endpoints.")
),
modifiers(&SecurityAddon)
)]
pub struct ApiDoc;
```
The goal of this crate is to propose a macro that automates the detection of methods carrying Utoipa
macros (`#[utoipa::path(...]`), and adds them automatically. (it also detects sub-modules.)
It also detects struct that derive or implement `ToSchema` for the `components(schemas)` section, and the `ToResponse`
for the `components(responses)` section.
# Features
- [x] Automatic recursive path detection
- [x] Automatic import from module
- [x] Automatic import from src folder
- [x] Automatic model detection
- [x] Automatic response detection
- [x] Works with workspaces
- [x] Exclude a method from automatic scanning
- [x] Custom path detection
# How to use it
Simply add the crate `utoipauto` to the project
```
cargo add utoipauto
```
Import macro
```rust
use utoipauto::utoipauto;
```
Then add the `#[utoipauto]` macro just before the #[derive(OpenApi)] and `#[openapi]` macros.
## Important !!
Put `#[utoipauto]` before `#[derive(OpenApi)] `and `#[openapi]` macros.
```rust
#[utoipauto(paths = "MODULE_SRC_FILE_PATH, MODULE_SRC_FILE_PATH, ...")]
```
The paths receives a String which must respect this structure :
`"MODULE_SRC_FILE_PATH, MODULE_SRC_FILE_PATH, ..."`
You can add several paths by separating them with a coma `","`.
## Usage with workspaces
If you are using a workspace, you must specify the name of the crate in the path.