Bug 21116: Add API routes through plugins
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 23 Jul 2018 14:14:47 +0000 (11:14 -0300)
committerFridolin Somers <fridolin.somers@biblibre.com>
Thu, 29 Nov 2018 12:26:14 +0000 (13:26 +0100)
commit16e0a19daf8874fccb4ba01548041b9d4ac9729a
tree76f331a1ed3f0d8f87d99e6e11bba1d6883bc182
parent8a5f84725faf27f092dc12731f8d11783fd4f717
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>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 3fedae85f25ef5f587d567b51b86aab776d87311)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit ab79f3fc67a06ea7383270ae7f00f97605c3a4d0)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Koha/Exceptions/Plugin.pm [new file with mode: 0644]
Koha/REST/Plugin/PluginRoutes.pm [new file with mode: 0644]
Koha/REST/V1.pm