fix back-reference of dynamically created route for service by pyramihook #584
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using
config.route_prefixand theadd_cornice_servicedirective, I am able to register services that are used as decorators on pyramid view functions, with the appropriate prefix applied. So far, everything is ok.However, I am also using at the same time the https://github.com/Cornices/cornice.ext.swagger package, with the help of multiple extended definitions/converters in https://github.com/crim-ca/weaver/blob/master/weaver/wps_restapi/colander_extras.py + Cornices/cornice.ext.swagger@main...fmigneault:cornice.ext.swagger:openapi-3, to auto-generate the OpenAPI 3.x definition represented by all the service paths, bodies, responses, etc. (relates to Cornices/cornice.ext.swagger#133).
When running the Swagger/OpenAPI generator, the service paths are resolved using the
Service.pathproperty. Since the services are configured with the non-prefixed path, and that prefixes are applied on the fly byadd_cornice_service, I end up with incorrect paths wheneverconfig.route_prefixis set to anything. Looking deeper into thecornice-swaggercode (i.e.: https://github.com/Cornices/cornice.ext.swagger/blob/609f923784d935ba5f497e9ebb87b8e5a21747a6/src/cornice_swagger/swagger.py#L571-L593), I find that the route-builder looks forService.pyramid_routeinstead of usingService.pathif it is defined, in case it could extract a predefined route (aka the name definition referenced byconfig.add_route).Similarly, the pyramid
add_cornice_servicedirective looks for thatService.pyramid_routein case it already exists to use it:cornice/src/cornice/pyramidhook.py
Lines 169 to 183 in 677aa40
Now, the issue is that, when using
add_cornice_serviceWITHOUT a predefined route, it creates one dynamically, but does not back-propagate this route reference onto the service. In order words,services[prefix + service.path] = serviceis set with the appropriate prefix, but the linked service in that dictionary still only has theService.pathreference without prefix.This PR applies the
route_namethat is expected to be created just a few lines after onto theservice.pyramid_routeproperty.This way,
cornice-swaggeris able to correctly resolve the prefixed path of the service.cornice/src/cornice/pyramidhook.py
Lines 224 to 226 in 677aa40