JSPM

  • Created
  • Published
  • Downloads 1323
  • Score
    100M100P100Q111144F

A Swagger codegen for JavaScript

Package Exports

  • swagger-js-codegen

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (swagger-js-codegen) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

#Swagger to JS Codegen Build Status NPM version Code Climate

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') 
    }
});

Grunt task

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.