Bug 33556: Avoid relying on $c->validation
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 29 May 2023 15:10:51 +0000 (12:10 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 21 Jul 2023 20:14:37 +0000 (17:14 -0300)
commit95af4c9de18ebbb686ec2b1291dbf0fa980c9450
tree95090270e7f9741252abdc9fadea716938156e85
parentdcbd3e69295a778788f0d3d840b3edc30a8657e1
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@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
39 files changed:
Koha/REST/V1/Acquisitions/Orders.pm
Koha/REST/V1/Acquisitions/Vendors.pm
Koha/REST/V1/AdvancedEditorMacro.pm
Koha/REST/V1/ArticleRequests.pm
Koha/REST/V1/Auth/Identity/Provider/Domains.pm
Koha/REST/V1/Auth/Identity/Providers.pm
Koha/REST/V1/Auth/Password.pm
Koha/REST/V1/AuthorisedValues.pm
Koha/REST/V1/Authorities.pm
Koha/REST/V1/BackgroundJobs.pm
Koha/REST/V1/Biblios.pm
Koha/REST/V1/Biblios/ItemGroups.pm
Koha/REST/V1/Biblios/ItemGroups/Items.pm
Koha/REST/V1/CashRegisters/Cashups.pm
Koha/REST/V1/Checkouts.pm
Koha/REST/V1/Cities.pm
Koha/REST/V1/Clubs/Holds.pm
Koha/REST/V1/Config/SMTP/Servers.pm
Koha/REST/V1/Holds.pm
Koha/REST/V1/Illbackends.pm
Koha/REST/V1/ImportBatchProfiles.pm
Koha/REST/V1/ImportRecordMatches.pm
Koha/REST/V1/Items.pm
Koha/REST/V1/Libraries.pm
Koha/REST/V1/OAuth.pm
Koha/REST/V1/Patrons.pm
Koha/REST/V1/Patrons/Account.pm
Koha/REST/V1/Patrons/Attributes.pm
Koha/REST/V1/Patrons/Holds.pm
Koha/REST/V1/Patrons/Password.pm
Koha/REST/V1/Patrons/Password/Expiration.pm
Koha/REST/V1/Quotes.pm
Koha/REST/V1/ReturnClaims.pm
Koha/REST/V1/SearchFilter.pm
Koha/REST/V1/Stage.pm
Koha/REST/V1/Suggestions.pm
Koha/REST/V1/Tickets.pm
Koha/REST/V1/TransferLimits.pm
Koha/REST/V1/TwoFactorAuth.pm