swagger-js-codegen

A Swagger codegen for JavaScript

#Swagger to JS Codegen

This package generates a nodejs or angularjs class from a swagger specification file. The code is generated using mustache templates and is quality checked by jshint and beautified by js-beautify.

##Installation

npm install swagger-js-codegen

##Example

var fs = require('fs');
var CodeGen = require('swagger-js-codegen').CodeGen;
 
var file = 'swagger/spec.json';
var swagger = JSON.parse(fs.readFileSync(file, 'UTF-8'));
var nodejsSourceCode = CodeGen.getNodeCode({ className: 'Test', swagger: swagger }); 
var angularjsSourceCode = CodeGen.getAngularCode({ className: 'Test', swagger: swagger }); 
console.log(nodejsSourceCode);
console.log(angularjsSourceCode);

##Custom template

var source = CodeGen.getCustomCode({
    moduleName: 'Test',
    className: 'Test',
    swagger: swaggerSpec, 
    template: {
        class: fs.readFileSync('my-class.mustache', 'utf-8'),
        method: fs.readFileSync('my-method.mustache', 'utf-8'),
        request:fs.readFileSync('my-request.mustache', 'utf-8') 
    }
});

There is a grunt task that enables you to integrate the code generation in your development pipeline. This is extremely convenient if your application is using APIs which are documented/specified in the swagger format.

##Who is using it? The CellStore project.

28.io is using this project to generate their nodejs and angularjs language bindings.