[Koha-bugs] [Bug 33556] $c->validation should be avoided (part 1)

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Fri Jul 21 15:09:57 CEST 2023


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33556

--- Comment #23 from Jonathan Druart <jonathan.druart+koha at gmail.com> ---
Created attachment 153785
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=153785&action=edit
Bug 33556: Avoid relying on $c->validation

Talking to the OpenAPI plugin maintainer, he mentioned the use of
$c->validation->output should be avoided as the plugin is not designed to have
a stable behavior there, and he even thought of just removing the method.

That method returns an internal data structure the plugin uses to validate
things, and then updates the request itself.

Take the following example:

GET /patrons/123
x-koha-embed: checkouts,library

without the OpenAPI plugin, requesting the header like this:

$c->req->headers->header('x-koha-embed')

would return a scalar, the string 'checkouts,library'.

When using the plugin, and with `x-koha-embed` being defined as
collectionFormat: csv, that header is entirely replaced by an arrayref.

That's how the plugin works and how it is expected to be used. So we need to
replace the uses of $c->validation format, with normal Mojo usage to avoid
future headaches.

This patch changes:
* $c->validation->param => $c->param
* $c->validation->param('body') => $c->req->json

To test:
1. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/*.t
=> SUCCESS: Tests pass!
2. Apply this patches
3. Repeat 1
=> SUCCESS: Tests still pass!
4. Sign off :-D

Signed-off-by: Martin Renvoize <martin.renvoize at ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart at bugs.koha-community.org>

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list