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

Update to swagger-express-mw 0.6.0 ? #345

Closed
oliverhr opened this issue Jan 17, 2016 · 10 comments
Closed

Update to swagger-express-mw 0.6.0 ? #345

oliverhr opened this issue Jan 17, 2016 · 10 comments

Comments

@oliverhr
Copy link

Any plan to update to swagger-express-mw 0.6.0 ?
Or a guide to use with generated swagger-node projects?

@oliverhr oliverhr changed the title swagger-express-mw 0.6.0 Update to swagger-express-mw 0.6.0 ? Jan 17, 2016
@Hanspagh
Copy link

+1

@ronkot
Copy link

ronkot commented May 25, 2016

+1
Doesn't work with swagger-express-mw 0.6.0 and current documentation. It seems that req.swagger.params is undefined.

@molokoloco
Copy link

@ronkot i can advise you that it works better for me now with this code...
=> https://www.npmjs.com/package/swagger-tools
You can forget "swagger-express-mw"...

'use strict';

var swagger = require('swagger-tools');
var express = require('express');
var http = require('http');

var swaggerObject = require('./api/swagger/swagger.json');

var app = express();

swagger.initializeMiddleware(swaggerObject, function(middleware) {

    app.use(middleware.swaggerMetadata());
    app.use(middleware.swaggerValidator());
    app.use(middleware.swaggerRouter({useStubs: true, controllers: './api/controllers'}));
    app.use(middleware.swaggerUi());

    http
        .createServer(app)
        .listen(80);
});

@ronkot
Copy link

ronkot commented May 26, 2016

Thanks, @molokoloco! Your approach worked perfectly. Just had to add cors middleware (using cors npm module).

@AmreeshTyagi
Copy link

AmreeshTyagi commented Jun 13, 2016

@molokoloco How you are dealing with oauth2 security with swagger-tools. I am using swagger-express-mw and following is my approach for oauth2

var SwaggerExpress = require('swagger-express-mw')
var swaggerConfig = {
  appRoot: __dirname, // config.get('api').API_BASE_URI, // required config
  swaggerSecurityHandlers: {
    apiKey: services.authService.validateHeader,
    accessToken: services.authService.authorizeToken
  }
}
SwaggerExpress.create(swaggerConfig, function (err, swaggerExpress) {
  if (err) {
    throw err
  }

  // install middleware
  swaggerExpress.register(app)
)

This is working perfectly fine. But not sure about how to achieve this using swagger-tools. any idea? Tried with swagger security middleware, but it was not working.

@oliverhr
Copy link
Author

oliverhr commented Jun 27, 2016

The thing is that since version 0.6.0 swagger-node-runner no longer use swagger-tools, it was replaced with sway.

If you use the express middleware the dependency chain looks like this

0 - swagger-node
1 - swagger-express-mw
2 - swagger-node-runner "swagger-node-runner": "^0.6.1"
3 - "sway": "^0.3.2", "bagpipes": "^0.1.0"
...

https://github.com/apigee-127/sway
https://github.com/apigee-127/bagpipes

I also add a comment from @theganyo:
apigee-127/bagpipes#5 (comment)

@pourquoi42
Copy link

@oliverhr: this doesn't really address the question.

I am also stuck. I need some features/fixes that are in later of swagger-express-mw. But I can't just replace it, or I face the same issue that @ronkot described. Basically, my existing project doesnt work any more. I am very tempted to follow the adivse of molokoloco, yet I am totally confused about the roadmap: if sway replaces swagger-tools, does it mean swagger-tools will be abandoned ??? And if the swagger-tools direction is not the way to go, then can someone please advise on the original question, how to upgrade swagger-node-mw ? (If you use this project as is, you get swagger-node-mw v0.1.0 which has horrible bugs)

@stv8
Copy link

stv8 commented Jan 11, 2017

I want to add that I was having many problems with swagger-express-mw and using @molokoloco solution worked out the best.

I feel like the generator for an express app should use that as boilerplate instead of using swagger-express-mw

@Mojo90
Copy link

Mojo90 commented Feb 8, 2017

#460 should fix that ;)

@cadriel
Copy link

cadriel commented Mar 5, 2017

If the skeleton is now not the preferred approach, what would the app.js look like?

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

9 participants