Classement par préférence :
Site principal : RAML : v1.0 (2015-11-03) [Licence MIT]
Site principal : API-BluePrint : v1A9 (2015-06-08) [Licence MIT]
Permet de rédiger la doc en Markdown. Relativement complexe pour se retrouver dans la doc.
Site principal : Swagger : v2.0 (2014-09-08) [Licence Apache, v2.0] Ancien, mais toujours actif. Syntaxe YAML. Editeur et doc utilise nodejs. L'écosystème semble moins développer que les précédents. Le générateur de SDK est en Java…
Pour simplifier, on peut rajouter ces commandes dans la partie scripts du fichier package.json, avec les entrées :
"aglio-server": "./node_modules/.bin/aglio -i mon-api.apib --theme-full-width --theme-variables flatly -s", "aglio-convert": "./node_modules/.bin/aglio -i mon-api.apib --theme-full-width --theme-variables flatly -o mon-api.html"
Serveur de mock de l'API. Ajouter dans la partie scripts du fichier package.json :
"drakov": "./node_modules/.bin/drakov -f mon-api.apib"
"dredd": "./node_modules/.bin/dredd"
On pourra ensuite utiliser les commandes :
Permet de découper une document Markdown en plusieurs sous partie.
"hercule": "./node_modules/.bin/hercule mon-api.src.apib -o mon-api.apib"
Permet d'automatiser le fonctionnement des modules ci-dessus : aglio, dredd et hercule.
var gulp = require('gulp'); var plumber = require('gulp-plumber'); var rename = require("gulp-rename"); var es = require('event-stream'); var hercule = require('hercule'); var dredd = require('dredd'); var exec = require('child_process').exec; gulp.task('default', ['startWatcher', 'startAglioServer']); gulp.task('startAglioServer', function() { exec('./node_modules/.bin/aglio -i mon-api.apib --theme-full-width --theme-variables flatly -s', function (error, stdout, stderr) { console.log('Stdout: ' + stdout); console.log('Stderr: ' + stderr); if (error !== null) { console.log('Exec error: ' + error); } }); }); gulp.task('startWatcher', function() { var watcher = gulp.watch('mon-api.src.apib', ['doHercule']); var watcherDest = gulp.watch('mon-api.apib', ['doDredd']); watcher.on('change', function(event) { console.log('File ' + event.path + ' was ' + event.type + ', running tasks...'); }); }); gulp.task('doHercule', function() { function transclude() { // you're going to receive Vinyl files as chunks function transform(file, cb) { hercule.transcludeString(file.contents.toString(), function(output) { file.contents = new Buffer(output); }); cb(null, file); } return es.map(transform); }; gulp.src('mon-api.src.apib') .pipe(plumber()) .pipe(transclude()) .pipe(rename('mon-api.apib')) .pipe(gulp.dest('./')); }); gulp.task('doDredd', function() { var dreddConfig = { server: 'http://api.mon-site.org/mon-api/v1', // your URL to API endpoint the tests will run against options: { 'path': 'mon-api.apib', // Required Array if Strings; filepaths to API Blueprint files, can use glob wildcards 'dry-run': false, // Boolean, do not run any real HTTP transaction 'names': false, // Boolean, Print Transaction names and finish, similar to dry-run 'level': 'verbose', // String, log-level (info, silly, debug, verbose, ...) 'silent': false, // Boolean, Silences all logging output 'only': [], // Array of Strings, run only transaction that match these names 'header': [], // Array of Strings, these strings are then added as headers (key:value) to every transaction 'user': null, // String, Basic Auth credentials in the form username:password 'hookfiles': [], // Array of Strings, filepaths to files containing hooks (can use glob wildcards) //'reporter': ['dot', 'html'], // Array of possible reporters, see folder src/reporters //'output': [], // Array of Strings, filepaths to files used for output of file-based reporters 'inline-errors': false, // Boolean, If failures/errors are display immediately in Dredd run 'color': true, 'timestamp': false } //'emitter': EventEmitterInstance, // optional - listen to test progress, your own instance of EventEmitter //'hooksData': { // 'pathToHook' : '' //} }; var dredd = new dredd(dreddConfig); dredd.run(function (err, stats) { if (err) { console.log(err); } }); });