Summary: | Add API routes through plugins | ||
---|---|---|---|
Product: | Koha | Reporter: | Tomás Cohen Arazi (tcohen) <tomascohen> |
Component: | REST API | Assignee: | Tomás Cohen Arazi (tcohen) <tomascohen> |
Status: | CLOSED FIXED | QA Contact: | Alex Arnaud <alex.arnaud> |
Severity: | new feature | ||
Priority: | P5 - low | CC: | alex.arnaud, benjamin.rokseth, dcook, ere.maijala, fridolin.somers, kyle, lari.taskula, martin.renvoize, nick |
Version: | Main | ||
Hardware: | All | ||
OS: | All | ||
See Also: | https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=21334 | ||
Change sponsored?: | --- | Patch complexity: | --- |
Documentation contact: | Documentation submission: | ||
Text to go in the release notes: |
Allows the extension of the Koha API via plugins. This can allow for custom vendor integrations and prototyping of new routes.
|
Version(s) released in: | |
Circulation function: | |||
Attachments: |
Bug 21116: Add API routes through plugins
Bug 21116: Add API routes through plugins Bug 21116: Unit tests Bug 21116: Add API routes through plugins Bug 21116: Unit tests Bug 21116: Add API routes through plugins Bug 21116: Unit tests Bug 21116: Add API routes through plugins |
Description
Tomás Cohen Arazi (tcohen)
2018-07-25 13:56:08 UTC
Created attachment 77274 [details] [review] Bug 21116: Add API routes through plugins This patch adds plugins the capability of injecting new routes on the API. The plugins should provide the following methods to be considered valid API-generating plugins: - 'api_routes': returning the 'path' component of the OpenAPI specification corresponding to the routes served by the plugin - 'api_namespace': it should return a namespace to be used for grouping the endpoints provided by the plugin otherwise, they will be just skipped. All plugin-generated routes will be added the 'contrib' namespace, and will end up placed inside /contrib/<namespace>, where <namespace> is what the 'api_namespace' returns. A sample endpoint will be added to the Kitchen Sink plugin, and tests are being written. To test, wait a bit more for those samples :-D The KitchenSink plugin [1] already implements a sample contrib endpoint using this :-D YAY! [1] https://github.com/bywatersolutions/koha-plugin-kitchen-sink/commit/e7da3c40842b25d3ef88bf7600c7c1113365b8d2 Download link for the kpz file: https://github.com/bywatersolutions/koha-plugin-kitchen-sink/releases/download/v2.1.18/koha-plugin-kitchen-sink-v2.1.18.kpz Created attachment 77601 [details] [review] Bug 21116: Add API routes through plugins This patch adds plugins the capability of injecting new routes on the API. The plugins should provide the following methods to be considered valid API-generating plugins: - 'api_routes': returning the 'path' component of the OpenAPI specification corresponding to the routes served by the plugin - 'api_namespace': it should return a namespace to be used for grouping the endpoints provided by the plugin otherwise, they will be just skipped. All plugin-generated routes will be added the 'contrib' namespace, and will end up placed inside /contrib/<namespace>, where <namespace> is what the 'api_namespace' returns. A sample endpoint will be added to the Kitchen Sink plugin, and tests are being written. To test, wait a bit more for those samples :-D Signed-off-by: Benjamin Rokseth <benjamin.rokseth@deichman.no> Tested according to plan: patched, added kitchen sink plugin, verified swagger schema and new 'contrib' endpoint : PUT /api/v1/contrib/kitchensink/patrons/{patron_id}/bother gave expected result: {"bothered":true} A very interesting and non-obtrusive approach to a common problem (feature creep)! Created attachment 78194 [details] [review] Bug 21116: Unit tests This path implements unit tests for the route-from-plugin development. It adds the required methods to the Koha::Plugin::Test plugin distributed along with the tests. A second plugin implementing invalid OpenAPI specs is added (Koha::Plugin::BadAPIRoute). Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Created attachment 78195 [details] [review] Bug 21116: Add API routes through plugins This patch adds plugins the capability of injecting new routes on the API. The plugins should provide the following methods to be considered valid API-generating plugins: - 'api_routes': returning the 'path' component of the OpenAPI specification corresponding to the routes served by the plugin - 'api_namespace': it should return a namespace to be used for grouping the endpoints provided by the plugin otherwise, they will be just skipped. All plugin-generated routes will be added the 'contrib' namespace, and will end up placed inside /contrib/<namespace>, where <namespace> is what the 'api_namespace' returns. A sample endpoint will be added to the Kitchen Sink plugin, and tests are being written. To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/PluginRoutes.t => SUCCESS: Tests pass! - Install the (latest) KitchenSink plugin - Point your browser to the API like this: http://koha-intra.myDNSname.org:8081/api/v1/.html => SUCCESS: The /contrib/kitchensink/patrons/:patron_id/bother endpoint implemented by the plugin has been merged! - Sign off! :-D Signed-off-by: Benjamin Rokseth <benjamin.rokseth@deichman.no> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Created attachment 78322 [details] [review] Bug 21116: Unit tests This path implements unit tests for the route-from-plugin development. It adds the required methods to the Koha::Plugin::Test plugin distributed along with the tests. A second plugin implementing invalid OpenAPI specs is added (Koha::Plugin::BadAPIRoute). Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com> Created attachment 78323 [details] [review] Bug 21116: Add API routes through plugins This patch adds plugins the capability of injecting new routes on the API. The plugins should provide the following methods to be considered valid API-generating plugins: - 'api_routes': returning the 'path' component of the OpenAPI specification corresponding to the routes served by the plugin - 'api_namespace': it should return a namespace to be used for grouping the endpoints provided by the plugin otherwise, they will be just skipped. All plugin-generated routes will be added the 'contrib' namespace, and will end up placed inside /contrib/<namespace>, where <namespace> is what the 'api_namespace' returns. A sample endpoint will be added to the Kitchen Sink plugin, and tests are being written. To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/PluginRoutes.t => SUCCESS: Tests pass! - Install the (latest) KitchenSink plugin - Point your browser to the API like this: http://koha-intra.myDNSname.org:8081/api/v1/.html => SUCCESS: The /contrib/kitchensink/patrons/:patron_id/bother endpoint implemented by the plugin has been merged! - Sign off! :-D Signed-off-by: Benjamin Rokseth <benjamin.rokseth@deichman.no> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com> Created attachment 78542 [details] [review] Bug 21116: Unit tests This path implements unit tests for the route-from-plugin development. It adds the required methods to the Koha::Plugin::Test plugin distributed along with the tests. A second plugin implementing invalid OpenAPI specs is added (Koha::Plugin::BadAPIRoute). Edit: I made terminology changes to make it less rude. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com> Created attachment 78543 [details] [review] Bug 21116: Add API routes through plugins This patch adds plugins the capability of injecting new routes on the API. The plugins should provide the following methods to be considered valid API-generating plugins: - 'api_routes': returning the 'path' component of the OpenAPI specification corresponding to the routes served by the plugin - 'api_namespace': it should return a namespace to be used for grouping the endpoints provided by the plugin otherwise, they will be just skipped. All plugin-generated routes will be added the 'contrib' namespace, and will end up placed inside /contrib/<namespace>, where <namespace> is what the 'api_namespace' returns. A sample endpoint will be added to the Kitchen Sink plugin, and tests are being written. To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/REST/Plugin/PluginRoutes.t => SUCCESS: Tests pass! - Install the (latest) KitchenSink plugin - Point your browser to the API like this: http://koha-intra.myDNSname.org:8081/api/v1/.html => SUCCESS: The /contrib/kitchensink/patrons/:patron_id/bother endpoint implemented by the plugin has been merged! - Sign off! :-D Signed-off-by: Benjamin Rokseth <benjamin.rokseth@deichman.no> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com> Awesome work all! Pushed to master for 18.11 Pushed to 18.05.x for 18.05.04. After deliberating on this one for a while, I've decided to backport it for similar reasons to bug 20942. It is not immediately user facing and as such will not be a surprise to end users. It does, however, encourage plugin developers to develop and test against a stable koha earlier and open up the option for a wider supported koha version range in plugins. New feature not pushed to 17.11.x to encourage upgrade ;) (In reply to Fridolin SOMERS from comment #14) > New feature not pushed to 17.11.x to encourage upgrade ;) I changed my mind, plugins are great, it does no harm to have this in 17.11.x I haded a followup to remove use of Koha::Exceptions::Exception that needs Bug 20590. Pushed to 17.11.x for 17.11.13 |