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

Path impl_for override. PathBuilder::path_from #759

Merged
merged 5 commits into from
Dec 14, 2023

Conversation

wyatt-herkamp
Copy link
Contributor

@wyatt-herkamp wyatt-herkamp commented Sep 13, 2023

I personally do like the derive OpenAPI macro

So I tend to implement OpenAPI by hand.

However it generates a pretty ugly to look at type __path_{function_name} I use Actix so Actix already generates a type for my route. So I just want the path macro to implement for that type.

Example

#[utoipa::path(get,  
    impl_for = me,  
    path = "/api/me",  
    responses(  
        (status = 200, description = "You are Logged In", body = User),  
        (status = 401, description = "You are not logged in")  
    ),  
    security(  
        ("api_key" = [])  
    )  
)]  
#[get("")]  
pub async fn me(auth: Authentication) -> JsonResponse<User> {  
    JsonResponse::from(Into::<User>::into(auth))  
}  

Then I added a new function to PathBuilder path_from. Just for a cleaner way of appending a path.

@juhaku
Copy link
Owner

juhaku commented Dec 14, 2023

However it generates a pretty ugly to look at type __path_{function_name}

It generates ugly to look so that it does not name clash even possibly with any other type that might be generated. However as it is a generated type it does not really matter what it looks like though. But I can see why somebody would save a few bytes without generating an "extra" type. Yet this actually could open a door for path support in traits as well.

@juhaku juhaku merged commit 1b9c39b into juhaku:master Dec 14, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants