From c85ae52c22592587e5bae7f7c5974400a9f07b0d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 19 Mar 2020 12:04:39 -0300 Subject: [PATCH] Bug 24908: Add text-formatted MARC support in /biblios/{biblio_id} This patch makes the route support requesting (through the Accept header) the MARC record to be output as formatted text as in $record->as_formatted. To test: 1. Apply the unit tests patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/biblios.t => FAIL: Tests fail 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Try the route with your favourite API testing tool (Postman?) => SUCCESS: Accept: text/plain returns the expected results => SUCCESS: Wrong Accept header returns a list of valid formats, and includes 'text/plain'. 6. Sign off :-D Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Joy Nelson --- Koha/REST/V1/Biblios.pm | 8 +++++++- api/v1/swagger/paths/biblios.json | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index b3cba7c8d3..57b5241ee4 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -81,13 +81,19 @@ sub get { format => 'marc', text => $record->as_usmarc }, + txt => { + status => 200, + format => 'text/plain', + text => $record->as_formatted + }, any => { status => 406, openapi => [ "application/json", "application/marcxml+xml", "application/marc-in-json", - "application/marc" + "application/marc", + "text/plain" ] } ); diff --git a/api/v1/swagger/paths/biblios.json b/api/v1/swagger/paths/biblios.json index b2bb58a6ce..27ccc4c3e1 100644 --- a/api/v1/swagger/paths/biblios.json +++ b/api/v1/swagger/paths/biblios.json @@ -15,7 +15,8 @@ "application/json", "application/marcxml+xml", "application/marc-in-json", - "application/marc" + "application/marc", + "text/plain" ], "responses": { "200": { -- 2.39.5