carllerche / tower-web

A fast, boilerplate free, web framework for Rust
MIT License
981 stars 51 forks source link

Disallow repeating the same route for multiple endpoints in a resource #135

Closed phrohdoh closed 5 years ago

phrohdoh commented 6 years ago

On one of my resources, ApiService, I have the following impl:

        #[get("/api/company/:id")]
        #[content_type("application/json")]
        fn get_single_company(&self, id: u32) -> Result<SingleCompanyResponse, ()> {
            Ok(SingleCompanyResponse {
                item: Company { id, display_name: "Target".into(), aliases: vec![] }
            })
        }

        #[get("/api/company/:id")]
        #[content_type("application/json")]
        fn get_single_country(&self, id: u32) -> Result<SingleCountryResponse, ()> {
            Ok(SingleCountryResponse {
                item: Country { id, display_name: "Canada".into(), tags: vec![] }
            })
        }

The routes being duplicate is a copy & paste issue but I received no warning or error. This can lead to confusion and lost time.

It would be useful to error (or at least warn) in this scenario if at all possible.