Skip to content

Conversation

@juhaku
Copy link
Owner

@juhaku juhaku commented Oct 2, 2024

Add support for auto collecting schemas from handlers annotated with #[utoipa::path(...)] macro used with utoipa-axum routes! macro.

Update examples and docs.

From now on the there is no need to merge schemas from separate OpenApi since the schemas will get collected from the handlers.

 #[derive(utoipa::ToSchema)]
 struct User {
     id: i32,
 }

 #[utoipa::path(get, path = "/user", responses((status = OK, body = User)))]
 async fn get_user() -> Json<User> {
     Json(User { id: 1 })
 }

 let (router, api) = OpenApiRouter::new()
     .routes(routes!(get_user))
     .split_for_parts();

Closes #1065

Add support for auto collecting schemas from handlers annotated with
`#[utoipa::path(...)]` macro used with `utoipa-axum` `routes!` macro.

Update examples and docs.

From now on the there is no need to merge schemas from separate
OpenApi since the schemas will get collected from the handlers.
```rust
 #[derive(utoipa::ToSchema)]
 struct User {
     id: i32,
 }

 #[utoipa::path(get, path = "/user", responses((status = OK, body = User)))]
 async fn get_user() -> Json<User> {
     Json(User { id: 1 })
 }

 let (router, api) = OpenApiRouter::new()
     .routes(routes!(get_user))
     .split_for_parts();
```
@juhaku juhaku merged commit 8a5bb72 into master Oct 2, 2024
@juhaku juhaku deleted the feature-axum-auto-collect-schemas branch October 2, 2024 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Released

Development

Successfully merging this pull request may close these issues.

Auto collect schemas recursively from usages

2 participants