utoipa icon indicating copy to clipboard operation
utoipa copied to clipboard

[feature] qol with merge

Open mortifia opened this issue 1 year ago • 1 comments

update this Implementations pub fn merge(&mut self, other: OpenApi)

to pub fn merge(&mut self, other: OpenApi) -> OpenApi

or pub fn merge(&mut self, other: OpenApi) -> Self

why ?

to avoid creating a mutable var

    // with axum
   
    let mut api_doc = ApiDoc::openapi();
    api_doc.merge(advertisements::ApiDoc::openapi());
    
    let app = Router::new()
        .route("/", get(hello_world))
        .nest("/advertisement", advertisements_routes())
        .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", api_doc));
        
    //to
    
    let app = Router::new()
        .route("/", get(hello_world))
        .nest("/advertisement", advertisements_routes())
        .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json",
            ApiDoc::openapi()
                .merge(advertisements::ApiDoc::openapi())
            );

mortifia avatar Oct 10 '23 08:10 mortifia

Perhaps we could add another API that supports this behavior. E.g. merge_from.

juhaku avatar Oct 31 '23 15:10 juhaku