Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ServiceConfig to avoid redundancy. #657

Closed
afidegnum opened this issue Jun 25, 2023 · 2 comments · Fixed by #1158
Closed

Add ServiceConfig to avoid redundancy. #657

afidegnum opened this issue Jun 25, 2023 · 2 comments · Fixed by #1158
Labels
enhancement New feature or request

Comments

@afidegnum
Copy link

Can you please guide on adding ServiceConfig instead of manually list the routes to avoid erroneous repetitions?

the Configuration is already established at
looking at
we only need to pass that ServiceConfig to paths instead of manually list the routes which could be tedious. Could there be a macro or anything you can suggest?

@juhaku
Copy link
Owner

juhaku commented Jul 3, 2023

At the moment there is no build in solution for this. But others might have build some sort of macro rules to mitigate the overhead of double definition. Also there is a thrid-party crate that might be useful: #635 and there is one issue that has collected several relative issues together that touches the same topic #662.

@juhaku
Copy link
Owner

juhaku commented Oct 22, 2024

Duplicate #121

juhaku added a commit that referenced this issue Oct 22, 2024
Implements wrappers for `ServiceConfig`, `App`, `Scope` of actix-web.
This allows users to create `App` with collecting `paths` and `schemas`
recursively without registering them to `#[openapi(...)]` attribute.

Example of new supported syntax.
```rust
 use actix_web::{get, App};
 use utoipa_actix_web::{scope, AppExt};

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

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

 let (_, mut api) = App::new()
     .into_utoipa_app()
     .service(scope::scope("/api/v1").service(get_user))
     .split_for_parts();
```

Relates #283 Relates #662
Closes #121 Closes #657
@juhaku juhaku added the enhancement New feature or request label Oct 22, 2024
juhaku added a commit that referenced this issue Oct 22, 2024
Implements wrappers for `ServiceConfig`, `App`, `Scope` of actix-web.
This allows users to create `App` with collecting `paths` and `schemas`
recursively without registering them to `#[openapi(...)]` attribute.

Example of new supported syntax.
```rust
 use actix_web::{get, App};
 use utoipa_actix_web::{scope, AppExt};

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

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

 let (_, mut api) = App::new()
     .into_utoipa_app()
     .service(scope::scope("/api/v1").service(get_user))
     .split_for_parts();
```

Relates #283 Relates #662
Closes #121 Closes #657
@juhaku juhaku closed this as completed in 2bfbee7 Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Released
Development

Successfully merging a pull request may close this issue.

2 participants