Cannot set property 'doc' of undefined #3

Open
rashidshkh opened this Issue Sep 4, 2015 · 33 comments

Comments

Projects
None yet
@rashidshkh

When i use sails-swagger it says :- error: The bootstrap function threw an error after its callback was called :: Ty peError: Cannot set property 'doc' of undefined. Do you have any documentation about how to implement.

I dig more into code and found
this.sails.hooks.swagger get undefined
in node_modules\sails-swagger\dist\api\hooks\swagger\index.js

@jekiii

This comment has been minimized.

Show comment
Hide comment
@jekiii

jekiii Sep 6, 2015

I experienced the same issue. The hook was loaded successfully but was not added to sails.hooks.

jekiii commented Sep 6, 2015

I experienced the same issue. The hook was loaded successfully but was not added to sails.hooks.

@tjwebb

This comment has been minimized.

Show comment
Hide comment
@tjwebb

tjwebb Sep 12, 2015

Member

Sorry, updating documentation. This hooks currently works only with sails master

Member

tjwebb commented Sep 12, 2015

Sorry, updating documentation. This hooks currently works only with sails master

@ksnyde

This comment has been minimized.

Show comment
Hide comment
@ksnyde

ksnyde Sep 13, 2015

Will this make its way into v0.11? I'm not really sure on the timetable for v0.12 and happy to start on 0.12 if it's a relatively mature beta.

ksnyde commented Sep 13, 2015

Will this make its way into v0.11? I'm not really sure on the timetable for v0.12 and happy to start on 0.12 if it's a relatively mature beta.

@tjwebb

This comment has been minimized.

Show comment
Hide comment
@tjwebb

tjwebb Sep 13, 2015

Member

0.12 is in "release candidate" stage at the moment. I'm running it in production in a couple of places.

Member

tjwebb commented Sep 13, 2015

0.12 is in "release candidate" stage at the moment. I'm running it in production in a couple of places.

@ksnyde

This comment has been minimized.

Show comment
Hide comment
@ksnyde

ksnyde Sep 13, 2015

I'm running into problems getting it running with handlebars templates so for now I've reverted to 0.11.1; how painful is the migration to 0.12.x?

ksnyde commented Sep 13, 2015

I'm running into problems getting it running with handlebars templates so for now I've reverted to 0.11.1; how painful is the migration to 0.12.x?

@tjwebb

This comment has been minimized.

Show comment
Hide comment
@tjwebb

tjwebb Sep 14, 2015

Member

The upgrade path to 0.12 should be pretty painless. Can you file a more specific issue in the Sails repo?

Member

tjwebb commented Sep 14, 2015

The upgrade path to 0.12 should be pretty painless. Can you file a more specific issue in the Sails repo?

@ksnyde

This comment has been minimized.

Show comment
Hide comment
@ksnyde

ksnyde Sep 14, 2015

@tjwebb, sure will do. thanks for your feedback here.

ksnyde commented Sep 14, 2015

@tjwebb, sure will do. thanks for your feedback here.

@Glavin001

This comment has been minimized.

Show comment
Hide comment
@Glavin001

Glavin001 Sep 30, 2015

Is there migration from v0.11.x to v0.12.x instructions?

I am really excited to use sails-swagger however it is erroring with this issue.

Is there migration from v0.11.x to v0.12.x instructions?

I am really excited to use sails-swagger however it is erroring with this issue.

@drewlio

This comment has been minimized.

Show comment
Hide comment
@drewlio

drewlio Oct 8, 2015

Following. Just got the same thing on 0.11.2 and 0.12.0-rc3.

drewlio commented Oct 8, 2015

Following. Just got the same thing on 0.11.2 and 0.12.0-rc3.

@AlexisNo

This comment has been minimized.

Show comment
Hide comment
@AlexisNo

AlexisNo Oct 9, 2015

Contributor

Works on master for me, but not 0.12.0-rc3

Contributor

AlexisNo commented Oct 9, 2015

Works on master for me, but not 0.12.0-rc3

@devildeveloper

This comment has been minimized.

Show comment
Hide comment
@devildeveloper

devildeveloper Oct 11, 2015

sails is now on 0.11.2 as master, and i have te same error

sails is now on 0.11.2 as master, and i have te same error

@muhammadghazali

This comment has been minimized.

Show comment
Hide comment
@muhammadghazali

muhammadghazali Oct 11, 2015

Got the same error here:

sails lift

info: Starting app...

debug: hookPath: /home/ghazali/node-app/node_modules/sails-swagger/dist/api/hooks/swagger
debug: marlinspike (swagger): loading config from /home/ghazali/node-app/node_modules/sails-swagger/dist/config
debug: marlinspike (swagger): loading Services from /home/ghazali/node-app/node_modules/sails-swagger/dist/api/services...
warn: marlinspike (swagger): no Services found. skipping
debug: marlinspike (swagger): loading Controllers...
debug: marlinspike (swagger): loading Policies...
warn: marlinspike (swagger): no Policies found. skipping
info: 
info:                .-..-.
info: 
info:    Sails              <|    .-..-.
info:    v0.11.2             |\
info:                       /|.\
info:                      / || \
info:                    ,'  |'  \
info:                 .-'.-==|/_--'
info:                 `--'-------' 
info:    __---___--___---___--___---___--___
info:  ____---___--___---___--___---___--___-__
info: 
info: Server lifted in `/home/ghazali/version-control/actigage/actigage-api`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press <CTRL> + C at any time.

debug: --------------------------------------------------------
debug: :: Sun Oct 11 2015 22:39:55 GMT+0700 (WIB)

debug: Environment : development
debug: Port        : 1337
debug: --------------------------------------------------------
error: The bootstrap function threw an error after its callback was called :: TypeError: Cannot set property 'doc' of undefined
 at /home/ghazali/node-app/node_modules/sails-swagger/dist/api/hooks/swagger/index.js:49:18
 at /home/ghazali/node-app/node_modules/sails/lib/app/private/after.js:91:14
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:251:17
 at done (/home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:132:19)
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:32:16
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:248:21
 at Sails.<anonymous> (/home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:572:34)
 at Sails.g (events.js:260:16)
 at emitNone (events.js:72:20)
 at Sails.emit (events.js:166:7)
 at Sails.emitter.emit (/home/ghazali/node-app/node_modules/sails/lib/app/private/after.js:50:11)
 at sailsReady (/home/ghazali/node-app/node_modules/sails/lib/app/lift.js:47:11)
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:251:17
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:154:25
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:248:21
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:612:34 [TypeError: Cannot set property 'doc' of undefined]

Got the same error here:

sails lift

info: Starting app...

debug: hookPath: /home/ghazali/node-app/node_modules/sails-swagger/dist/api/hooks/swagger
debug: marlinspike (swagger): loading config from /home/ghazali/node-app/node_modules/sails-swagger/dist/config
debug: marlinspike (swagger): loading Services from /home/ghazali/node-app/node_modules/sails-swagger/dist/api/services...
warn: marlinspike (swagger): no Services found. skipping
debug: marlinspike (swagger): loading Controllers...
debug: marlinspike (swagger): loading Policies...
warn: marlinspike (swagger): no Policies found. skipping
info: 
info:                .-..-.
info: 
info:    Sails              <|    .-..-.
info:    v0.11.2             |\
info:                       /|.\
info:                      / || \
info:                    ,'  |'  \
info:                 .-'.-==|/_--'
info:                 `--'-------' 
info:    __---___--___---___--___---___--___
info:  ____---___--___---___--___---___--___-__
info: 
info: Server lifted in `/home/ghazali/version-control/actigage/actigage-api`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press <CTRL> + C at any time.

debug: --------------------------------------------------------
debug: :: Sun Oct 11 2015 22:39:55 GMT+0700 (WIB)

debug: Environment : development
debug: Port        : 1337
debug: --------------------------------------------------------
error: The bootstrap function threw an error after its callback was called :: TypeError: Cannot set property 'doc' of undefined
 at /home/ghazali/node-app/node_modules/sails-swagger/dist/api/hooks/swagger/index.js:49:18
 at /home/ghazali/node-app/node_modules/sails/lib/app/private/after.js:91:14
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:251:17
 at done (/home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:132:19)
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:32:16
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:248:21
 at Sails.<anonymous> (/home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:572:34)
 at Sails.g (events.js:260:16)
 at emitNone (events.js:72:20)
 at Sails.emit (events.js:166:7)
 at Sails.emitter.emit (/home/ghazali/node-app/node_modules/sails/lib/app/private/after.js:50:11)
 at sailsReady (/home/ghazali/node-app/node_modules/sails/lib/app/lift.js:47:11)
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:251:17
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:154:25
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:248:21
 at /home/ghazali/node-app/node_modules/sails/node_modules/async/lib/async.js:612:34 [TypeError: Cannot set property 'doc' of undefined]
@Masquer

This comment has been minimized.

Show comment
Hide comment
@Masquer

Masquer Oct 11, 2015

This hook currently works only with sails 0.12

Masquer commented Oct 11, 2015

This hook currently works only with sails 0.12

@kevinblanco

This comment has been minimized.

Show comment
Hide comment
@kevinblanco

kevinblanco Oct 13, 2015

Any update on this ? I get the same error using 0.11.2 and 0.12.

Any update on this ? I get the same error using 0.11.2 and 0.12.

@AlexisNo

This comment has been minimized.

Show comment
Hide comment
@AlexisNo

AlexisNo Oct 20, 2015

Contributor

The problem seems to be about the name of the hook. The hook itself assume it is sails.hooks.swagger, but with 0.12.0-rc3, it seems that the name is not cleaned and the hook is available as sails.hooks['sails-swagger']. Using the master branch of Sails, the hook is correctly loaded.

You can change the way sails loads an installable hook to load the hook correctly with 0.12.0-rc3. I didn't test it with 0.11.x.

// config/installedHooks.js
module.exports.installedHooks = {
   "sails-swagger": {
      // load the hook into sails.hooks.swagger instead of sails.hooks['sails-swagger']
      "name": "swagger"
   }
};

Then you can load the swagger document at http://127.0.0.1:1337/swagger/doc/

Edit
You may have to create this file too (Inspired by the permissions-api generator) to access to the hook's actions

// api/controllers/SwaggerController.js

var _ = require('lodash');
var _super = require('sails-swagger/dist/api/controllers/SwaggerController');

_.merge(exports, _super);
_.merge(exports, {

    // Extend with custom logic here by adding additional fields, methods, etc.

});
Contributor

AlexisNo commented Oct 20, 2015

The problem seems to be about the name of the hook. The hook itself assume it is sails.hooks.swagger, but with 0.12.0-rc3, it seems that the name is not cleaned and the hook is available as sails.hooks['sails-swagger']. Using the master branch of Sails, the hook is correctly loaded.

You can change the way sails loads an installable hook to load the hook correctly with 0.12.0-rc3. I didn't test it with 0.11.x.

// config/installedHooks.js
module.exports.installedHooks = {
   "sails-swagger": {
      // load the hook into sails.hooks.swagger instead of sails.hooks['sails-swagger']
      "name": "swagger"
   }
};

Then you can load the swagger document at http://127.0.0.1:1337/swagger/doc/

Edit
You may have to create this file too (Inspired by the permissions-api generator) to access to the hook's actions

// api/controllers/SwaggerController.js

var _ = require('lodash');
var _super = require('sails-swagger/dist/api/controllers/SwaggerController');

_.merge(exports, _super);
_.merge(exports, {

    // Extend with custom logic here by adding additional fields, methods, etc.

});
@svenarndt

This comment has been minimized.

Show comment
Hide comment
@svenarndt

svenarndt Nov 4, 2015

I had to create both files in my project directory.
In order to get it to run, I had to install lodash (npm install lodash --save)

I had to create both files in my project directory.
In order to get it to run, I had to install lodash (npm install lodash --save)

@lucj

This comment has been minimized.

Show comment
Hide comment
@lucj

lucj Nov 24, 2015

@AlexisNo I have added both files you described (and also installed lodash). Swagger spec is available form http://localhost:1337/swagger/doc but how do you use swagger-ui then ?

lucj commented Nov 24, 2015

@AlexisNo I have added both files you described (and also installed lodash). Swagger spec is available form http://localhost:1337/swagger/doc but how do you use swagger-ui then ?

@AlexisNo

This comment has been minimized.

Show comment
Hide comment
@AlexisNo

AlexisNo Nov 25, 2015

Contributor

Swagger UI is not part of sails-swagger.

From the Swagger UI README file:

Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation and sandbox from a Swagger-compliant API. Because Swagger UI has no dependencies, you can host it in any server environment, or on your local machine.
swagger-ui is independent.

You can quickly have a Swagger UI app running on your local environment using docker

docker build -t swagger-ui-builder .
docker run -p 127.0.0.1:8080:8080 swagger-ui-builder

This will start Swagger UI at http://localhost:8080. By default, CORS should be correctly configured for this address. But I think the current NPM version does not include it. You'll have to configure it yourself in your project.

// config/routes.js
module.exports.routes = {
  '/swagger/doc': {
    cors: {
      origin: 'http://localhost:8080',
      methods: 'GET,OPTIONS,HEAD'
    },
    controller: 'SwaggerController',
    action: 'doc'
  }
}

Also, use config/swagger.js to configure the address where http://localhost:1337/swagger/ui will redirect.

// config/swagger.js
module.exports.swagger = {
  /**
   * require() the package.json file for your Sails app.
   */
  pkg: require('../package'),
  ui: {
    url: 'http://localhost:8080'
  }
};
Contributor

AlexisNo commented Nov 25, 2015

Swagger UI is not part of sails-swagger.

From the Swagger UI README file:

Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation and sandbox from a Swagger-compliant API. Because Swagger UI has no dependencies, you can host it in any server environment, or on your local machine.
swagger-ui is independent.

You can quickly have a Swagger UI app running on your local environment using docker

docker build -t swagger-ui-builder .
docker run -p 127.0.0.1:8080:8080 swagger-ui-builder

This will start Swagger UI at http://localhost:8080. By default, CORS should be correctly configured for this address. But I think the current NPM version does not include it. You'll have to configure it yourself in your project.

// config/routes.js
module.exports.routes = {
  '/swagger/doc': {
    cors: {
      origin: 'http://localhost:8080',
      methods: 'GET,OPTIONS,HEAD'
    },
    controller: 'SwaggerController',
    action: 'doc'
  }
}

Also, use config/swagger.js to configure the address where http://localhost:1337/swagger/ui will redirect.

// config/swagger.js
module.exports.swagger = {
  /**
   * require() the package.json file for your Sails app.
   */
  pkg: require('../package'),
  ui: {
    url: 'http://localhost:8080'
  }
};
@lucj

This comment has been minimized.

Show comment
Hide comment
@lucj

lucj Nov 25, 2015

Thanks a lot for the details answer ! Got it working :)

lucj commented Nov 25, 2015

Thanks a lot for the details answer ! Got it working :)

@adrien-candiotti

This comment has been minimized.

Show comment
Hide comment
@adrien-candiotti

adrien-candiotti Dec 4, 2015

I got a problem with the CORS, even after doing what you said : the Access-Control-Allow-Origin header coming from my sailsjs app is empty, i can't find anything online.

I got a problem with the CORS, even after doing what you said : the Access-Control-Allow-Origin header coming from my sailsjs app is empty, i can't find anything online.

@lucj

This comment has been minimized.

Show comment
Hide comment
@lucj

lucj Dec 4, 2015

@adrien-candiotti I also have this problem so I copied the swagger-ui elements in an assets/docs folder instead, so ui is on the same machine/port. It seems I did not manage to setup the CORS correctly.

lucj commented Dec 4, 2015

@adrien-candiotti I also have this problem so I copied the swagger-ui elements in an assets/docs folder instead, so ui is on the same machine/port. It seems I did not manage to setup the CORS correctly.

@moisesrodriguez

This comment has been minimized.

Show comment
Hide comment
@moisesrodriguez

moisesrodriguez Dec 11, 2015

Contributor

@adrien-candiotti @lucj the problem with CORS is the config is hard coded #13. I believe the issue has been fixed in further commits in master, but a new released version has not been added to npm to publish the fix

Contributor

moisesrodriguez commented Dec 11, 2015

@adrien-candiotti @lucj the problem with CORS is the config is hard coded #13. I believe the issue has been fixed in further commits in master, but a new released version has not been added to npm to publish the fix

@lucj

This comment has been minimized.

Show comment
Hide comment
@lucj

lucj Dec 11, 2015

@moisesrodriguez Hi, thanks a lot for the update.

lucj commented Dec 11, 2015

@moisesrodriguez Hi, thanks a lot for the update.

@manodupont

This comment has been minimized.

Show comment
Hide comment
@manodupont

manodupont Dec 21, 2015

So i read all the thread and was wondering if there was a fix for Sails v0.11.3. ?

Thanks.

So i read all the thread and was wondering if there was a fix for Sails v0.11.3. ?

Thanks.

@tjwebb

This comment has been minimized.

Show comment
Hide comment
@tjwebb

tjwebb Dec 21, 2015

Member

I merged #18, I just need to publish to npm. You can use master for now

Member

tjwebb commented Dec 21, 2015

I merged #18, I just need to publish to npm. You can use master for now

@lucj

This comment has been minimized.

Show comment
Hide comment
@lucj

lucj Dec 22, 2015

Thanks a lot Travis !

On Mon, Dec 21, 2015 at 11:40 PM, Travis Webb notifications@github.com
wrote:

I merged #18 #18, I just
need to publish to npm. You can use master for now


Reply to this email directly or view it on GitHub
#3 (comment).

Luc Juggery - https://about.me/lucjuggery

lucj commented Dec 22, 2015

Thanks a lot Travis !

On Mon, Dec 21, 2015 at 11:40 PM, Travis Webb notifications@github.com
wrote:

I merged #18 #18, I just
need to publish to npm. You can use master for now


Reply to this email directly or view it on GitHub
#3 (comment).

Luc Juggery - https://about.me/lucjuggery

@selftaught91

This comment has been minimized.

Show comment
Hide comment
@selftaught91

selftaught91 Dec 30, 2015

@AlexisNo I did the steps as you have said but I am not getting the swagger Ui but only the json format document .
I didn't understand the docker part please help me @lucj

@AlexisNo I did the steps as you have said but I am not getting the swagger Ui but only the json format document .
I didn't understand the docker part please help me @lucj

@moisesrodriguez

This comment has been minimized.

Show comment
Hide comment
@moisesrodriguez

moisesrodriguez Jan 13, 2016

Contributor

@tjwebb would you mind publishing to npm. I'm getting this error on sails 0.12.0-rc4 and when I try to use master by doing this on my package.json "sails-swagger": "git://github.com/tjwebb/sails-swagger.git", it says it cannot find the module even thought it there.

Contributor

moisesrodriguez commented Jan 13, 2016

@tjwebb would you mind publishing to npm. I'm getting this error on sails 0.12.0-rc4 and when I try to use master by doing this on my package.json "sails-swagger": "git://github.com/tjwebb/sails-swagger.git", it says it cannot find the module even thought it there.

@ralberts

This comment has been minimized.

Show comment
Hide comment
@ralberts

ralberts Jan 17, 2016

Thanks @AlexisNo and @lucj - I was able to get it all running with your instructions! Now I need to figure out how to have the swagger-ui allow me to edit the post/put directly in swagger-ui like the demo.

@tjwebb I look forward to the npm push as well. Let me know if I can help.

Since I am not running off master for either project. I combined comments from this thread and hope it helps others:

  1. npm install --save lodash ( thx @svenarndt )
  2. Created the controller
// api/controllers/SwaggerController.js

var _ = require('lodash');
var _super = require('sails-swagger/dist/api/controllers/SwaggerController');

_.merge(exports, _super);
_.merge(exports, {
  // Extend with custom logic here by adding additional fields, methods, etc.
});
  1. Created the installHooks.js
// config/installedHooks.js
module.exports.installedHooks = {
  "sails-swagger": {
    // load the hook into sails.hooks.swagger instead of sails.hooks['sails-swagger']
    "name": "swagger"
  }
};
  1. Create swagger.js hook:
// config/swagger.js
module.exports.swagger = {
  /**
   * require() the package.json file for your Sails app.
   */
  pkg: require('../package'),
  ui: {
      url: 'http://swagger.balderdash.io'
  }
};
  1. Downloaded swagger-ui and copyied the dist/ contents to assets/docs under my current webapp as @lucj did. I am sure the docker way works well but I didn't try it as I wanted it all under the same app.
  2. Done. (At least I hope I got everything).

Thanks @AlexisNo and @lucj - I was able to get it all running with your instructions! Now I need to figure out how to have the swagger-ui allow me to edit the post/put directly in swagger-ui like the demo.

@tjwebb I look forward to the npm push as well. Let me know if I can help.

Since I am not running off master for either project. I combined comments from this thread and hope it helps others:

  1. npm install --save lodash ( thx @svenarndt )
  2. Created the controller
// api/controllers/SwaggerController.js

var _ = require('lodash');
var _super = require('sails-swagger/dist/api/controllers/SwaggerController');

_.merge(exports, _super);
_.merge(exports, {
  // Extend with custom logic here by adding additional fields, methods, etc.
});
  1. Created the installHooks.js
// config/installedHooks.js
module.exports.installedHooks = {
  "sails-swagger": {
    // load the hook into sails.hooks.swagger instead of sails.hooks['sails-swagger']
    "name": "swagger"
  }
};
  1. Create swagger.js hook:
// config/swagger.js
module.exports.swagger = {
  /**
   * require() the package.json file for your Sails app.
   */
  pkg: require('../package'),
  ui: {
      url: 'http://swagger.balderdash.io'
  }
};
  1. Downloaded swagger-ui and copyied the dist/ contents to assets/docs under my current webapp as @lucj did. I am sure the docker way works well but I didn't try it as I wanted it all under the same app.
  2. Done. (At least I hope I got everything).
@talamaska

This comment has been minimized.

Show comment
Hide comment
@talamaska

talamaska Jan 20, 2016

@ralberts thanks for your summary, the only thing I did not get is how to navigate to /assets/docs to actually open the swagger.io on local server.

@ralberts thanks for your summary, the only thing I did not get is how to navigate to /assets/docs to actually open the swagger.io on local server.

@blanco217

This comment has been minimized.

Show comment
Hide comment
@blanco217

blanco217 Jan 28, 2016

@ralberts Thanks for your explination it helped me get the ui up and running.

@talamaska you will go to http://localhost:1337/docs

@ralberts Thanks for your explination it helped me get the ui up and running.

@talamaska you will go to http://localhost:1337/docs

@ronsuez

This comment has been minimized.

Show comment
Hide comment
@ronsuez

ronsuez Feb 1, 2016

does anyone knows how to enable POST/PUT requests from the local swaggerUI?

ronsuez commented Feb 1, 2016

does anyone knows how to enable POST/PUT requests from the local swaggerUI?

@pankajdaffodil

This comment has been minimized.

Show comment
Hide comment
@pankajdaffodil

pankajdaffodil Feb 4, 2016

Please let me know how can I send data in query string?

Please let me know how can I send data in query string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment