| var commonHelpers, dirname, fs, generator, path, template, util, _; | ||
| fs = require('fs'); | ||
| _ = require('lodash'); | ||
| util = require('./util.js'); | ||
| commonHelpers = require("../helpers/common.js").helpers(); | ||
| path = require('path'); | ||
| generator = {}; | ||
| generator.helpers = commonHelpers; | ||
| dirname = path.dirname(__filename); | ||
| template = path.resolve(dirname, "tmpl/jaxrsResources.hbs"); | ||
| generator.template = fs.readFileSync(template).toString(); | ||
| generator.parser = function(data) { | ||
| var first, k, methodParse, model, parsed, resource, resourceGroup, v, _i, _len, _ref; | ||
| parsed = []; | ||
| methodParse = []; | ||
| _ref = data.resources; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| resource = _ref[_i]; | ||
| util.parseResource(resource, methodParse); | ||
| } | ||
| resourceGroup = _.groupBy(methodParse, function(method) { | ||
| return method.displayName; | ||
| }); | ||
| for (k in resourceGroup) { | ||
| v = resourceGroup[k]; | ||
| model = {}; | ||
| if (data.extra) { | ||
| model.extra = data.extra; | ||
| } | ||
| first = _.first(v); | ||
| model.uri = first.uri; | ||
| model.className = "" + first.displayName + "Resource"; | ||
| model.methods = v; | ||
| parsed.push({ | ||
| name: model.className + ".groovy", | ||
| model: model | ||
| }); | ||
| } | ||
| return parsed; | ||
| }; | ||
| module.exports = generator; |
| var capitalize, commonHelpers, dirname, fs, generator, path, template, util; | ||
| fs = require('fs'); | ||
| commonHelpers = require("../helpers/common.js").helpers(); | ||
| util = require('./util.js'); | ||
| path = require('path'); | ||
| generator = {}; | ||
| generator.helpers = commonHelpers; | ||
| dirname = path.dirname(__filename); | ||
| template = path.resolve(dirname, "tmpl/pojo.hbs"); | ||
| generator.template = fs.readFileSync(template).toString(); | ||
| capitalize = function(str) { | ||
| return str.charAt(0).toUpperCase() + str.slice(1); | ||
| }; | ||
| generator.parser = function(datos) { | ||
| var data, key, model, p, parsed, ref, row, schemaName, _i, _len, _ref, _ref1; | ||
| parsed = []; | ||
| _ref = datos.schemas; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| row = _ref[_i]; | ||
| for (schemaName in row) { | ||
| data = JSON.parse(row[schemaName]); | ||
| model = {}; | ||
| model.className = data.title; | ||
| model.classMembers = []; | ||
| model.classDescription = (_ref1 = data.description) != null ? _ref1 : ""; | ||
| if (data.type === "array") { | ||
| ref = data.items['$ref'].replace("#/", "").split(".")[0]; | ||
| ref = capitalize(ref); | ||
| model.classMembers.push({ | ||
| name: "items", | ||
| type: "List<" + ref + ">" | ||
| }); | ||
| } | ||
| for (key in data.properties) { | ||
| p = data.properties[key]; | ||
| model.classMembers.push(util.mapProperty(p, key)); | ||
| } | ||
| if (datos.extra) { | ||
| model.extra = datos.extra; | ||
| } | ||
| parsed.push({ | ||
| name: capitalize("" + schemaName + ".groovy"), | ||
| model: model | ||
| }); | ||
| } | ||
| } | ||
| return parsed; | ||
| }; | ||
| module.exports = generator; |
| var commonHelpers, dirname, fs, generator, path, template, util; | ||
| fs = require('fs'); | ||
| commonHelpers = require("../helpers/common.js").helpers(); | ||
| util = require('./util.js'); | ||
| path = require('path'); | ||
| generator = {}; | ||
| generator.helpers = commonHelpers; | ||
| dirname = path.dirname(__filename); | ||
| template = path.resolve(dirname, "tmpl/retrofitClient.hbs"); | ||
| generator.template = fs.readFileSync(template).toString(); | ||
| generator.parser = function(data) { | ||
| var methodParse, model, parsed, resource, _i, _len, _ref; | ||
| parsed = []; | ||
| methodParse = []; | ||
| _ref = data.resources; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| resource = _ref[_i]; | ||
| util.parseResource(resource, methodParse); | ||
| } | ||
| model = {}; | ||
| model.methods = methodParse; | ||
| if (data.extra) { | ||
| model.extra = data.extra; | ||
| } | ||
| model.className = data.title.split(" ").join(""); | ||
| parsed.push({ | ||
| name: model.className + ".java", | ||
| model: model | ||
| }); | ||
| return parsed; | ||
| }; | ||
| module.exports = generator; |
| package {{extra.package}} | ||
| import javax.ws.rs.Consumes | ||
| import javax.ws.rs.GET | ||
| import javax.ws.rs.POST | ||
| import javax.ws.rs.Path | ||
| import javax.ws.rs.PathParam | ||
| import javax.ws.rs.Produces | ||
| import javax.ws.rs.core.Context | ||
| import javax.ws.rs.core.Response | ||
| import javax.ws.rs.core.UriInfo | ||
| {{#if extra.importPojos}} | ||
| import {{extra.importPojos}}.*; | ||
| {{/if}} | ||
| @Path("{{{uri}}}") | ||
| public interface {{className}} { | ||
| {{#methods}} | ||
| /*** | ||
| * @return Response This must be a valid {{{respond}}} JSON object. | ||
| */ | ||
| @{{annotation}} | ||
| public Response {{{name}}}({{#each args}}{{#if @index}}, {{/if}}{{{kind}}} {{type}} {{name}}{{/each}}); | ||
| {{/methods}} | ||
| } |
| package {{extra.package}} | ||
| import groovy.transform.* | ||
| {{#if classDescription}} | ||
| /** | ||
| *{{{classDescription}}} | ||
| **/{{/if}} | ||
| @CompileStatic | ||
| @Canonical | ||
| public class {{{className}}} implements Serializable { | ||
| {{#classMembers}} | ||
| {{#if comment}} /* {{comment}} */{{/if}} | ||
| {{{type}}} {{name}} | ||
| {{/classMembers}} | ||
| } |
| package {{extra.package}}; | ||
| import retrofit.http.Body; | ||
| import retrofit.http.Path; | ||
| import retrofit.http.DELETE; | ||
| import retrofit.http.GET; | ||
| import retrofit.http.POST; | ||
| import retrofit.http.PUT; | ||
| import java.util.List; | ||
| import rx.Observable; | ||
| {{#if extra.importPojos}} | ||
| import {{extra.importPojos}}.*; | ||
| {{/if}} | ||
| public interface {{{className}}} { | ||
| {{#methods}} | ||
| @{{annotation}}("{{{uri}}}") | ||
| public Observable<{{{respond}}}> {{{name}}}({{#each args}}{{#if @index}}, {{/if}}{{{kind}}} {{type}} {{name}}{{/each}}); | ||
| {{/methods}} | ||
| } |
| var util; | ||
| util = {}; | ||
| util.getUriParameter = function(resource) { | ||
| var key, p, uriParameters; | ||
| uriParameters = []; | ||
| for (key in resource.uriParameters) { | ||
| p = resource.uriParameters[key]; | ||
| uriParameters.push(util.mapProperty(p, key)); | ||
| } | ||
| return uriParameters; | ||
| }; | ||
| util.mapProperty = function(property, name) { | ||
| var p; | ||
| p = {}; | ||
| p.name = name; | ||
| p.comment = property.description; | ||
| switch (property.type) { | ||
| case 'array': | ||
| p.type = "List"; | ||
| p.name = "items"; | ||
| break; | ||
| case 'string': | ||
| p.type = "String"; | ||
| break; | ||
| case 'boolean': | ||
| p.type = "Boolean"; | ||
| break; | ||
| case 'number': | ||
| p.type = "Double"; | ||
| break; | ||
| case 'integer': | ||
| p.type = "Integer"; | ||
| } | ||
| p.kind = "@Path(\"" + p.name + "\")"; | ||
| return p; | ||
| }; | ||
| util.parseResource = function(resource, parsed, parentUri, parentUriArgs) { | ||
| var innerResource, m, methodDef, request, respond, uriArgs, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3; | ||
| if (parentUri == null) { | ||
| parentUri = ""; | ||
| } | ||
| if (parentUriArgs == null) { | ||
| parentUriArgs = []; | ||
| } | ||
| _ref = resource.methods; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| m = _ref[_i]; | ||
| methodDef = {}; | ||
| methodDef.uri = parentUri + resource.relativeUri; | ||
| uriArgs = util.getUriParameter(resource); | ||
| methodDef.args = parentUriArgs.concat(uriArgs); | ||
| request = util.parseSchema(m.body, "" + methodDef.uri + " body"); | ||
| respond = util.parseSchema(util.getBestValidResponse(m.responses).body, "" + methodDef.uri + " response"); | ||
| if (request.title) { | ||
| methodDef.args = (_ref1 = methodDef.args) != null ? _ref1 : []; | ||
| methodDef.args.push({ | ||
| 'kind': '@Body', | ||
| 'type': request.title, | ||
| 'name': request.title.toLowerCase() | ||
| }); | ||
| } | ||
| methodDef.request = (_ref2 = request.title) != null ? _ref2 : null; | ||
| methodDef.respond = respond.type === "array" ? "List<" + respond.title + ">" : respond.title; | ||
| methodDef.annotation = m.method.toUpperCase(); | ||
| methodDef.name = m.method + resource.displayName; | ||
| methodDef.displayName = resource.displayName; | ||
| parsed.push(methodDef); | ||
| } | ||
| if (resource.resources) { | ||
| _ref3 = resource.resources; | ||
| for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { | ||
| innerResource = _ref3[_j]; | ||
| util.parseResource(innerResource, parsed, resource.relativeUri, uriArgs); | ||
| } | ||
| } | ||
| return void 0; | ||
| }; | ||
| util.parseSchema = function(body, meta) { | ||
| var e, schema; | ||
| if (meta == null) { | ||
| meta = ''; | ||
| } | ||
| schema = {}; | ||
| if (body && body['application/json']) { | ||
| try { | ||
| schema = JSON.parse(body['application/json'].schema); | ||
| } catch (_error) { | ||
| e = _error; | ||
| console.log("-----JSON ERROR on " + meta + "---------"); | ||
| console.log(body['application/json'].schema); | ||
| throw e; | ||
| } | ||
| } | ||
| return schema; | ||
| }; | ||
| util.getBestValidResponse = function(responses) { | ||
| var response, _ref, _ref1, _ref2, _ref3; | ||
| return response = (_ref = responses["304"]) != null ? _ref : response = (_ref1 = responses["204"]) != null ? _ref1 : response = (_ref2 = responses["201"]) != null ? _ref2 : response = (_ref3 = responses["200"]) != null ? _ref3 : response; | ||
| }; | ||
| module.exports = util; |
| fs = require('fs') | ||
| _ = require('lodash') | ||
| util = require('./util.js') | ||
| commonHelpers = require("../helpers/common.js").helpers() | ||
| path = require('path') | ||
| generator = {} | ||
| generator.helpers = commonHelpers | ||
| dirname = path.dirname(__filename) | ||
| template = path.resolve(dirname, "tmpl/jaxrsResources.hbs") | ||
| generator.template = fs.readFileSync(template).toString() | ||
| generator.parser = (data) -> | ||
| parsed = [] | ||
| methodParse = [] | ||
| for resource in data.resources | ||
| util.parseResource(resource, methodParse) | ||
| resourceGroup = _.groupBy(methodParse, (method) -> | ||
| method.displayName | ||
| ) | ||
| for k,v of resourceGroup | ||
| model = {} | ||
| model.extra = data.extra if data.extra | ||
| first = _.first(v) | ||
| model.uri = first.uri | ||
| model.className = "#{first.displayName}Resource" | ||
| model.methods = v | ||
| parsed.push {name: model.className + ".groovy" , model} | ||
| parsed | ||
| module.exports = generator |
| fs = require('fs') | ||
| commonHelpers = require("../helpers/common.js").helpers() | ||
| util = require('./util.js') | ||
| path = require('path') | ||
| generator = {} | ||
| generator.helpers = commonHelpers | ||
| dirname = path.dirname(__filename) | ||
| template = path.resolve(dirname, "tmpl/pojo.hbs") | ||
| generator.template = fs.readFileSync(template).toString() | ||
| capitalize = (str)-> | ||
| str.charAt(0).toUpperCase() + str.slice(1) | ||
| generator.parser = (datos) -> | ||
| parsed = [] | ||
| for row in datos.schemas | ||
| for schemaName of row | ||
| data = JSON.parse(row[schemaName]) | ||
| model = {} | ||
| model.className = data.title | ||
| model.classMembers = [] | ||
| model.classDescription = data.description ? "" | ||
| if data.type is "array" | ||
| ref = data.items['$ref'].replace("#/", "").split(".")[0] | ||
| ref = capitalize(ref) | ||
| model.classMembers.push {name: "items", type: "List<#{ref}>"} | ||
| for key of data.properties | ||
| p = data.properties[key] | ||
| model.classMembers.push util.mapProperty(p, key) | ||
| model.extra = datos.extra if datos.extra | ||
| parsed.push {name: capitalize("#{schemaName}.groovy") , model} | ||
| parsed | ||
| module.exports = generator | ||
| fs = require('fs') | ||
| commonHelpers = require("../helpers/common.js").helpers() | ||
| util = require('./util.js') | ||
| path = require('path') | ||
| generator = {} | ||
| generator.helpers = commonHelpers | ||
| dirname = path.dirname(__filename) | ||
| template = path.resolve(dirname, "tmpl/retrofitClient.hbs") | ||
| generator.template = fs.readFileSync(template).toString() | ||
| generator.parser = (data) -> | ||
| parsed = [] | ||
| methodParse = [] | ||
| for resource in data.resources | ||
| util.parseResource(resource, methodParse) | ||
| model = {} | ||
| model.methods = methodParse | ||
| model.extra = data.extra if data.extra | ||
| model.className = data.title.split(" ").join("") | ||
| parsed.push {name: model.className + ".java" , model} | ||
| parsed | ||
| module.exports = generator |
| package {{extra.package}} | ||
| import javax.ws.rs.Consumes | ||
| import javax.ws.rs.GET | ||
| import javax.ws.rs.POST | ||
| import javax.ws.rs.Path | ||
| import javax.ws.rs.PathParam | ||
| import javax.ws.rs.Produces | ||
| import javax.ws.rs.core.Context | ||
| import javax.ws.rs.core.Response | ||
| import javax.ws.rs.core.UriInfo | ||
| {{#if extra.importPojos}} | ||
| import {{extra.importPojos}}.*; | ||
| {{/if}} | ||
| @Path("{{{uri}}}") | ||
| public interface {{className}} { | ||
| {{#methods}} | ||
| /*** | ||
| * @return Response This must be a valid {{{respond}}} JSON object. | ||
| */ | ||
| @{{annotation}} | ||
| public Response {{{name}}}({{#each args}}{{#if @index}}, {{/if}}{{{kind}}} {{type}} {{name}}{{/each}}); | ||
| {{/methods}} | ||
| } |
| package {{extra.package}} | ||
| import groovy.transform.* | ||
| {{#if classDescription}} | ||
| /** | ||
| *{{{classDescription}}} | ||
| **/{{/if}} | ||
| @CompileStatic | ||
| @Canonical | ||
| public class {{{className}}} implements Serializable { | ||
| {{#classMembers}} | ||
| {{#if comment}} /* {{comment}} */{{/if}} | ||
| {{{type}}} {{name}} | ||
| {{/classMembers}} | ||
| } |
| package {{extra.package}}; | ||
| import retrofit.http.Body; | ||
| import retrofit.http.Path; | ||
| import retrofit.http.DELETE; | ||
| import retrofit.http.GET; | ||
| import retrofit.http.POST; | ||
| import retrofit.http.PUT; | ||
| import java.util.List; | ||
| import rx.Observable; | ||
| {{#if extra.importPojos}} | ||
| import {{extra.importPojos}}.*; | ||
| {{/if}} | ||
| public interface {{{className}}} { | ||
| {{#methods}} | ||
| @{{annotation}}("{{{uri}}}") | ||
| public Observable<{{{respond}}}> {{{name}}}({{#each args}}{{#if @index}}, {{/if}}{{{kind}}} {{type}} {{name}}{{/each}}); | ||
| {{/methods}} | ||
| } |
| util = {} | ||
| util.getUriParameter = (resource)-> | ||
| uriParameters = [] | ||
| for key of resource.uriParameters | ||
| p = resource.uriParameters[key] | ||
| uriParameters.push util.mapProperty(p, key) | ||
| uriParameters | ||
| util.mapProperty = (property, name)-> | ||
| p = {} | ||
| p.name = name | ||
| p.comment = property.description | ||
| switch property.type | ||
| when 'array' | ||
| p.type = "List" | ||
| p.name = "items" | ||
| when 'string' then p.type = "String" | ||
| when 'boolean' then p.type = "Boolean" | ||
| when 'number' then p.type = "Double" | ||
| when 'integer' then p.type = "Integer" | ||
| p.kind = "@Path(\"#{p.name}\")" | ||
| p | ||
| util.parseResource = (resource, parsed, parentUri = "", parentUriArgs = []) -> | ||
| # console.log "resource>", resource | ||
| for m in resource.methods | ||
| methodDef = {} | ||
| methodDef.uri = parentUri + resource.relativeUri | ||
| uriArgs = util.getUriParameter(resource) | ||
| methodDef.args = parentUriArgs.concat(uriArgs) | ||
| request = util.parseSchema(m.body, "#{methodDef.uri} body" ) | ||
| respond = util.parseSchema(util.getBestValidResponse(m.responses).body, "#{methodDef.uri} response" ) | ||
| if request.title | ||
| methodDef.args = methodDef.args ? [] | ||
| methodDef.args.push {'kind': '@Body', 'type': request.title, 'name': request.title.toLowerCase()} | ||
| methodDef.request = request.title ? null | ||
| methodDef.respond = if respond.type is "array" then "List<#{respond.title}>" else respond.title | ||
| methodDef.annotation = m.method.toUpperCase() | ||
| methodDef.name = m.method + resource.displayName | ||
| methodDef.displayName = resource.displayName | ||
| parsed.push methodDef | ||
| if resource.resources | ||
| for innerResource in resource.resources | ||
| util.parseResource(innerResource, parsed, resource.relativeUri, uriArgs) | ||
| undefined | ||
| util.parseSchema = (body, meta = '') -> | ||
| schema = {} | ||
| if body and body['application/json'] | ||
| try | ||
| schema = JSON.parse(body['application/json'].schema) | ||
| catch e | ||
| console.log "-----JSON ERROR on #{meta}---------" | ||
| console.log body['application/json'].schema | ||
| throw e | ||
| schema | ||
| util.getBestValidResponse = (responses) -> | ||
| response = responses["304"] ? | ||
| response = responses["204"] ? | ||
| response = responses["201"] ? | ||
| response = responses["200"] ? | ||
| response | ||
| module.exports = util |
| package org.gex | ||
| import javax.ws.rs.Consumes | ||
| import javax.ws.rs.GET | ||
| import javax.ws.rs.POST | ||
| import javax.ws.rs.Path | ||
| import javax.ws.rs.PathParam | ||
| import javax.ws.rs.Produces | ||
| import javax.ws.rs.core.Context | ||
| import javax.ws.rs.core.Response | ||
| import javax.ws.rs.core.UriInfo | ||
| @Path("/cats") | ||
| public interface GatitosResource { | ||
| /*** | ||
| * @return Response This must be a valid List<Cats> JSON object. | ||
| */ | ||
| @GET | ||
| public Response getGatitos(); | ||
| /*** | ||
| * @return Response This must be a valid Cat JSON object. | ||
| */ | ||
| @POST | ||
| public Response postGatitos(@Body Cat cat); | ||
| } |
| var raml2code =require('../..'); | ||
| var path = require('path'); | ||
| var fs = require('fs'); | ||
| var gutil = require('gulp-util'); | ||
| var gen = require("../../lib/generators/groovy/jaxrsInterface"); | ||
| //var gen = require("../../lib/generators/groovy/pojo") | ||
| var wrapAssertion = require("../helpers").wrapAssertion; | ||
| var chai = require('chai'); | ||
| chai.should(); | ||
| describe('RAML to Retrofit client ', function () { | ||
| it('should generate a resource interface from RAML file', function(done) { | ||
| var raml2codeInstance = raml2code({generator:gen, extra: {package: 'org.gex'}}); | ||
| var ramlPath = path.join(__dirname, '../raml/cats.raml'); | ||
| var examplePath = path.join(__dirname, '../examples/GatitosResource.groovy'); | ||
| var ramlContents = fs.readFileSync(ramlPath); | ||
| var exampleContents = fs.readFileSync(examplePath); | ||
| raml2codeInstance.write(new gutil.File({ | ||
| path: ramlPath, | ||
| contents: ramlContents | ||
| })); | ||
| raml2codeInstance.on('data', function(file){ | ||
| var content = file.contents.toString('utf8'); | ||
| //console.log("======="); | ||
| //console.log(content); | ||
| //console.log("=======") | ||
| if(file.path == 'GatitosResource.groovy'){ | ||
| wrapAssertion(function () { | ||
| file.isBuffer().should.equal(true); | ||
| var content = file.contents.toString('utf8'); | ||
| exampleContents = exampleContents.toString('utf8').split('\n'); | ||
| content.split('\n').forEach(function(e,i){ | ||
| e.should.equal(exampleContents[i]); | ||
| }); | ||
| }, done); | ||
| } | ||
| }); | ||
| raml2codeInstance.on('error', function(error) { | ||
| console.log("error", error); | ||
| }); | ||
| }); | ||
| }); |
| var raml2code =require('../..'); | ||
| var path = require('path'); | ||
| var fs = require('fs'); | ||
| var gutil = require('gulp-util'); | ||
| var genDTO = require("../../lib/generators/groovy/pojo") | ||
| var wrapAssertion = require("../helpers").wrapAssertion; | ||
| var chai = require('chai'); | ||
| chai.should(); | ||
| describe('should generate a Groovy Pojo', function () { | ||
| it('DTO from RAML file', function(done) { | ||
| var raml2codeInstance = raml2code({generator:genDTO, extra: {package: 'org.gex'}}); | ||
| var ramlPath = path.join(__dirname, '../raml/cats.raml'); | ||
| var examplePath = path.join(__dirname, '../examples/CatDTO.groovy'); | ||
| var ramlContents = fs.readFileSync(ramlPath); | ||
| var exampleContents = fs.readFileSync(examplePath); | ||
| raml2codeInstance.write(new gutil.File({ | ||
| path: ramlPath, | ||
| contents: ramlContents | ||
| })); | ||
| raml2codeInstance.on('data', function(file){ | ||
| if(file.path == 'Cat.groovy'){ | ||
| wrapAssertion(function () { | ||
| file.isBuffer().should.equal(true); | ||
| var content = file.contents.toString('utf8'); | ||
| //console.log(content); | ||
| exampleContents = exampleContents.toString('utf8').split('\n'); | ||
| content.split('\n').forEach(function(e,i){ | ||
| e.should.equal(exampleContents[i]); | ||
| }); | ||
| }, done); | ||
| } | ||
| }); | ||
| raml2codeInstance.on('error', function(error) { | ||
| console.log("error", error); | ||
| }); | ||
| }); | ||
| }); |
| var raml2code =require('../..'); | ||
| var path = require('path'); | ||
| var fs = require('fs'); | ||
| var gutil = require('gulp-util'); | ||
| var gen = require("../../lib/generators/groovy/retrofitClient") | ||
| var wrapAssertion = require("../helpers").wrapAssertion; | ||
| var chai = require('chai'); | ||
| chai.should(); | ||
| describe('RAML to Retrofit client ', function () { | ||
| it('should generate a retrofit client from RAML file', function(done) { | ||
| var raml2codeInstance = raml2code({generator: gen, extra: {package: 'org.gex.client', importPojos: 'com.pojos'}}); | ||
| var ramlPath = path.join(__dirname, '../raml/cats.raml'); | ||
| var examplePath = path.join(__dirname, '../examples/CatDTO.groovy'); | ||
| var ramlContents = fs.readFileSync(ramlPath); | ||
| var exampleContents = fs.readFileSync(examplePath); | ||
| raml2codeInstance.write(new gutil.File({ | ||
| path: ramlPath, | ||
| contents: ramlContents | ||
| })); | ||
| raml2codeInstance.on('data', function(file){ | ||
| if(file.path == 'GatitosAPI.java'){ | ||
| wrapAssertion(function () { | ||
| file.isBuffer().should.equal(true); | ||
| var content = file.contents.toString('utf8'); | ||
| //console.log(content); | ||
| exampleContents = exampleContents.toString('utf8').split('\n'); | ||
| // content.split('\n').forEach(function(e,i){ | ||
| // e.should.equal(exampleContents[i]); | ||
| // }); | ||
| }, done); | ||
| } | ||
| }); | ||
| raml2codeInstance.on('error', function(error) { | ||
| console.log("error", error); | ||
| }); | ||
| }); | ||
| }); |
+6
-7
| var gulp = require('gulp'); | ||
| var gutil = require('gulp-util'); | ||
| var mocha = require('gulp-mocha'); | ||
| var coffee = require('gulp-coffee'); | ||
| gulp.task('coffee', function() { | ||
| gulp.task('coffee', ['copy-templates'], function() { | ||
| gulp.src('./src/**/*.coffee') | ||
@@ -14,10 +13,9 @@ .pipe(coffee({bare: true}).on('error', gutil.log)) | ||
| gulp.task('copy-templates', function(){ | ||
| gulp.src('./src/**/*.hbs') | ||
| var stream = gulp.src('./src/**/*.hbs') | ||
| .pipe(gulp.dest('./lib/')); | ||
| return stream; | ||
| }); | ||
| gulp.task('test', ['coffee', 'copy-templates'], function(){ | ||
| gulp.src('./test/index.js') | ||
| gulp.task('test', ['coffee', 'copy-templates'], function(cb){ | ||
| gulp.src(['./test/**/*spec.js']) | ||
| .pipe(mocha( | ||
@@ -32,1 +30,2 @@ { | ||
| gulp.task('default', ['test']); |
+11
-10
@@ -11,3 +11,3 @@ var through = require('through2'); | ||
| function processData(fileName, self, callback, options){ | ||
| function processData(fileName, self, callback, options) { | ||
| var raml = require('raml-parser'); | ||
@@ -18,7 +18,7 @@ var cwd = process.cwd(); | ||
| raml.loadFile(fileName.path).then(function (data) { | ||
| if(options && options.generator){ | ||
| if (options && options.generator) { | ||
| data.extra = options.extra; | ||
| options.generator.handleRender = function(results){ | ||
| results.forEach(function(element, index, array){ | ||
| if(element.name && element.content){ | ||
| options.generator.handleRender = function (results) { | ||
| results.forEach(function (element, index, array) { | ||
| if (element.name && element.content) { | ||
| var fileG = new gutil.File({ | ||
@@ -31,3 +31,4 @@ base: "", | ||
| self.push(fileG); | ||
| }else{ | ||
| gutil.log(gutil.colors.cyan('Generating file'), element.name); | ||
| } else { | ||
| self.emit('error', new PluginError(PLUGIN_NAME, 'Data array element must contain name and content properties')); | ||
@@ -39,3 +40,3 @@ } | ||
| data2code.process(data, options.generator); | ||
| }else{ | ||
| } else { | ||
| self.emit('error', new PluginError(PLUGIN_NAME, 'Generator not supplied')); | ||
@@ -54,5 +55,5 @@ } | ||
| module.exports = function(options){ | ||
| module.exports = function (options) { | ||
| var stream = through.obj(function(file, enc, cb) { | ||
| var stream = through.obj(function (file, enc, cb) { | ||
| if (file.isStream()) { | ||
@@ -64,5 +65,5 @@ this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!')); | ||
| return processData(file, this, cb, options); | ||
| } | ||
| } | ||
| }); | ||
| return stream; | ||
| } |
+7
-5
| { | ||
| "name": "raml2code", | ||
| "version": "0.0.2", | ||
| "version": "0.0.4", | ||
| "description": "Raml spec to code", | ||
@@ -30,9 +30,11 @@ "main": "index.js", | ||
| "devDependencies": { | ||
| "gulp": "3.8.7", | ||
| "chai": "^1.9.1", | ||
| "gulp": "3.8.8", | ||
| "gulp-coffee": "2.2.0", | ||
| "gulp-jasmine": "^1.0.1", | ||
| "gulp-mocha": "1.0.0", | ||
| "gulp-util": "3.0.1", | ||
| "gulp-coffee": "2.2.0", | ||
| "gulp-mocha" : "1.0.0", | ||
| "chai": "^1.9.1", | ||
| "lodash": "^2.4.1", | ||
| "mocha": "^1.20.1" | ||
| } | ||
| } |
+6
-11
@@ -19,14 +19,14 @@ # Raml to code generator | ||
| ## generators included | ||
| * raml to DTO groovy | ||
| ## generators included and tested | ||
| * raml to Groovy pojo | ||
| ## As gulp-plugin | ||
| ## Gulp-plugin | ||
| ``` | ||
| var gulp = require('gulp'); | ||
| var data2code = require('raml2code'); | ||
| var gen = require('raml2code/raml2DTO.js') | ||
| var raml2code = require('raml2code'); | ||
| var genDTO = require("raml2code/lib/generators/groovy/raml2DTO.js"); | ||
| gulp.task("test", function(){ | ||
| gulp.src('./test/cats.raml') | ||
| .pipe(data2code({generator:gen})) | ||
| .pipe(raml2code({generator: genDTO, extra: {package:'com.gex'}})) | ||
| .pipe(gulp.dest('build')); | ||
@@ -37,8 +37,3 @@ }); | ||
| ## As command line | ||
| ```bash | ||
| node lib/raml2code.js -i test/cats.raml -g "./generators/groovy/raml2DTO.js" -o target -e '{"package":"gex.dt"}' | ||
| ``` | ||
@@ -12,2 +12,2 @@ module.exports.helpers = -> | ||
| return | ||
| }] | ||
| }] |
+0
-2
@@ -1,3 +0,1 @@ | ||
| function wrapAssertion(fn, done) { | ||
@@ -4,0 +2,0 @@ try { |
+1
-1
@@ -11,3 +11,3 @@ var raml = require('raml-parser'); | ||
| raml.loadFile('/Users/Atoms/workspace/gee/oso/raml2code/test/raml/cats.raml').then( function(data) { | ||
| raml.loadFile('./raml/cats.raml').then( function(data) { | ||
| console.log(data); | ||
@@ -14,0 +14,0 @@ }, function(error) { |
@@ -8,4 +8,6 @@ 'use strict'; | ||
| var fs = require('fs'); | ||
| var wrapAssertion = require("./helpers").wrapAssertion; | ||
| var chai = require('chai'); | ||
| chai.should(); | ||
| describe('raml2code basic test', function () { | ||
@@ -75,5 +77,6 @@ | ||
| raml2codeInstance.on('data', function(file){ | ||
| wrapAssertion(function () { | ||
| file.path.should.equal('test.test'); | ||
| file.contents.toString('utf8').should.equal("Compra venta de gatitos finos"); | ||
| done(); | ||
| file.contents.toString('utf8').should.equal("Gatitos API finos"); | ||
| }, done); | ||
| }); | ||
@@ -80,0 +83,0 @@ |
| package {{extra.package}} | ||
| {{#classMethods.responses}} | ||
| import {{../extra.dtoPackage}}.{{type}}DTO{{/classMethods.responses}} | ||
| public abstract class {{className}} { | ||
| def responseHandlers = [:] | ||
| {{className}}(){ | ||
| {{#classMethods.responses}}responseHandlers.put({{../className}}.Code.{{statusCode}}_{{methodName}}, {data-> new {{type}}DTO(data)}) | ||
| {{/classMethods.responses}} | ||
| } | ||
| public enum Code{ | ||
| {{#classMethods.responses}} | ||
| {{statusCode}}_{{methodName}}({{statusCode}}),{{/classMethods.responses}} | ||
| private final int code; | ||
| Status(final int statusCode){ | ||
| this.code = statusCode | ||
| } | ||
| } | ||
| def handleResponse({{className}}.Code code, data){ | ||
| responseHandlers.get(status)(data) | ||
| } | ||
| {{#classMethods.methods}} | ||
| abstract {{methodName}}(){{/classMethods.methods}} | ||
| } | ||
| package {{extra.package}} | ||
| import groovy.transform.* | ||
| {{#if classDescription}} | ||
| /** | ||
| *{{classDescription}} | ||
| **/{{/if}} | ||
| @CompileStatic | ||
| @Canonical | ||
| public class {{className}} implements Serializable { | ||
| {{#classMembers}} | ||
| {{#if comment}} /* {{comment}} */{{/if}} | ||
| {{type}} {{name}} | ||
| {{/classMembers}} | ||
| } |
| var commonHelpers, fs; | ||
| fs = require('fs'); | ||
| commonHelpers = require("../helpers/common.js").helpers(); | ||
| module.exports.generator = function() { | ||
| var capitalize, generator, parseMethods, parseResource; | ||
| capitalize = function(str) { | ||
| return str.charAt(0).toUpperCase() + str.slice(1); | ||
| }; | ||
| generator = {}; | ||
| generator.helpers = commonHelpers; | ||
| generator.helpers.push({ | ||
| name: "parseSchema", | ||
| fn: function(context, options) { | ||
| var schema; | ||
| schema = JSON.parse(this.schema); | ||
| return options.fn(schema); | ||
| } | ||
| }); | ||
| generator.template = fs.readFileSync(__dirname + "/AbstractResource.hbs").toString(); | ||
| generator.parser = function(data) { | ||
| var p, parsed, r, _i, _j, _len, _len1, _ref; | ||
| parsed = []; | ||
| _ref = data.resources; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| r = _ref[_i]; | ||
| parseResource(r, parsed); | ||
| } | ||
| for (_j = 0, _len1 = parsed.length; _j < _len1; _j++) { | ||
| p = parsed[_j]; | ||
| if (data.extra) { | ||
| p.model.extra = data.extra; | ||
| } | ||
| } | ||
| return parsed; | ||
| }; | ||
| parseMethods = function(methods) { | ||
| var m, methodName, model, rsc, schema, statusCode, _i, _len; | ||
| model = {}; | ||
| model.responses = []; | ||
| model.methods = []; | ||
| for (_i = 0, _len = methods.length; _i < _len; _i++) { | ||
| m = methods[_i]; | ||
| console.log("====", m); | ||
| methodName = m.method; | ||
| for (statusCode in m.responses) { | ||
| console.log('->>>', statusCode); | ||
| rsc = m.responses[statusCode]; | ||
| if (rsc && rsc.body) { | ||
| schema = JSON.parse(rsc.body['application/json'].schema); | ||
| console.log(schema); | ||
| console.log(schema.title); | ||
| model.responses.push({ | ||
| methodName: methodName, | ||
| statusCode: statusCode, | ||
| type: schema.title | ||
| }); | ||
| } | ||
| } | ||
| model.methods.push({ | ||
| methodName: methodName, | ||
| argument: null, | ||
| description: m.description | ||
| }); | ||
| } | ||
| return model; | ||
| }; | ||
| parseResource = function(data, parsed, parentUri) { | ||
| var model, r, _i, _len, _ref, _ref1; | ||
| if (parentUri == null) { | ||
| parentUri = ""; | ||
| } | ||
| model = {}; | ||
| model.className = "" + data.displayName + (capitalize(data.type)) + "AbstractResource"; | ||
| model.classDescription = data.description; | ||
| model.uri = "" + parentUri + data.relativeUri; | ||
| model.relativeUriPathSegments = data.relativeUriPathSegments; | ||
| model.classMethods = parseMethods(data.methods); | ||
| model.classDescription = (_ref = data.description) != null ? _ref : ""; | ||
| if (data.resources) { | ||
| _ref1 = data.resources; | ||
| for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
| r = _ref1[_i]; | ||
| parseResource(r, parsed, model.uri); | ||
| } | ||
| } | ||
| return parsed.push({ | ||
| name: "" + model.className + ".groovy", | ||
| model: model | ||
| }); | ||
| }; | ||
| return generator; | ||
| }; |
| var capitalize, commonHelpers, dirname, fs, generator, path, template; | ||
| fs = require('fs'); | ||
| commonHelpers = require("../helpers/common.js").helpers(); | ||
| path = require('path'); | ||
| generator = {}; | ||
| generator.helpers = commonHelpers; | ||
| dirname = path.dirname(__filename); | ||
| template = path.resolve(dirname, "dto.hbs"); | ||
| console.log("raml2DTO", template); | ||
| generator.template = fs.readFileSync(template).toString(); | ||
| capitalize = function(str) { | ||
| return str.charAt(0).toUpperCase() + str.slice(1); | ||
| }; | ||
| generator.parser = function(datos) { | ||
| var data, key, model, p, parsed, property, ref, row, schemaName, _i, _len, _ref, _ref1; | ||
| parsed = []; | ||
| _ref = datos.schemas; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| row = _ref[_i]; | ||
| for (schemaName in row) { | ||
| data = JSON.parse(row[schemaName]); | ||
| model = {}; | ||
| model.className = data.title; | ||
| model.classMembers = []; | ||
| model.classDescription = (_ref1 = data.description) != null ? _ref1 : ""; | ||
| if (data.type === "array") { | ||
| ref = data.items['$ref'].replace("#/", ""); | ||
| ref = capitalize(ref); | ||
| model.classMembers.push({ | ||
| name: "items", | ||
| type: "List<" + ref + ">" | ||
| }); | ||
| } | ||
| for (key in data.properties) { | ||
| p = data.properties[key]; | ||
| property = {}; | ||
| property.name = key; | ||
| property.comment = p.description; | ||
| switch (p.type) { | ||
| case 'array': | ||
| property.type = "List"; | ||
| property.name = "items"; | ||
| break; | ||
| case 'string': | ||
| property.type = "String"; | ||
| break; | ||
| case 'boolean': | ||
| property.type = "Boolean"; | ||
| break; | ||
| case 'Number': | ||
| property.type = "Double"; | ||
| break; | ||
| case 'integer': | ||
| property.type = "Integer"; | ||
| } | ||
| model.classMembers.push(property); | ||
| } | ||
| if (datos.extra) { | ||
| model.extra = datos.extra; | ||
| } | ||
| parsed.push({ | ||
| name: capitalize("" + schemaName + "DTO.groovy"), | ||
| model: model | ||
| }); | ||
| } | ||
| } | ||
| return parsed; | ||
| }; | ||
| module.exports = generator; |
| var data2code, fs, g, gen, generators, parseExtra, program, raml, writeFile, _i, _len, _ref; | ||
| program = require('commander'); | ||
| data2code = require("./data2code.js"); | ||
| fs = require('fs'); | ||
| raml = require('raml-parser'); | ||
| if (require.main === module) { | ||
| program.usage('[options] [RAML input file]').option('-i, --input [input]', 'RAML input file').option('-g, --generators [generators]', 'Generator modules comma separated').option('-o, --outputDir [outputDir]', 'Output Dir').option('-e, --extra [extra]', "JSON string to be added to model").parse(process.argv); | ||
| if (!(program.input && program.generators && program.outputDir)) { | ||
| console.error("Error: You need to specify all parameters"); | ||
| program.help(); | ||
| process.exit(1); | ||
| } | ||
| generators = []; | ||
| _ref = program.generators.split(","); | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| gen = _ref[_i]; | ||
| g = require(gen); | ||
| g.handleRender = function(results) { | ||
| var result, _j, _len1, _results; | ||
| _results = []; | ||
| for (_j = 0, _len1 = results.length; _j < _len1; _j++) { | ||
| result = results[_j]; | ||
| if (result.name && result.str) { | ||
| _results.push(writeFile("" + program.outputDir + "/" + result.name, result.str)); | ||
| } else { | ||
| _results.push(console.log("no name")); | ||
| } | ||
| } | ||
| return _results; | ||
| }; | ||
| generators.push(g); | ||
| } | ||
| writeFile = function(path, content) { | ||
| return fs.writeFile(path, content, function(err) { | ||
| if (err) { | ||
| console.log(err); | ||
| } else { | ||
| console.log("The file " + path + " was generated!"); | ||
| } | ||
| }); | ||
| }; | ||
| parseExtra = function(str) { | ||
| var data, e; | ||
| data = {}; | ||
| if (str) { | ||
| try { | ||
| data = JSON.parse(program.extra); | ||
| } catch (_error) { | ||
| e = _error; | ||
| console.error(e); | ||
| } | ||
| } | ||
| return data; | ||
| }; | ||
| raml.loadFile(program.input).then((function(data) { | ||
| var _j, _len1; | ||
| data.extra = parseExtra(program.extra); | ||
| for (_j = 0, _len1 = generators.length; _j < _len1; _j++) { | ||
| gen = generators[_j]; | ||
| data2code.process(data, gen); | ||
| } | ||
| }), function(error) { | ||
| console.log("Error parsing: " + error); | ||
| }); | ||
| } |
| package {{extra.package}} | ||
| {{#classMethods.responses}} | ||
| import {{../extra.dtoPackage}}.{{type}}DTO{{/classMethods.responses}} | ||
| public abstract class {{className}} { | ||
| def responseHandlers = [:] | ||
| {{className}}(){ | ||
| {{#classMethods.responses}}responseHandlers.put({{../className}}.Code.{{statusCode}}_{{methodName}}, {data-> new {{type}}DTO(data)}) | ||
| {{/classMethods.responses}} | ||
| } | ||
| public enum Code{ | ||
| {{#classMethods.responses}} | ||
| {{statusCode}}_{{methodName}}({{statusCode}}),{{/classMethods.responses}} | ||
| private final int code; | ||
| Status(final int statusCode){ | ||
| this.code = statusCode | ||
| } | ||
| } | ||
| def handleResponse({{className}}.Code code, data){ | ||
| responseHandlers.get(status)(data) | ||
| } | ||
| {{#classMethods.methods}} | ||
| abstract {{methodName}}(){{/classMethods.methods}} | ||
| } | ||
| package {{extra.package}} | ||
| import groovy.transform.* | ||
| {{#if classDescription}} | ||
| /** | ||
| *{{classDescription}} | ||
| **/{{/if}} | ||
| @CompileStatic | ||
| @Canonical | ||
| public class {{className}} implements Serializable { | ||
| {{#classMembers}} | ||
| {{#if comment}} /* {{comment}} */{{/if}} | ||
| {{type}} {{name}} | ||
| {{/classMembers}} | ||
| } |
| fs = require('fs') | ||
| commonHelpers = require("../helpers/common.js").helpers() | ||
| module.exports.generator = -> | ||
| capitalize = (str)-> | ||
| str.charAt(0).toUpperCase() + str.slice(1) | ||
| generator = {} | ||
| generator.helpers = commonHelpers | ||
| generator.helpers.push { name: "parseSchema", fn: (context, options) -> | ||
| schema = JSON.parse(this.schema) | ||
| return options.fn(schema) | ||
| } | ||
| generator.template = fs.readFileSync(__dirname + "/AbstractResource.hbs").toString() | ||
| generator.parser = (data)-> | ||
| parsed = [] | ||
| for r in data.resources | ||
| parseResource(r, parsed) | ||
| for p in parsed | ||
| p.model.extra = data.extra if data.extra | ||
| parsed | ||
| parseMethods = (methods)-> | ||
| model = {} | ||
| model.responses = [] | ||
| model.methods = [] | ||
| for m in methods | ||
| console.log "====", m | ||
| methodName = m.method | ||
| for statusCode of m.responses | ||
| console.log '->>>', statusCode | ||
| rsc = m.responses[statusCode] | ||
| if rsc and rsc.body | ||
| schema = JSON.parse(rsc.body['application/json'].schema) | ||
| console.log schema | ||
| console.log schema.title | ||
| model.responses.push {methodName, statusCode, type: schema.title} | ||
| model.methods.push {methodName, argument : null, description: m.description} | ||
| model | ||
| parseResource = (data, parsed, parentUri = "")-> | ||
| model = {} | ||
| model.className = "#{data.displayName}#{capitalize(data.type)}AbstractResource" | ||
| model.classDescription = data.description | ||
| model.uri = "#{parentUri}#{data.relativeUri}" | ||
| model.relativeUriPathSegments = data.relativeUriPathSegments | ||
| model.classMethods = parseMethods(data.methods) | ||
| model.classDescription = data.description ? "" | ||
| if data.resources | ||
| for r in data.resources | ||
| parseResource(r, parsed, model.uri) | ||
| parsed.push {name :"#{model.className}.groovy", model} | ||
| generator |
| fs = require('fs') | ||
| commonHelpers = require("../helpers/common.js").helpers() | ||
| path = require('path') | ||
| generator = {} | ||
| generator.helpers = commonHelpers | ||
| dirname = path.dirname(__filename) | ||
| template = path.resolve(dirname, "dto.hbs") | ||
| console.log "raml2DTO", template | ||
| generator.template = fs.readFileSync(template).toString() | ||
| capitalize = (str)-> | ||
| str.charAt(0).toUpperCase() + str.slice(1) | ||
| generator.parser = (datos) -> | ||
| parsed = [] | ||
| for row in datos.schemas | ||
| for schemaName of row | ||
| data = JSON.parse(row[schemaName]) | ||
| model = {} | ||
| model.className = data.title | ||
| model.classMembers = [] | ||
| model.classDescription = data.description ? "" | ||
| if data.type is "array" | ||
| ref = data.items['$ref'].replace("#/", "") | ||
| ref = capitalize(ref) | ||
| model.classMembers.push {name: "items", type: "List<#{ref}>"} | ||
| for key of data.properties | ||
| p = data.properties[key] | ||
| property = {} | ||
| property.name = key | ||
| property.comment = p.description | ||
| switch p.type | ||
| when 'array' | ||
| property.type = "List" | ||
| property.name = "items" | ||
| when 'string' then property.type = "String" | ||
| when 'boolean' then property.type = "Boolean" | ||
| when 'Number' then property.type = "Double" | ||
| when 'integer' then property.type = "Integer" | ||
| model.classMembers.push property | ||
| model.extra = datos.extra if datos.extra | ||
| parsed.push {name: capitalize("#{schemaName}DTO.groovy") , model} | ||
| parsed | ||
| module.exports = generator | ||
| program = require('commander') | ||
| data2code = require("./data2code.js") | ||
| fs = require('fs') | ||
| raml = require('raml-parser') | ||
| if require.main is module | ||
| program | ||
| .usage('[options] [RAML input file]') | ||
| .option('-i, --input [input]', 'RAML input file') | ||
| .option('-g, --generators [generators]', 'Generator modules comma separated') | ||
| .option('-o, --outputDir [outputDir]', 'Output Dir') | ||
| .option('-e, --extra [extra]', "JSON string to be added to model") | ||
| .parse(process.argv) | ||
| if not (program.input and program.generators and program.outputDir) | ||
| console.error "Error: You need to specify all parameters" | ||
| program.help() | ||
| process.exit(1) | ||
| generators = [] | ||
| for gen in program.generators.split(",") | ||
| g = require(gen) | ||
| g.handleRender = (results)-> | ||
| for result in results | ||
| if result.name and result.str | ||
| writeFile("#{program.outputDir}/#{result.name}", result.str) | ||
| else | ||
| console.log "no name" | ||
| generators.push g | ||
| writeFile = (path, content) -> | ||
| fs.writeFile path, content, (err) -> | ||
| if err | ||
| console.log err | ||
| else | ||
| console.log "The file #{path} was generated!" | ||
| return | ||
| parseExtra = (str)-> | ||
| data = {} | ||
| if str | ||
| try | ||
| data = JSON.parse(program.extra) | ||
| catch e | ||
| console.error e | ||
| return data | ||
| raml.loadFile(program.input).then ((data) -> | ||
| data.extra = parseExtra(program.extra) | ||
| for gen in generators | ||
| data2code.process(data, gen) | ||
| return | ||
| ), (error) -> | ||
| console.log "Error parsing: " + error | ||
| return | ||
| var raml2code =require('../..'); | ||
| var path = require('path'); | ||
| var fs = require('fs'); | ||
| var gutil = require('gulp-util'); | ||
| var genDTO = require("../../lib/generators/groovy/raml2DTO") | ||
| var wrapAssertion = require("../helpers").wrapAssertion; | ||
| console.log(wrapAssertion); | ||
| describe('RAML to Groovy ', function () { | ||
| it('DTO from RAML file', function(done) { | ||
| var raml2codeInstance = raml2code({generator:genDTO, extra: {package: 'org.gex'}}); | ||
| var ramlPath = path.join(__dirname, '../raml/cats.raml'); | ||
| var examplePath = path.join(__dirname, '../examples/CatDTO.groovy'); | ||
| var ramlContents = fs.readFileSync(ramlPath); | ||
| var exampleContents = fs.readFileSync(examplePath); | ||
| raml2codeInstance.write(new gutil.File({ | ||
| path: ramlPath, | ||
| contents: ramlContents | ||
| })); | ||
| raml2codeInstance.on('data', function(file){ | ||
| console.log(file.path); | ||
| if(file.path == 'CatDTO.groovy'){ | ||
| wrapAssertion(function () { | ||
| file.isBuffer().should.equal(true); | ||
| var content = file.contents.toString('utf8'); | ||
| console.log("-----"); | ||
| console.log(content); | ||
| console.log("-----"); | ||
| exampleContents = exampleContents.toString('utf8').split('\n'); | ||
| content.split('\n').forEach(function(e,i){ | ||
| e.should.equal(exampleContents[i]); | ||
| }); | ||
| }, done); | ||
| } | ||
| }); | ||
| raml2codeInstance.on('error', function(error) { | ||
| console.log("error", error); | ||
| }); | ||
| }); | ||
| }); |
| 'use strict'; | ||
| var Mocha = require('mocha'); | ||
| var chai = require('chai'); | ||
| var mocha = new Mocha(); | ||
| mocha.addFile(__dirname + '/raml2Code-spec'); | ||
| mocha.addFile(__dirname + '/groovy/dto-spec'); | ||
| chai.should(); | ||
| mocha.run(); |
| package {{extra.package}} | ||
| {{debug}} | ||
| class {{displayName}} implements Serializable { | ||
| {{#methods}} | ||
| {{method}} | ||
| {{#if responses}} | ||
| {{#each responses}} | ||
| {{#if this.body}} | ||
| {{@key}} | ||
| {{#each this.body}} | ||
| {{#if this.schema}} | ||
| {{#parseSchema this.schema}} | ||
| {{#each properties}} | ||
| {{@key}} {{this.type}} | ||
| {{/each}} | ||
| {{/parseSchema}} | ||
| {{/if}} | ||
| {{/each}} | ||
| {{/if}} | ||
| {{/each}} | ||
| {{/if}} | ||
| {{/methods}} | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
31983
13.95%34
17.24%574
13.89%8
33.33%38
-11.63%8
33.33%1
Infinity%