gulp-loopback-swagger-validator

A gulp module to validate loopback code against swagger spec


License
MIT
Install
npm install gulp-loopback-swagger-validator@0.0.2

Documentation

gulp-loopback-swagger-validator


NPM

NPM

Build status codecov

Gulp plugin that parses Swagger specifications in YAML format, validates against the official [Swagger 2.0 schema][swagger2spec], and compares against loopback application

Usage

Pre-requisite changes in Loopback configuration:

  1. Create a folder called 'spec' and store your YAML specification file
  2. Make changes to component-config.json Modify the configuration of the loopback-explorer component as:
{
  "loopback-component-explorer": {
    "mountPath": "/explorer",
    "consumes": "${consumes}",
    "produces" : "${produces}",
    "apiInfo": "${apiInfo}"
  }
}
  1. Make changes to config.json At the end of config.json file add the follow configuration:
{
      "apiInfo": {
        "title": Title of the your API application as written in YAML
      },
      "consumes":Array of mime types that your application consumes (as written in YAML),
      "produces":Array of mime types that your application produces (as written in YAML)
}
  1. Add gulpfile task
var gulp = require('gulp');
var lbValidator = require('gulp-loopback-swagger-validator');
var swagger = require('gulp-swagger');
var path     = require('path');

gulp.task('swagger-validate', function() {
  gulp.src('./json/*.json')
  .pipe(swagger('schema.json'))
  .pipe(lbValidator({'appPath':path.resolve('./project/server/server')}))
  .on('error',function(e){
      console.log(e.message);
  });
});



gulp.task('default', ['swagger-validate']);
  1. Preview in the console

Preview

See Also