Feature Request
Is your feature request related to an issue? Please describe.
When route_prefix_context is used to apply a prefix on various routes, the supplied route_prefix gets stripped to remove any leading/training slashes. Provided that Pyramid handles /prefix/route and prefix/route the same way, it should not strip the leading slash (it is fine to strip the training one to allow addition of more routes after).
This was highlighted a while back in #2143, but not addressed further.
When working with utilities like https://github.com/Cornices/cornice and https://github.com/Cornices/cornice.ext.swagger, it is possible to define a Service that uses the prefix_route to obtain the correct path for the OpenAPI rendering. Because route_prefix_context strips the path, it is not generating the intended path.
Describe the solution you'd like
Modify this line:
|
route_prefix = route_prefix.strip('/') |
- route_prefix = route_prefix.strip('/')
+ route_prefix = route_prefix.rstrip('/')
When using rstrip and with config.route_prefix_context("/ogcapi"), the routes below get rendered correctly.
They behave and respond exactly the same way as if the path were stripped from the leading /.

With the current strip, all leading / are lost, creating inconsistent paths:

Describe alternatives you've considered
Override the pyramind.config.Configurator.route_prefix_context method.
While this works, it is a dirty workaround as I have to duplicate the code to keep all the other self.begin(), etc. calls.
Additional context
This is where the supplied route_prefix is relevant in the package that uses it for eventual OpenAPI generation :
https://github.com/Cornices/cornice/blob/abfcfd9eeefaf281237ba84a3b90ef5ee0698aa9/src/cornice/pyramidhook.py#L169-L183
Feature Request
Is your feature request related to an issue? Please describe.
When
route_prefix_contextis used to apply a prefix on various routes, the suppliedroute_prefixgets stripped to remove any leading/training slashes. Provided that Pyramid handles/prefix/routeandprefix/routethe same way, it should not strip the leading slash (it is fine to strip the training one to allow addition of more routes after).This was highlighted a while back in #2143, but not addressed further.
When working with utilities like https://github.com/Cornices/cornice and https://github.com/Cornices/cornice.ext.swagger, it is possible to define a
Servicethat uses theprefix_routeto obtain the correct path for the OpenAPI rendering. Becauseroute_prefix_contextstrips the path, it is not generating the intended path.Describe the solution you'd like
Modify this line:
pyramid/src/pyramid/config/routes.py
Line 602 in 72f6185
When using
rstripandwith config.route_prefix_context("/ogcapi"), the routes below get rendered correctly.They behave and respond exactly the same way as if the path were stripped from the leading
/.With the current
strip, all leading/are lost, creating inconsistent paths:Describe alternatives you've considered
Override the
pyramind.config.Configurator.route_prefix_contextmethod.While this works, it is a dirty workaround as I have to duplicate the code to keep all the other
self.begin(), etc. calls.Additional context
This is where the supplied
route_prefixis relevant in the package that uses it for eventual OpenAPI generation :https://github.com/Cornices/cornice/blob/abfcfd9eeefaf281237ba84a3b90ef5ee0698aa9/src/cornice/pyramidhook.py#L169-L183