lib/server.js
function SwaggerServer(app) {
  app = app || express();

  // Event Emitter
  _.extend(this, EventEmitter.prototype);
  EventEmitter.call(this);

  /**
   * @type {Middleware}
   * @protected
   */
  this.__middleware = new SwaggerMiddleware(app);

  /**
   * @type {SwaggerParser}
   * @protected
   */
  this.__parser = new SwaggerParser(this);

  /**
   *
   * @type {Handlers|exports|module.exports}
   * @private
   */
  this.__handlers = new Handlers(this);

  /**
   * @type {SwaggerWatcher}
   * @protected
   */
  this.__watcher = new SwaggerWatcher(this);

  /**
   * The Express Application.
   * @type {e.application}
   */
  this.app = app;

  /**
   * The {@link DataStore} object that's used by the mock middleware.
   * See https://github.com/BigstickCarpet/swagger-express-middleware/blob/master/docs/exports/DataStore.md
   *
   * @type {DataStore}
   */
  Object.defineProperty(this, 'dataStore', {
    configurable: true,
    enumerable: true,
    get: function() {
      return app.get('mock data store');
    },
    set: function(value) {
      app.set('mock data store', value);
    }
  });

  /**
   * Parses the given Swagger API.
   *
   * @param {string|object} swagger
   * The file path or URL of a Swagger 2.0 API spec, in YAML or JSON format.
   * Or a valid Swagger API object (see https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#swagger-object).
   *
   * @param {function} [callback]
   * function(err, api, parser)
   */
  this.parse = function(swagger, callback) {
    this.__parser.parse(swagger);

    if (_.isFunction(callback)) {
      this.__parser.whenParsed(callback);
    }
  };

  /**
   * Adds the Swaggerize Express handlers to the Express Instance
   * (see https://github.com/krakenjs/swaggerize-express for info and acceptable formats)
   */
  this.addHandlers = function() {
    this.__handlers.setupHandlers();
  };

  // Patch the Express app to support Swagger
  application.patch(this);

  // For convenience, expose many of the Express app's methods directly on the Swagger Server object
  var server = this;
  swaggerMethods.concat(['enable', 'disable', 'set', 'listen', 'use', 'route', 'all'])
    .forEach(function(method) {
      server[method] = app[method].bind(app);
    });
}
function SwaggerServer(app) {
  app = app || express();

  // Event Emitter
  _.extend(this, EventEmitter.prototype);
  EventEmitter.call(this);

  /**
   * @type {Middleware}
   * @protected
   */
  this.__middleware = new SwaggerMiddleware(app);

  /**
   * @type {SwaggerParser}
   * @protected
   */
  this.__parser = new SwaggerParser(this);

  /**
   *
   * @type {Handlers|exports|module.exports}
   * @private
   */
  this.__handlers = new Handlers(this);

  /**
   * @type {SwaggerWatcher}
   * @protected
   */
  this.__watcher = new SwaggerWatcher(this);

  /**
   * The Express Application.
   * @type {e.application}
   */
  this.app = app;

  /**
   * The {@link DataStore} object that's used by the mock middleware.
   * See https://github.com/BigstickCarpet/swagger-express-middleware/blob/master/docs/exports/DataStore.md
   *
   * @type {DataStore}
   */
  Object.defineProperty(this, 'dataStore', {
    configurable: true,
    enumerable: true,
    get: function() {
      return app.get('mock data store');
    },
    set: function(value) {
      app.set('mock data store', value);
    }
  });

  /**
   * Parses the given Swagger API.
   *
   * @param {string|object} swagger
   * The file path or URL of a Swagger 2.0 API spec, in YAML or JSON format.
   * Or a valid Swagger API object (see https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#swagger-object).
   *
   * @param {function} [callback]
   * function(err, api, parser)
   */
  this.parse = function(swagger, callback) {
    this.__parser.parse(swagger);

    if (_.isFunction(callback)) {
      this.__parser.whenParsed(callback);
    }
  };

  /**
   * Adds the Swaggerize Express handlers to the Express Instance
   * (see https://github.com/krakenjs/swaggerize-express for info and acceptable formats)
   */
  this.addHandlers = function() {
    this.__handlers.setupHandlers();
  };

  // Patch the Express app to support Swagger
  application.patch(this);

  // For convenience, expose many of the Express app's methods directly on the Swagger Server object
  var server = this;
  swaggerMethods.concat(['enable', 'disable', 'set', 'listen', 'use', 'route', 'all'])
    .forEach(function(method) {
      server[method] = app[method].bind(app);
    });
}
function SwaggerServer ( app ) { app = app || express ( ) ; // Event Emitter _ . extend ( this , EventEmitter . prototype ) ; EventEmitter . call ( this ) ; /**
   * @type {Middleware}
   * @protected
   */ this . __middleware = new SwaggerMiddleware ( app ) ; /**
   * @type {SwaggerParser}
   * @protected
   */ this . __parser = new SwaggerParser ( this ) ; /**
   *
   * @type {Handlers|exports|module.exports}
   * @private
   */ this . __handlers = new Handlers ( this ) ; /**
   * @type {SwaggerWatcher}
   * @protected
   */ this . __watcher = new SwaggerWatcher ( this ) ; /**
   * The Express Application.
   * @type {e.application}
   */ this . app = app ; /**
   * The {@link DataStore} object that's used by the mock middleware.
   * See https://github.com/BigstickCarpet/swagger-express-middleware/blob/master/docs/exports/DataStore.md
   *
   * @type {DataStore}
   */ Object . defineProperty ( this , 'dataStore' , { configurable : true , enumerable : true , get : function ( ) { return app . get ( 'mock data store' ) ; } , set : function ( value ) { app . set ( 'mock data store' , value ) ; } } ) ; /**
   * Parses the given Swagger API.
   *
   * @param {string|object} swagger
   * The file path or URL of a Swagger 2.0 API spec, in YAML or JSON format.
   * Or a valid Swagger API object (see https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#swagger-object).
   *
   * @param {function} [callback]
   * function(err, api, parser)
   */ this . parse = function ( swagger , callback ) { this . __parser . parse ( swagger ) ; if ( _ . isFunction ( callback ) ) { this . __parser . whenParsed ( callback ) ; } } ; /**
   * Adds the Swaggerize Express handlers to the Express Instance
   * (see https://github.com/krakenjs/swaggerize-express for info and acceptable formats)
   */ this . addHandlers = function ( ) { this . __handlers . setupHandlers ( ) ; } ; // Patch the Express app to support Swagger application . patch ( this ) ; // For convenience, expose many of the Express app's methods directly on the Swagger Server object var server = this ; swaggerMethods . concat ( [ 'enable' , 'disable' , 'set' , 'listen' , 'use' , 'route' , 'all' ] ) . forEach ( function ( method ) { server [ method ] = app [ method ] . bind ( app ) ; } ) ; }
The Swagger Server class, which wraps an Express Application and extends it.

@param {e.application} [app]  An Express Application. If not provided, a new app is created.
@constructor
@extends EventEmitter
The Swagger Server class which wraps an Express Application and extends it .