From 80b6ba9600e83d05224c9dd1d690a5f76c61ed9b Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Tue, 3 Jan 2017 17:12:54 +0200
Subject: [PATCH] Minor API fixes (#877)

- Added error handling to Swagger spec fragment parsing
- Fixed a phpdoc mistake
- Tweaked code style
---
 module/VuFindApi/src/VuFindApi/Controller/ApiController.php | 6 ++++++
 module/VuFindApi/src/VuFindApi/Controller/ApiInterface.php  | 2 +-
 .../src/VuFindApi/Controller/SearchApiController.php        | 3 +--
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/module/VuFindApi/src/VuFindApi/Controller/ApiController.php b/module/VuFindApi/src/VuFindApi/Controller/ApiController.php
index 391045b7af1..9d7d795ca9d 100644
--- a/module/VuFindApi/src/VuFindApi/Controller/ApiController.php
+++ b/module/VuFindApi/src/VuFindApi/Controller/ApiController.php
@@ -108,6 +108,12 @@ class ApiController extends \VuFind\Controller\AbstractBase
         foreach ($this->apiControllers as $controller) {
             $api = $controller->getSwaggerSpecFragment();
             $specs = json_decode($api, true);
+            if (null === $specs) {
+                throw new \Exception(
+                    'Could not parse Swagger spec fragment of '
+                    . get_class($controller)
+                );
+            }
             foreach ($specs as $key => $spec) {
                 if (isset($results[$key])) {
                     $results[$key] = array_merge($results[$key], $spec);
diff --git a/module/VuFindApi/src/VuFindApi/Controller/ApiInterface.php b/module/VuFindApi/src/VuFindApi/Controller/ApiInterface.php
index ec71fb4d6aa..37b57e26762 100644
--- a/module/VuFindApi/src/VuFindApi/Controller/ApiInterface.php
+++ b/module/VuFindApi/src/VuFindApi/Controller/ApiInterface.php
@@ -46,7 +46,7 @@ interface ApiInterface
      * Get Swagger specification JSON fragment for services provided by the
      * controller
      *
-     * @return \Zend\Http\Response
+     * @return string
      */
     public function getSwaggerSpecFragment();
 }
diff --git a/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php b/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php
index 91697197533..e54cb7d0395 100644
--- a/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php
+++ b/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php
@@ -222,8 +222,7 @@ class SearchApiController extends \VuFind\Controller\AbstractSearch
 
         $this->determineOutputMode();
 
-        if ($result = $this->isAccessDenied($this->searchAccessPermission)
-        ) {
+        if ($result = $this->isAccessDenied($this->searchAccessPermission)) {
             return $result;
         }
 
-- 
GitLab