title: Creating API factory with SwaggerJS
body: <p>So I have this long standing APIService factory that creates functions to pass through the swagger functions to the UI. Here's a snippet of the factory:</p>
  
  <pre><code>'use strict';
  
  angular.module('myApp').factory('APIService', function ($http, $window, $q, swaggerClient, $mdToast) {
      var ApiDoc = {};
  
      ApiDoc.getAllBookmarks = function () {
          return $q(function (resolve, reject) {
              $http.get('client/components/api/Schema.json')
                      .success(function (data) {
                          var schema = data;
                          _.each(schema.apis, function (b) {
                              b.apiDeclaration.basePath = $window.location.origin;
                          })
  
                          var api = swaggerClient(schema);
                          api = api.apiBookmarks.getAll();
                          resolve(api);
                       });
          });
      }
      return ApiDoc;
  });
  </code></pre>
  
  <p>And here is a snippet of it's use case in a controller:</p>
  
  <pre><code>$scope.getAllDashboards = function () {
      APIService.getAllBookmarks().then(function(data){
          if (data.length &gt; 0){
             $scope.dashboardsList = data;
             $scope.emptyDash = false;
          } else {
             $scope.emptyDash = true;
          }
      })
  }
  
  $scope.getAllDashboards();
  </code></pre>
  
  <p>The inherent problem herein, is that if I have 30 API function calls in a controller, then there are 30 $http requests for schema.json that are un-needed really. Problem is that I can't figure out how to request/store that json and call on the functions with swagger the same way as they are now (or else I have to change 200+ methods in controllers, urgh). I tried this:</p>
  
  <pre><code>// var api = null;
  // $http.get('client/components/api/Schema.json')
  //     .success(function (data) {
  //         var schema = data;
  //         _.each(schema.apis, function (b) {
  //             b.apiDeclaration.basePath = $window.location.origin;
  //         })
  //         api = swaggerClient(schema);
  //     });
  </code></pre>
  
  <p>But couldn't get a function after that to read it properly, or return the result of the function call in a promise like the controllers expect.</p>
  
  <p>I have no other JS developers here so I need help from you all! Thanks much!</p>