fix back-reference of dynamically created route for service by pyramihook#584
fix back-reference of dynamically created route for service by pyramihook#584fmigneault wants to merge 1 commit intoCornices:mainfrom
Conversation
… for OpenAPI generation by cornice-swagger (fixed by Cornices/cornice#584)
|
@leplatrem FYI |
|
Thanks @fmigneault for this detailed explanation, it looks like you went deep into the implementation. I haven't touched this code base for a long time, and I'm wondering whether this change could have side-effects. I believe that Cornice users appreciate the very low level of activity and thus high stability. And I wouldn't want to disturb that :) If you are sure about the approach, would you mind adding a unit test to reproduce the issue you describe? Thank you, hope that you understand my "conservatism" :) |
|
Unfortunately, the Since the condition |
|
Well, I think I have found one uncommon side-effect with the proposed change after all. When running a test suite with I have tried calling Do you have any idea how this kind of problem could be resolved? |
…solve multi-config issue in tests (relates to Cornices/cornice#584)
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