gulp-loopback-swagger-validator
v0.0.3
Published
A gulp module to validate loopback code against swagger spec
Downloads
6
Readme
gulp-loopback-swagger-validator
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:
- Create a folder called 'spec' and store your YAML specification file
- 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}"
}
}
- 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)
}
- 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']);
- Preview in the console