-
Notifications
You must be signed in to change notification settings - Fork 149
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
fix back-reference of dynamically created route for service by pyramihook #584
base: main
Are you sure you want to change the base?
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_prefix
and theadd_cornice_service
directive, 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.path
property. 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_prefix
is set to anything. Looking deeper into thecornice-swagger
code (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_route
instead of usingService.path
if it is defined, in case it could extract a predefined route (aka the name definition referenced byconfig.add_route
).Similarly, the pyramid
add_cornice_service
directive looks for thatService.pyramid_route
in 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_service
WITHOUT 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] = service
is set with the appropriate prefix, but the linked service in that dictionary still only has theService.path
reference without prefix.This PR applies the
route_name
that is expected to be created just a few lines after onto theservice.pyramid_route
property.This way,
cornice-swagger
is able to correctly resolve the prefixed path of the service.cornice/src/cornice/pyramidhook.py
Lines 224 to 226 in 677aa40