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

Bugfix/basepath #1716

Merged
merged 7 commits into from
Jul 1, 2023
Merged

Bugfix/basepath #1716

merged 7 commits into from
Jul 1, 2023

Conversation

Ruwann
Copy link
Member

@Ruwann Ruwann commented Jun 16, 2023

Working towards #1709

I think we're almost there, some tests I did are now working properly.

Would love to get some feedback/ideas on the implementation and the tests :)

@Ruwann Ruwann requested a review from RobbeSneyders June 16, 2023 09:16
@coveralls
Copy link

coveralls commented Jun 16, 2023

Coverage Status

coverage: 94.07% (+0.03%) from 94.045% when pulling 2b5f642 on Ruwann:bugfix/basepath into 5e9447c on spec-first:main.

@Ruwann Ruwann force-pushed the bugfix/basepath branch from 7d51913 to 51982a5 Compare June 16, 2023 10:12
Copy link
Member

@RobbeSneyders RobbeSneyders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Ruwann!

This approach looks good to me. Unless I'm missing something, I don't think we're sorting paths without path parameters correctly though?

Eg. if you look at the example in the issue, we should also sort "/swagger" before "/". I think this is only necessary for the APIs, not for individual routes, but I don't think it has any downside there.

connexion/middleware/main.py Show resolved Hide resolved
Comment on lines 452 to 460
class SortableRoute:
def __init__(self, path: str) -> None:
self.path = path
self.path_regex, _, _ = compile_path(path)

def __lt__(self, other: "SortableRoute") -> bool:
return bool(other.path_regex.match(self.path))

return sorted(routes, key=lambda r: SortableRoute(key(r) if key else r))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart 🤯

@Ruwann
Copy link
Member Author

Ruwann commented Jun 20, 2023

Thanks, good catch. Indeed, this was not yet working properly because the tests added the /{path:path} part that's actually needed. Fixed this now :)
Agreed, don't think it has downsides for routes as / and /basepath are technically not comparable, neither is more specific than the other, but this changes for basepaths.

@Ruwann Ruwann marked this pull request as ready for review June 20, 2023 11:42
@Ruwann Ruwann force-pushed the bugfix/basepath branch from 17a15ac to 2b5f642 Compare June 26, 2023 07:13
Copy link
Member

@RobbeSneyders RobbeSneyders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Ruwann!

@RobbeSneyders RobbeSneyders merged commit 3fa9f3b into spec-first:main Jul 1, 2023
@Ruwann Ruwann deleted the bugfix/basepath branch August 29, 2023 13:51
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.

API with base path not reachable when registered after API without base path.
3 participants