From e03e5a2ecee3c7c773e1cce418703a88cc53bb53 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 --- 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 80c7200319..157282b4a1 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -82,13 +82,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 530993ff33..4896b71f62 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