From 9ebc1db5b21ac697bc65c06298a27b6948cba378 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 25 Feb 2022 12:57:49 -0300 Subject: [PATCH] Bug 30194: Adapt V1.pm to the latest JSON::Validator This patch acknowledges a refactoring that took place within JSON::Validator, the OpenAPIv2 schema validator and the Mojolicious::Plugin::OpenAPI plugin. To test: 0. Edit /etc/apt/sources.list.d/koha.list - Duplicate the only present line, replacing 'dev' for 'exp' Run: $ apt update ; apt dist-upgrade 1. Apply this patch 2. Restart all: $ restart_all ; tail -f /var/log/koha/kohadev/*.log => FAIL: It fails 3. Grab a bundled version of the API spec from a working Koha 4. (temporarily) tweak V1.pm to point to this file (swagger.json) 5. Repeat 2 => SUCCESS: Koha works with latests Mojolicious and JSON::Validator Work is being done on bug 30193 to come up with a reorganized spec that conforms better to the standard and thus doesn't require step 4. --- Koha/REST/V1.pm | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/Koha/REST/V1.pm b/Koha/REST/V1.pm index 1c22a769d7..2dd9d3aaa0 100644 --- a/Koha/REST/V1.pm +++ b/Koha/REST/V1.pm @@ -22,7 +22,7 @@ use Mojo::Base 'Mojolicious'; use C4::Context; use Koha::Logger; -use JSON::Validator::OpenAPI::Mojolicious; +use JSON::Validator::Schema; use Try::Tiny qw( catch try ); =head1 NAME @@ -68,7 +68,7 @@ sub startup { $self->secrets([$secret_passphrase]); } - my $validator = JSON::Validator::OpenAPI::Mojolicious->new; + my $validator = JSON::Validator::Schema->new( $self->home->rel_file("api/v1/swagger/swagger.yaml") ); push @{$self->routes->namespaces}, 'Koha::Plugin'; @@ -76,12 +76,7 @@ sub startup { my $spec; my $swagger_schema = $self->home->rel_file("api/swagger-v2-schema.json"); try { - $spec = $validator->bundle( - { - replace => 1, - schema => $self->home->rel_file("api/v1/swagger/swagger.yaml") - } - ); + my $spec = $validator->bundle->data; $self->plugin( 'Koha::REST::Plugin::PluginRoutes' => { @@ -95,10 +90,6 @@ sub startup { spec => $spec, route => $self->routes->under('/api/v1')->to('Auth#under'), schema => ( $swagger_schema ) ? $swagger_schema : undef, - allow_invalid_ref => - 1, # required by our spec because $ref directly under - # Paths-, Parameters-, Definitions- & Info-object - # is not allowed by the OpenAPI specification. } ); } @@ -111,10 +102,9 @@ sub startup { $logger->error("Warning: Could not load REST API spec bundle: " . $_); try { - $validator->load_and_validate_schema( + $validator->schema( $self->home->rel_file("api/v1/swagger/swagger.yaml"), { - allow_invalid_ref => 1, schema => ( $swagger_schema ) ? $swagger_schema : undef, } ); @@ -131,10 +121,6 @@ sub startup { OpenAPI => { spec => $spec, route => $self->routes->under('/api/v1')->to('Auth#under'), - allow_invalid_ref => - 1, # required by our spec because $ref directly under - # Paths-, Parameters-, Definitions- & Info-object - # is not allowed by the OpenAPI specification. } ); } -- 2.35.1