Currently the API spec is validated multiple times, and the whole spec loaded so far is re-validated for each (if any) REST API plugin. Coming up with a patch to avoid multiple validation unless the complete spec doesn't validate.
Created attachment 99314 [details] [review] Bug 24700: Avoid validating REST API spec multiple times This patch changes the spec loading so that it is fully loaded and merged with any plugin routes before validation. The individual parts are separately validated only if the resulting complete spec is invalid. Note: the OpenAPI plugin validates the spec given to it, so normally no manual validation is necessary. Test plan: 1. prove -v t/db_dependent/Koha/REST/* 2. prove -v t/db_dependent/api/v1/* Sponsored-by: The National Library of Finland
Created attachment 99319 [details] [review] Bug 24700: Avoid validating REST API spec multiple times This patch changes the spec loading so that it is fully loaded and merged with any plugin routes before validation. The individual parts are separately validated only if the resulting complete spec is invalid. Note: the OpenAPI plugin validates the spec given to it, so normally no manual validation is necessary. Test plan: 1. prove -v t/db_dependent/Koha/REST/* 2. prove -v t/db_dependent/api/v1/* Sponsored-by: The National Library of Finland Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 99320 [details] [review] Bug 24700: Avoid validating REST API spec multiple times This patch changes the spec loading so that it is fully loaded and merged with any plugin routes before validation. The individual parts are separately validated only if the resulting complete spec is invalid. Note: the OpenAPI plugin validates the spec given to it, so normally no manual validation is necessary. Test plan: 1. prove -v t/db_dependent/Koha/REST/* 2. prove -v t/db_dependent/api/v1/* Sponsored-by: The National Library of Finland Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This is a nice improvement and the code is fairly clear. I'm struggling a little to find where this is tested to date though.. so I haven't run tests against it yet to fully prove there are no regressions.. human testing gave me no issues though so I'm signing off.
t/db_dependent/Koha/REST/Plugin/PluginRoutes.t contains the tests for PluginRoutes, but I don't think there's anything for V1.pm's startup. I can try to create something, but it's pretty huge if all that the startup method does is to be tested.
I'll just verify for myself that the pluginroutes tests cover us.. thanks for the pointer.
Don't understand the code well enough to QA here - still gave it a go to provoke some movement. Might be my data, but I have failing tests with and without the patch: Test Summary Report ------------------- t/db_dependent/Koha/REST/Plugin/PluginRoutes.t (Wstat: 65280 Tests: 2 Failed: 1) Failed test: 2 Non-zero exit status: 255 # Failed test 'No tests run for subtest "Disabled plugins tests"' # at t/db_dependent/Koha/REST/Plugin/PluginRoutes.t line 121. Can't locate Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm in @INC (you may need to install the Koha::Plugin::Com::ByWaterSolutions::KitchenSink module) (@INC contains: /home/vagrant/kohaclone /home/vagrant/qa-test-tools /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base t/db_dependent/Koha/REST/Plugin/../../../../lib) at /usr/share/perl/5.24/Module/Load.pm line 77. Can't locate Koha/Plugin/Com/ByWaterSolutions/KitchenSink in @INC (@INC contains: /home/vagrant/kohaclone /home/vagrant/qa-test-tools /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base t/db_dependent/Koha/REST/Plugin/../../../../lib) at /usr/share/perl/5.24/Module/Load.pm line 77. # Looks like your test exited with 255 just after 2. Dubious, test returned 255 (wstat 65280, 0xff00) Failed 1/2 subtests t/db_dependent/api/v1/acquisitions_orders.t (Wstat: 256 Tests: 5 Failed: 1) Failed test: 1 Non-zero exit status: 1 [Sun Mar 22 13:31:12 2020] [debug] GET "/api/v1/acquisitions/orders" [Sun Mar 22 13:31:12 2020] [debug] Routing to controller "Koha::REST::V1::Auth" and action "under" [Sun Mar 22 13:31:12 2020] [debug] 400 Bad Request (0.027112s, 36.884/s) ok 6 - GET //W0txdhLojIJjsOm41yB0E6aNafhS1vdorHkDUn9Z17KvscSt:thePassword123@/api/v1/acquisitions/orders?order_blah=blah ok 7 - 400 Bad Request ok 8 - exact match for JSON Pointer "" # Looks like you failed 2 tests of 8. not ok 1 - list() tests
Created attachment 101906 [details] [review] Bug 24700: Avoid validating REST API spec multiple times This patch changes the spec loading so that it is fully loaded and merged with any plugin routes before validation. The individual parts are separately validated only if the resulting complete spec is invalid. Note: the OpenAPI plugin validates the spec given to it, so normally no manual validation is necessary. Test plan: 1. prove -v t/db_dependent/Koha/REST/* 2. prove -v t/db_dependent/api/v1/* Sponsored-by: The National Library of Finland Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Nice work everyone! Pushed to master for 20.05
enhancement not backported to 19.11.x