trailsjs / sails-swagger

Swagger integration for sails.js
107 stars 47 forks source link

it trows an error on startup #15

Closed talamaska closed 8 years ago

talamaska commented 8 years ago
The bootstrap function threw an error after its callback was called :: TypeError: Invalid attempt to destructure non-iterable instance
    at server-location\node_modules\sails-swagger\dist\lib\xfmr.js:7:586
    at Object.getControllerFromRoute (server-location\node_modules\sails-swagger\dist\lib\xfmr.js:208:29)
    at Object.getPathTags (server-location\node_modules\sails-swagger\dist\lib\xfmr.js:178:183)
    at Object.getOperation (server-location\node_modules\sails-swagger\dist\lib\xfmr.js:169:25)
    at server-location\node_modules\sails-swagger\dist\lib\xfmr.js:155:26
    at server-location\node_modules\lodash\index.js:3395:24
    at server-location\node_modules\lodash\index.js:3073:15
    at baseForOwn (server-location\node_modules\lodash\index.js:2046:14)
    at Function.mapValues (server-location\node_modules\lodash\index.js:3394:9)
    at Object.getPathItem (server-location\node_modules\sails-swagger\dist\lib\xfmr.js:154:32)
    at server-location\node_modules\sails-swagger\dist\lib\xfmr.js:113:26
    at server-location\node_modules\lodash\index.js:3395:24
    at server-location\node_modules\lodash\index.js:3073:15
    at baseForOwn (server-location\node_modules\lodash\index.js:2046:14)
    at Function.mapValues (server-location\node_modules\lodash\index.js:3394:9)
    at Object.getPaths (server-location\node_modules\sails-swagger\dist\lib\xfmr.js:112:32) [TypeError: Invalid attempt to destructure non-iterable instance]

What I'm doing wrong?

zontafil commented 8 years ago

similar problem:

  error: The bootstrap function threw an error after its callback was called :: ReferenceError: Symbol is not defined
      at Object.getPathControllerTag (/home/dati/Sorgenti/Node/d/node_modules/sails-swagger/dist/lib/xfmr.js:226:51)
      at Object.getPathTags (/home/dati/Sorgenti/Node/d/node_modules/sails-swagger/dist/lib/xfmr.js:211:129)
      at Object.getOperation (/home/dati/Sorgenti/Node/d/node_modules/sails-swagger/dist/lib/xfmr.js:200:25)
      at /home/dati/Sorgenti/Node/d/node_modules/sails-swagger/dist/lib/xfmr.js:186:26
      at /home/dati/Sorgenti/Node/d/node_modules/sails-swagger/node_modules/lodash/index.js:3395:24
      at /home/dati/Sorgenti/Node/d/node_modules/sails-swagger/node_modules/lodash/index.js:3073:15
      at baseForOwn (/home/dati/Sorgenti/Node/d/node_modules/sails-swagger/node_modules/lodash/index.js:2046:14)
      at Function.mapValues (/home/dati/Sorgenti/Node/d/node_modules/sails-swagger/node_modules/lodash/index.js:3394:9)
      at Object.getPathItem (/home/dati/Sorgenti/Node/d/node_modules/sails-swagger/dist/lib/xfmr.js:185:32)
      at /home/dati/Sorgenti/Node/d/node_modules/sails-swagger/dist/lib/xfmr.js:142:26
      at /home/dati/Sorgenti/Node/d/node_modules/sails-swagger/node_modules/lodash/index.js:3395:24
      at /home/dati/Sorgenti/Node/d/node_modules/sails-swagger/node_modules/lodash/index.js:3073:15
      at baseForOwn (/home/dati/Sorgenti/Node/d/node_modules/sails-swagger/node_modules/lodash/index.js:2046:14)
      at Function.mapValues (/home/dati/Sorgenti/Node/d/node_modules/sails-swagger/node_modules/lodash/index.js:3394:9)
      at Object.getPaths (/home/dati/Sorgenti/Node/d/node_modules/sails-swagger/dist/lib/xfmr.js:141:32)
      at Object.getSwagger (/home/dati/Sorgenti/Node/d/node_modules/sails-swagger/dist/lib/xfmr.js:66:26)
      at /home/dati/Sorgenti/Node/d/node_modules/sails-swagger/dist/api/hooks/swagger/index.js:77:41
      at /home/dati/Sorgenti/Node/d/node_modules/sails/lib/app/private/after.js:91:14
      at /home/dati/Sorgenti/Node/d/node_modules/sails/node_modules/async/lib/async.js:251:17
      at done (/home/dati/Sorgenti/Node/d/node_modules/sails/node_modules/async/lib/async.js:132:19)
      at /home/dati/Sorgenti/Node/d/node_modules/sails/node_modules/async/lib/async.js:32:16
      at /home/dati/Sorgenti/Node/d/node_modules/sails/node_modules/async/lib/async.js:248:21 [ReferenceError: Symbol is not defined]
zuker commented 8 years ago

This happens when controller property in route config don't match pattern here https://github.com/tjwebb/sails-swagger/blob/v0.5.1/lib/xfmr.js#L188.

talamaska commented 8 years ago

Well, so we must name our controllers properly. But interesting is on https://github.com/tjwebb/sails-swagger/blob/v0.5.1/lib/xfmr.js#L193 that this pattern variable is never used.

zuker commented 8 years ago

Yes, variable pattern is never used, but the same pattern /(.+)Controller/ is used here: https://github.com/tjwebb/sails-swagger/blob/v0.5.1/lib/xfmr.js#L193

talamaska commented 8 years ago

You're right but this logic doesn't correspond to the Sails docs about custom routes http://sailsjs.org/documentation/concepts/routes/custom-routes

'GET /foo/go': 'FooController.myGoAction',
'GET /foo/go': 'Foo.myGoAction',
'GET /foo/go': {controller: "Foo", action: "myGoAction"},
'GET /foo/go': {controller: "FooController", action:"myGoAction"},

so this plugin will detect only the last route?

zuker commented 8 years ago

It seems that yes: only controllers specified by globalId (i.e. controller: "FooController") in route configuration are detected properly.

thibaultboursier commented 7 years ago

Same problem, I had to add "Controller" suffix on controller property to make it working.