From e1957dab30da5d9f63ac272fe98b96307d360c5d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 23 Oct 2017 15:34:01 -0300 Subject: [PATCH] Bug 7317: (followup) Migrate endpoint to OpenAPI This patch moves the current endpoint implementation from Swagger2 to the OpenAPI plugin. Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/Illrequests.pm | 10 +++++----- api/v1/swagger/paths/illrequests.json | 36 ++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Koha/REST/V1/Illrequests.pm b/Koha/REST/V1/Illrequests.pm index 0807eb1..ba47556 100644 --- a/Koha/REST/V1/Illrequests.pm +++ b/Koha/REST/V1/Illrequests.pm @@ -20,13 +20,13 @@ use Modern::Perl; use Mojo::Base 'Mojolicious::Controller'; use Koha::Illrequests; -use Koha::Library; +use Koha::Libraries; sub list { - my ($c, $args, $cb) = @_; + my $c = shift->openapi->valid_input or return; + my $args = $c->req->params->to_hash // {}; my $filter; - $args //= {}; my $output = []; # Create a hash where all keys are embedded values @@ -45,7 +45,7 @@ sub list { my $requests = Koha::Illrequests->search($filter); while (my $request = $requests->next) { - my $unblessed = $request->unblessed; + my $unblessed = $request->TO_JSON; # Add the request's id_prefix $unblessed->{id_prefix} = $request->id_prefix; # Augment the request response with patron details @@ -78,7 +78,7 @@ sub list { push @{$output}, $unblessed } - return $c->$cb( $output, 200 ); + return $c->render( status => 200, openapi => $output ); } diff --git a/api/v1/swagger/paths/illrequests.json b/api/v1/swagger/paths/illrequests.json index ddafd80..84eb5f1 100644 --- a/api/v1/swagger/paths/illrequests.json +++ b/api/v1/swagger/paths/illrequests.json @@ -1,8 +1,8 @@ { "/illrequests": { "get": { - "x-mojo-controller": "Koha::REST::V1::Illrequests", - "operationId": "list", + "x-mojo-to": "Illrequests#list", + "operationId": "listIllrequests", "tags": ["illrequests"], "parameters": [{ "name": "embed", @@ -85,7 +85,37 @@ ], "responses": { "200": { - "description": "OK" + "description": "A list of ILL requests" + }, + "401": { + "description": "Authentication required", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "403": { + "description": "Access forbidden", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "404": { + "description": "ILL requests not found", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "503": { + "description": "Under maintenance", + "schema": { + "$ref": "../definitions.json#/error" + } } }, "x-koha-authorization": { -- 2.7.4