ghaiklor / generator-sails-rest-api

Yeoman generator for scaffolding Sails REST API with predefined features
http://ghaiklor.github.io/generator-sails-rest-api/
MIT License
335 stars 52 forks source link

How to set api_key for Swagger UI Explorer? #148

Closed bossyang closed 8 years ago

bossyang commented 8 years ago

Or is there default api_key for demonstration purpose?

ghaiklor commented 8 years ago

@bossyang you can disable policy for DocsController, if you want to show Explorer without api key. There is still a question how to add support for Bearer tokens in Explorer.

bossyang commented 8 years ago

@ghaiklor Thanks. Is this normal?

No package information
You should set sails.config.swagger.pkg to retrieve the content of the package.json file

And the operations are not quite right. AuthController for example: sails-swagger-list-operations

ghaiklor commented 8 years ago

@bossyang we are using this hook https://github.com/tjwebb/sails-swagger for collecting data.

I know about these issues but can do nothing with it :(

evereq commented 8 years ago

@bossyang seems I found a way to get rid of this message about missing package info (Swagger wants to read your project name and description from it).

In the config folder of your sails app, create file swagger.js with something like:

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

@ghaiklor can also create such config file in the yo generator some day....

ghaiklor commented 8 years ago

@IncoCode could you add config for our explorer ?

bossyang commented 8 years ago

@evereq Thanks. It works! And where to set the default url? swagger-ui-default-url-issue

evereq commented 8 years ago

@bossyang it's in the explorer/index.html file

bossyang commented 8 years ago

@evereq Thanks. I changed the default to the current url.

  <script type="text/javascript">
    $(function () {
      var url = window.location.search.match(/url=([^&]+)/);
      if (url && url.length > 1) {
        url = decodeURIComponent(url[1]);
      } else {
        var base_url = window.location.origin;
        url = base_url + "/v1/Docs/";
      }
ghaiklor commented 8 years ago

@bossyang @evereq so what's the question? Do we need to add swagger config? Maybe some other fixes...

bossyang commented 8 years ago

@ghaiklor Yes, please.