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

fix: remove trailing / from nested paths #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

0xf09f95b4
Copy link

Hi!

This PR attempts to fix #134.

Currently, API documentation for nested routes is built by combining the path of the base route (with trailing slashes removed) with the path of the nested route.

If a path of a nested route is only "/", as seen in the todo list example, this leads to that path now containing a trailing slash:

ApiRouter::new().nest_api_service("/todo", ApiRouter::new().api_route("/",post_with(handler, docs)))

Generates this path:

"paths": {
    "/todo/": {
        ...
    },
    ...
}

This PR fixes this issue by removing any trailing slahes after the nested path is built in the nest and nest_api_service functions.

One edge case needs to be handled. In a construct like the following:

ApiRouter::new().nest_api_service("/", ApiRouter::new().api_route("/",post_with(handler, docs)))

the path of this route would be empty. A route of just / is therefore returned unmodified.

I've also added a basic unit test.

This seems to be a simple fix, I hope I didn't miss any other cases here.

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.

Broken URLs with trailing / due to .nest()
1 participant