Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Update example to use constructor and not setAppHandler #181

Closed
JohnMcLear opened this issue Nov 16, 2014 · 3 comments
Closed

Update example to use constructor and not setAppHandler #181

JohnMcLear opened this issue Nov 16, 2014 · 3 comments

Comments

@JohnMcLear
Copy link

The current docs suggest doing swagger.setAppHandler(app); which will output a warning of setAppHandler is deprecated! Pass it to the constructor instead..

The docs should use a constructor example.

Thanks!

@mchavarriagam
Copy link

+1

Looking at the swagger code, this is what's on the latest commit (https://github.com/swagger-api/swagger-node-express/blob/e9dec80b9e1fa793b09679dc2505569290436be0/lib/swagger.js#L33-L62):

// TODO-3.0.0 REMOVE
var ignoreAppHandlerInConstructor = true;

// TODO-3.0.0 REMOVE
// For backwards compatability, we just export a new instance of Swagger
module.exports = exports = new Swagger();

function Swagger(appHandler) {

  if (!(this instanceof Swagger)){
    return new Swagger(appHandler);
  }

  this.formatString = '.{format}';
  this.resourcePath = '/api-docs' + this.formatString;
  this.jsonSuffix = '.json';
  this.basePath = '/';
  this.apiInfo = null;
  this.authorizations = null;
  this.swaggerVersion = '1.2';
  this.apiVersion = '1.0';
  this.allModels = {};
  this.validators = [];
  this.appHandler = appHandler || null;
  this.resources = {};
  this.paramTypes = params;

  // For backwards compatability
  this.getModels = this.allModels;

  // TODO-3.0.0 REMOVE
  ignoreAppHandlerInConstructor = false;
}

So if I'm reading this correctly, there's currently no way to set the Application Handler in the constructor. It still has to be done via setAppHandler, so there's no way to avoid the warning right now.

Cheers.

@victory-deployment
Copy link

+1

@fehguy
Copy link
Contributor

fehguy commented Jun 3, 2015

This is addressed in #209

@fehguy fehguy closed this as completed Jun 3, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants