🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

raml2code

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raml2code

Raml spec to code

npmnpm
Version
0.0.37
Version published
Weekly downloads
56
300%
Maintainers
1
Weekly downloads
 
Created
Source

Raml to code generator

Build Status

  • This module generate code from a RAML definition
  • It uses Handlebars templates

It must be defined as Gulp-plugin

var gulp = require('gulp');
var raml2code = require('raml2code');
var genDTO = require("raml2code/lib/generators/groovy/raml2DTO.js");

gulp.task("test", function(){
  gulp.src('./test/cats.raml')
    .pipe(raml2code({generator: genDTO, extra: {package:'com.gex'}}))
    .pipe(gulp.dest('build'));
});

Sample gulpfile

var gulp = require('gulp');

var raml2code = require("raml2code");
var genPojos = require("raml2code/lib/generators/groovy/pojo");
var genJaxRS = require("raml2code/lib/generators/groovy/jaxrsInterface");
var genRetrofitClient = require("raml2code/lib/generators/groovy/retrofitClient");

var raml = require('gulp-raml');

var packagePojo = "gex.catapi.dto";
var packageClient = "gex.catapi.client";
var packageJersey = "gex.catapi.resources";

//this should point to your raml definition
var ramlResource = '../../test/raml/cats.raml'

gulp.task('raml', function() {
  gulp.src(ramlResource)
    .pipe(raml())
    .pipe(raml.reporter('default'))
    .pipe(raml.reporter('fail'));
});

gulp.task("genPojos", ['raml'], function(){
  gulp.src(ramlResource)
    .pipe(raml2code({generator: genPojos, extra: {package: packagePojo}}))
    .pipe(gulp.dest('./src/generated/groovy/gex/catapi/dto'));
});

gulp.task("genRetrofitClient" , ['raml'], function(){
  gulp.src(ramlResource)
    .pipe(raml2code({generator: genRetrofitClient, extra: {package: packageClient, importPojos: packagePojo}}))
    .pipe(gulp.dest('./src/generated/java/gex/catapi/client'));
});

gulp.task("genJaxRS" , ['raml'], function(){
  gulp.src(ramlResource)
    .pipe(raml2code({generator: genJaxRS, extra: {package: packageJersey, importPojos: packagePojo}}))
    .pipe(gulp.dest('./src/generated/groovy/gex/catapi/resources'));
});

gulp.task('build', ['raml', 'genPojos',  'genJaxRS', 'genRetrofitClient']);

gulp.task('default', ['build']);

We use the Gradle with the gulp plugin to build or loved Java project

gradle

gradle-gulp-plugin

And example of project could be found here:

raml2codeFullSpringExample

You don't like our generators, DIY

A generator is a simple object with the following properties:

  • Required properties:
    • template -> Handlebars template (you could use your own templates).
    • parser(data) -> Function it receives RAML parsed data, returns model that will be used in the template engine, each model must have a name, this name is the file that will be generated. [{ name: "test.test", model: {title:data.title + " finos"}}]
  • Optional properties:
    • helpers -> Handlebars helpers.
    • partials -> Handlebars partials.

Generators included and tested

  • Groovy POJO If the json schema has $ref, it would try to use the title to make references, if the title doesn't exits it would generate a inner classes with the name of the property. If there are $ref definitions, consider the following http://json-schema.org/latest/json-schema-core.html#anchor30

  • JAX-RS Interface

  • RETROFIT Client

Keywords

RAML

FAQs

Package last updated on 09 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts