-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Auto generate route name #2928
Auto generate route name #2928
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2928 +/- ##
=============================================
+ Coverage 87.985% 88.144% +0.158%
=============================================
Files 94 94
Lines 7408 7423 +15
Branches 1307 1306 -1
=============================================
+ Hits 6518 6543 +25
+ Misses 599 595 -4
+ Partials 291 285 -6 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain a little the use case for this? I am trying to understand how it will be useful other than the two existing options:
- Use the handler function's name, or
- Explicit naming with
name
param.
I guess I can see possible a use case like:
class BaseMixin:
def generate_name(self) -> str:
return self._generate_name()
This would then expose it as an easily overridable function.
Sanic mixins have been updated to support more informative route naming. `_generate_name()` is now enhanced to include methods and URIs as part of the route name, providing more context about the route configuration. The update also takes care of potential naming conflicts in different scenarios.
The ability to automatically generate names for routes has been added to Sanic. This feature is controlled by the 'generate_name' parameter available in the application, blueprint, and route definitions. Additionally, comprehensive tests have been added to ensure the correct functionality of this new feature.
- add new test_case
58ed970
to
9a0b6a2
Compare
Thanks for the work on this. I decided to rework the pattern in #2961. |
The ability to automatically generate names for routes has been added to Sanic. This feature is controlled by the 'generate_name' parameter available in the application, blueprint, and route definitions. Additionally, comprehensive tests have been added to ensure the correct functionality of this new feature.
a parameter added to the Sanic and Blueprint constructor
app = Sanic(name='hello', unique_route_name_generate=True)
in recent versions of Sanic, it's some kind of essential to assign names fo routes (it makes migrating to a new version of Sanic, very time-consuming). For example this little example:
by using this new argument, its becomes mandatory to assign names and be more backward compatible also naming can be ignored in most cases.