Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

a suggestion to fix the sample in the documentation #32

Open
seansylvan opened this issue Aug 31, 2014 · 2 comments
Open

a suggestion to fix the sample in the documentation #32

seansylvan opened this issue Aug 31, 2014 · 2 comments

Comments

@seansylvan
Copy link

I cut-and-pasted the example from the readme document and found a few typos that cause compilation error. This is the version I tested working (as of the latest 8/30/2014 snapshot). It would be great it can be included in the next version of the update of the readme.

var express = require('express'),
    swagger = require('swagger-jack');

var app = express();

app.use(express.bodyParser());

app.use(express.methodOverride());

app.use(swagger.generator(app, {
    // general descriptor part
    apiVersion: '2.0',
    basePath: 'http://my-hostname.com/api'
  }, [{
    // descriptor of a given resource
    api: {
      resourcePath: '/user',
      apis: [{
        path: '/user/',
        operations: [{
          httpMethod: 'POST',
          nickname: 'create',
          responseClass: 'void'
        }, {
          httpMethod: 'GET',
          nickname: 'list',
          responseClass: 'void'
        }]
      }]
    },
    // controller for this resource
    controller:
    {
      create: function(req, res, next) {
        return res.send(200);
      },
      list: function(req, res, next) {
        return res.send(200);
      }
    }
  }]));

app.use(swagger.validator(app));
app.use(swagger.errorHandler());

app.get("/api/unvalidated", function(req, res, next) {
  // not documented not validated
});

app.listen(8080);
@glatorre
Copy link

glatorre commented Sep 4, 2014

Hi,
I tried this code with express 4. I've fixed the code as the following:

...
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var app = express();
app.use(bodyParser.json());
app.use(methodOverride());
...

When I get http://localhost:8080/api/user I receive the following error as a browser response

{"message":"Object function router(req, res, next) {\n router.handle(req, res, next);\n } has no method 'matchRequest'"}

Is there something wrong?
Tnx

@d1b1
Copy link

d1b1 commented Sep 4, 2015

I am having the same issue.

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

3 participants