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

allow setting the route name #1872

Closed
wants to merge 2 commits into from
Closed

Conversation

cataggar
Copy link

@cataggar cataggar commented Aug 30, 2021

The route name is currently derived from the handler function name. This allows setting the route name. Here, the route name is set to Hello.

#[get("/", name = "Hello")]
fn hello() -> &'static str {
    "hello"
}

In my use case, I use the Swagger operationId as the route name.

@SergioBenitez
Copy link
Member

Why not name the function Hello?

@cataggar cataggar mentioned this pull request Aug 31, 2021
@cataggar
Copy link
Author

cataggar commented Aug 31, 2021

That was a bad example. Here is a more complete example. I have some routes like:

pub fn routes() -> Vec<rocket::Route> {
    routes![
        operations::list,
        locations::check_trial_availability,
        locations::check_quota_availability,
        private_clouds::list,
        private_clouds::list_in_subscription,
        private_clouds::get,
        private_clouds::create_or_update,
        private_clouds::update,
        private_clouds::delete,
        clusters::list,
        clusters::get,
        clusters::create_or_update,
        clusters::update,
        clusters::delete,
        private_clouds::list_admin_credentials,
        hcx_enterprise_sites::list,
        hcx_enterprise_sites::get,
        hcx_enterprise_sites::create_or_update,
        hcx_enterprise_sites::delete,
        authorizations::list,
        authorizations::get,
        authorizations::create_or_update,
        authorizations::delete
    ]
}

I want the route name for function operations::list to be Operations_List instead of list.

@SergioBenitez
Copy link
Member

For what reason? What are you gaining, exactly?

@cataggar
Copy link
Author

cataggar commented Aug 31, 2021

operationId is what we use to name each route. I'm able to test all method + uri combinations route correctly to an operationId.

@cataggar cataggar mentioned this pull request Aug 31, 2021
@kolbma
Copy link
Contributor

kolbma commented Jan 23, 2022

Why you don't use handler and a custom mapping during the test?
Runtime code then doesn't have to handle stuff you need for a test.

@SergioBenitez
Copy link
Member

I think this needs more motivation. I recommend opening up a "suggestion" issue with a concrete motivating use-case or two.

@cataggar cataggar deleted the route_name branch September 30, 2023 10:35
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.

3 participants