Socket
Book a DemoInstallSign in
Socket

gulp-swagger-endpoint

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-swagger-endpoint

Endpoint exporter for swagger

1.0.16
latest
Source
npmnpm
Version published
Maintainers
2
Created
Source

Swagger Endpoints

Install

Install with npm

npm install gulp-swagger-endpoint --save-dev

Configuration File.

Set plugin configuration

endpoints: This takes an array of objects, multiple domain and endpoint combinations can be added

useCommonJs: If using common js to build your app, set this to true. If false, a JS object will be created with your endpoints as Key/Value pairs

fileName: Your filename

prefix: If you wish to change the prefix of your URL, assign prefix.change to true. e.g. /api/product will change to /_api/product

gulp.swagger.conf.json file

This is the default configuration file located in the package root, please copy this file into your app root (where your package.json file is), and edit your configuartions there. This is to avoid your beautiful config file being overwritten on an npm update command.

{
  "Default": {
    "endpoints": [{
    "domain": "http://petstore.swagger.io",
    "swaggerUrl": "http://petstore.swagger.io/v2/swagger.json",
    "prefix": { 
      "change": false,
      "oldPrefix" : "api",
      "newPrefix" : "_api"
    }
  }],
  "useCommonJs": true,
  "fileName": "endpoint.js"
  }
}

You can add more environment variables as properties; so your file could end up looking like this:

{
  "Default": {
    "endpoints": [{
    "domain": "http://petstore.swagger.io",
    "swaggerUrl": "http://petstore.swagger.io/v2/swagger.json",
    "prefix": { 
      "change": false,
      "oldPrefix" : "api",
      "newPrefix" : "_api"
    }
  }],
  "useCommonJs": true,
  "fileName": "endpoint.js"
  },
  "Local": {
    "endpoints": [{
    "domain": "http://petstore.swagger.io",
    "swaggerUrl": "http://petstore.swagger.io/v2/swagger.json",
    "prefix": { 
      "change": false,
      "oldPrefix" : "api",
      "newPrefix" : "_api"
    }
  }],
  "useCommonJs": true,
  "fileName": "local.endpoint.js"
  }
}

Example

gulpfile.js

Plugin creates a js file which is containing all endpoints in your restfull API

You can pass a parameter to the swagger function (in this case: 'Local') to create the endpoints for a specific environment. If left blank or '', default environment will be used

gulp.task('endPoint', function() {
    return gulp.src("./node_modules/gulp-swagger-endpoint/index.js")
          .pipe(swagger('Default'))
          .pipe(gulp.dest('./Scripts/Common/angularjs/config'));
});

endpoints.js

Sample output file w/ commonJS = true

module.exports = {
     API_URLS: {
      /*  Endpoints from http://petstore.swagger.io/v2/swagger.json */ 
         Get_Product: "http://petstore.swagger.io/api/product",
         Get_ProductById: "http://petstore.swagger.io/api/product/{Id}",
         Get_ProductByCategoryId: "http://petstore.swagger.io/api/product/{CategoryId}",
         Post_Product: "http://petstore.swagger.io/api/product"
     }
};

Sample output file w/ commonJS = false

 API_URLS = {
    /*  Endpoints from http://petstore.swagger.io/v2/swagger.json */ 
     "Get_Product": "http://petstore.swagger.io/api/product",
     "Get_ProductById": "http://petstore.swagger.io/api/product/{Id}",
     "Get_ProductByCategoryId": "http://petstore.swagger.io/api/product/{CategoryId}",
     "Post_Product": "http://petstore.swagger.io/api/product"
 };

Keywords

gulpplugin

FAQs

Package last updated on 10 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.