| var arrayFromMask, commonHelpers, customAdapter, generator, parseResource, resolveArrayByMask, utilSchemas, utilText, _; | ||
| commonHelpers = require("../helpers/common").helpers(); | ||
| utilSchemas = require('../util/schemas'); | ||
| utilText = require('../util/text'); | ||
| parseResource = require('../util/parseResource'); | ||
| _ = require('lodash'); | ||
| generator = {}; | ||
| generator.helpers = commonHelpers; | ||
| generator.template = require("./tmpl/retrofitClient.hbs"); | ||
| customAdapter = function(method, methodParsed) { | ||
| var mediaType; | ||
| if (methodParsed.formData) { | ||
| methodParsed.additionalAnnotation = "Multipart"; | ||
| } | ||
| if (methodParsed.formEncoded) { | ||
| methodParsed.additionalAnnotation = "FormUrlEncoded"; | ||
| } | ||
| mediaType = "application/json"; | ||
| if (method.body && Object.keys(method.body)[0]) { | ||
| mediaType = Object.keys(method.body)[0]; | ||
| } | ||
| if (methodParsed.annotation === "DELETE") { | ||
| return methodParsed.additionalAnnotation = "Headers({\"Content-type: " + mediaType + "\"})"; | ||
| } | ||
| }; | ||
| generator.parser = function(data) { | ||
| var arg, d, method, methodParse, methodParsePermuted, model, name, newArgs, notReqArgs, options, parsed, permutations, permuted, reqArgs, resource, schemas, shallowMethod, _i, _j, _k, _len, _len1, _len2, _ref; | ||
| parsed = []; | ||
| schemas = utilSchemas.loadSchemas(data); | ||
| options = { | ||
| annotations: { | ||
| path: "@Path", | ||
| query: "@Query", | ||
| body: "@Body", | ||
| multiPart: "@Part", | ||
| form: "@Field" | ||
| }, | ||
| mapping: { | ||
| 'string': "String", | ||
| 'boolean': "Boolean", | ||
| 'number': "BigDecimal", | ||
| 'integer': "Long", | ||
| 'array': "List", | ||
| 'object': "Map", | ||
| 'file': "TypedFile" | ||
| } | ||
| }; | ||
| methodParse = []; | ||
| _ref = data.resources; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| resource = _ref[_i]; | ||
| methodParse.push(parseResource(resource, options, schemas, customAdapter)); | ||
| } | ||
| methodParse = _.flatten(methodParse); | ||
| methodParsePermuted = []; | ||
| for (_j = 0, _len1 = methodParse.length; _j < _len1; _j++) { | ||
| method = methodParse[_j]; | ||
| notReqArgs = _.filter(method.args, function(it) { | ||
| return it.required === false; | ||
| }); | ||
| if (notReqArgs && notReqArgs.length > 0) { | ||
| reqArgs = _.difference(method.args, notReqArgs); | ||
| permutations = (2 * notReqArgs.length) - 1; | ||
| while (permutations >= 0) { | ||
| shallowMethod = _.cloneDeep(method); | ||
| d = arrayFromMask(permutations); | ||
| permuted = resolveArrayByMask(d, notReqArgs); | ||
| name = shallowMethod.name; | ||
| for (_k = 0, _len2 = permuted.length; _k < _len2; _k++) { | ||
| arg = permuted[_k]; | ||
| name = name + ("And" + (utilText.capitalize(arg.name))); | ||
| } | ||
| newArgs = reqArgs.concat(permuted); | ||
| shallowMethod.args = newArgs; | ||
| shallowMethod.name = name; | ||
| methodParsePermuted.push(shallowMethod); | ||
| permutations--; | ||
| } | ||
| } else { | ||
| methodParsePermuted.push(method); | ||
| } | ||
| } | ||
| model = {}; | ||
| model.methods = methodParsePermuted; | ||
| model.version = data.version; | ||
| if (data.extra) { | ||
| data.extra["package"] = "" + data.extra["package"] + "." + data.version; | ||
| data.extra.importPojos = "" + data.extra.importPojos + "." + data.version; | ||
| model.extra = data.extra; | ||
| } | ||
| model.className = data.title.split(" ").join(""); | ||
| parsed.push({ | ||
| name: "" + data.version + "/" + model.className + ".java", | ||
| model: model | ||
| }); | ||
| return parsed; | ||
| }; | ||
| arrayFromMask = function(nMask) { | ||
| var aFromMask, nShifted; | ||
| if (nMask > 0x7fffffff || nMask < -0x80000000) { | ||
| throw new TypeError("arrayFromMask - out of range"); | ||
| } | ||
| nShifted = nMask; | ||
| aFromMask = []; | ||
| while (nShifted) { | ||
| aFromMask.push(Boolean(nShifted & 1)); | ||
| nShifted >>>= 1; | ||
| } | ||
| return aFromMask; | ||
| }; | ||
| resolveArrayByMask = function(mask, array) { | ||
| var i, j, res; | ||
| res = []; | ||
| i = array.length - 1; | ||
| j = 0; | ||
| while (i >= 0) { | ||
| if (mask[j]) { | ||
| res.push(array[i]); | ||
| } | ||
| i--; | ||
| j++; | ||
| } | ||
| return res; | ||
| }; | ||
| module.exports = generator; |
| package {{extra.package}}; | ||
| import retrofit.http.*; | ||
| import retrofit.client.Response; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import rx.Observable; | ||
| import retrofit.mime.TypedFile; | ||
| {{#if extra.importPojos}} | ||
| import {{extra.importPojos}}.*; | ||
| {{/if}} | ||
| public interface {{{className}}} { | ||
| {{#methods}} | ||
| @{{annotation}}("/{{{../version}}}{{{uri}}}") | ||
| {{#if additionalAnnotation}} | ||
| @{{{additionalAnnotation}}} | ||
| {{/if}} | ||
| Observable<{{{respond}}}> {{{name}}}({{#each args}}{{#if @index}},{{/if}} | ||
| {{{kind}}} {{{type}}} {{name}}{{/each}}); | ||
| {{/methods}} | ||
| } |
| var camelCase, context, defaultHelpers, extend, generator, helpers, languages; | ||
| extend = require('raml-client-generator/node_modules/extend'); | ||
| languages = require('raml-client-generator/languages'); | ||
| context = require('raml-client-generator/lib/compile/context'); | ||
| defaultHelpers = require('raml-client-generator/lib/compile/helpers'); | ||
| generator = {}; | ||
| generator.partials = { | ||
| auth: require('raml-client-generator/languages/javascript/partials/auth.js.hbs'), | ||
| utils: require('raml-client-generator/languages/javascript/partials/utils.js.hbs'), | ||
| client: require('raml-client-generator/languages/javascript/partials/client.js.hbs'), | ||
| resources: require('raml-client-generator/languages/javascript/partials/resources.js.hbs') | ||
| }; | ||
| helpers = { | ||
| stringify: require('raml-client-generator/node_modules/javascript-stringify'), | ||
| dependencies: require('raml-client-generator/languages/javascript/helpers/dependencies'), | ||
| requestSnippet: require('raml-client-generator/languages/javascript/helpers/request-snippet'), | ||
| parametersSnippet: require('raml-client-generator/languages/javascript/helpers/parameters-snippet') | ||
| }; | ||
| generator.helpers = extend({}, defaultHelpers, helpers); | ||
| generator.template = require('raml-client-generator/languages/javascript//templates/index.js.hbs'); | ||
| camelCase = require('raml-client-generator/node_modules/camel-case'); | ||
| generator.parser = function(data) { | ||
| var model, parsed, spec; | ||
| parsed = []; | ||
| spec = { | ||
| format: { | ||
| variable: camelCase | ||
| } | ||
| }; | ||
| model = context(data, spec); | ||
| parsed.push({ | ||
| name: model.version + ("/" + (camelCase(model.title)) + "Client.js"), | ||
| model: model | ||
| }); | ||
| return parsed; | ||
| }; | ||
| module.exports = generator; |
| ## 0.8.38 | ||
| Changing Versioning, adding support to generate a js client | ||
| - Moving retrofit client to src/generators/java this could break some already setup projects | ||
| - Now it generates jsClient it uses [raml-client-generator](https://github.com/mulesoft/raml-client-generator) | ||
| - Updating data2code to 0.0.3 | ||
| ## 0.0.37 | ||
| Adding support to optional properties for retrofit client, now it generates a permutations of the methods with the optional arguments | ||
| - Refactor on util.js | ||
| - Some test where change to support the new properties |
+0
-1
| language: node_js | ||
| node_js: | ||
| - "0.11" | ||
| - "0.10" | ||
@@ -5,0 +4,0 @@ before_script: |
+6
-1
@@ -32,3 +32,8 @@ var through = require('through2'); | ||
| } | ||
| data2code.process(data, options.generator); | ||
| try{ | ||
| data2code.process(data, options.generator); | ||
| }catch(e){ | ||
| self.emit('error', new PluginError(PLUGIN_NAME,e)); | ||
| } | ||
| } else { | ||
@@ -35,0 +40,0 @@ self.emit('error', new PluginError(PLUGIN_NAME, 'Generator not supplied')); |
@@ -1,5 +0,3 @@ | ||
| var commonHelpers, customAdapter, dirname, fs, generator, parseResource, path, template, utilSchemas, _; | ||
| var commonHelpers, customAdapter, generator, parseResource, utilSchemas, _; | ||
| fs = require('fs'); | ||
| _ = require('lodash'); | ||
@@ -13,4 +11,2 @@ | ||
| path = require('path'); | ||
| generator = {}; | ||
@@ -20,8 +16,4 @@ | ||
| dirname = path.dirname(__filename); | ||
| generator.template = require("./tmpl/jaxrsResources.hbs"); | ||
| template = path.resolve(dirname, "tmpl/jaxrsResources.hbs"); | ||
| generator.template = fs.readFileSync(template).toString(); | ||
| customAdapter = function(method, methodParsed) { | ||
@@ -28,0 +20,0 @@ if (methodParsed.formData) { |
@@ -1,9 +0,5 @@ | ||
| var cmPartial, commonHelpers, deref, dirname, fs, generator, path, template, utilMapProperty, utilSchemas, utilText; | ||
| var commonHelpers, deref, generator, utilMapProperty, utilSchemas, utilText; | ||
| fs = require('fs'); | ||
| commonHelpers = require("../helpers/common").helpers(); | ||
| path = require('path'); | ||
| utilText = require('../util/text'); | ||
@@ -19,17 +15,8 @@ | ||
| dirname = path.dirname(__filename); | ||
| generator.template = require("./tmpl/pojo.hbs"); | ||
| template = path.resolve(dirname, "tmpl/pojo.hbs"); | ||
| generator.partials = { | ||
| classMembers: require("./tmpl/classMembersPartial.hbs") | ||
| }; | ||
| cmPartial = path.resolve(dirname, "tmpl/classMembersPartial.hbs"); | ||
| generator.template = fs.readFileSync(template).toString(); | ||
| generator.partials = [ | ||
| { | ||
| name: "classMembers", | ||
| str: fs.readFileSync(cmPartial).toString() | ||
| } | ||
| ]; | ||
| deref = require('deref')(); | ||
@@ -36,0 +23,0 @@ |
+11
-8
| { | ||
| "name": "raml2code", | ||
| "version": "0.0.37", | ||
| "version": "0.8.38", | ||
| "description": "Raml spec to code", | ||
@@ -22,10 +22,13 @@ "main": "index.js", | ||
| }, | ||
| "homepage": "https://github.com/gextech/raml2code", | ||
| "homepage": | ||
| "https://github.com/gextech/raml2code", | ||
| "dependencies": { | ||
| "data2code": "~0.0.1", | ||
| "gulp-util": "~3.0.1", | ||
| "raml-parser": "~0.8.7", | ||
| "through2": "~0.6.3", | ||
| "lodash": "^2.4.1", | ||
| "deref": "0.2.6" | ||
| "data2code": "0.0.3", | ||
| "gulp-util": "3.0.1", | ||
| "raml-parser": "0.8.7", | ||
| "through2": "0.6.3", | ||
| "lodash": "2.4.1", | ||
| "deref": "0.2.6", | ||
| "raml-client-generator" : "0.0.6" | ||
| }, | ||
@@ -32,0 +35,0 @@ "devDependencies": { |
+36
-7
| # Raml to code generator | ||
| [](https://travis-ci.org/gextech/raml2code) | ||
| [](https://travis-ci.org/gextech/raml2code) | ||
| ## Versioning | ||
| The raml2code generator is versioned in the following manner: | ||
| ``` | ||
| x.y.z | ||
| ``` | ||
| in which *x.y* denotes the version of the [RAML specification](http://raml.org/spec.html) | ||
| and *z* is the version of the raml2code. | ||
| So *0.8.38* is the 38nd revision of the ralm2code for the *0.8* version | ||
| of the [RAML specification](http://raml.org/spec.html). | ||
| * This module generate code from a RAML definition | ||
| * It uses Handlebars templates | ||
| ## It must be defined as Gulp-plugin | ||
| ## It's a Gulp-plugin | ||
| ```js | ||
@@ -98,8 +111,24 @@ var gulp = require('gulp'); | ||
| * 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 | ||
| This generator use json-schema spec heavily, when using $ref certain rules apply: | ||
| * If the json schema has $ref and the schema referred has title we will use it to make a reference. For | ||
| example the property owner on: | ||
| [cat.schema.json](src/test/raml/cat.schema.json) | ||
| it will result on the property Owner in [CatDTO.groovy](src/test/examples/CatDTO.groovy) | ||
| * if the json schema has a property of type object like food on : | ||
| [cat.schema.json](src/test/raml/cat.schema.json) | ||
| it will result on a inner class called Food in [CatDTO.groovy](src/test/examples/CatDTO.groovy) | ||
| More info on $ref definitions, http://json-schema.org/latest/json-schema-core.html#anchor30 | ||
| * JAX-RS Interface | ||
| * RETROFIT Client | ||
| We use the optional resource.displayName to name resource classes, if you use this generator don't forget to provide it. | ||
| Example: | ||
| ```groovy | ||
| /cats: | ||
| displayName: Gatitos | ||
| ``` | ||
| Will generate GatitosResource | ||
| * RETROFIT Client java interface | ||
| * raml-client-generator javascript client generator from mulesoft | ||
| [raml-client-generator](https://github.com/mulesoft/raml-client-generator) | ||
@@ -106,0 +135,0 @@ |
| var arrayFromMask, commonHelpers, customAdapter, dirname, fs, generator, parseResource, path, resolveArrayByMask, template, utilSchemas, utilText, _; | ||
| fs = require('fs'); | ||
| commonHelpers = require("../helpers/common").helpers(); | ||
| utilSchemas = require('../util/schemas'); | ||
| utilText = require('../util/text'); | ||
| parseResource = require('../util/parseResource'); | ||
| path = require('path'); | ||
| _ = require('lodash'); | ||
| generator = {}; | ||
| generator.helpers = commonHelpers; | ||
| dirname = path.dirname(__filename); | ||
| template = path.resolve(dirname, "tmpl/retrofitClient.hbs"); | ||
| generator.template = fs.readFileSync(template).toString(); | ||
| customAdapter = function(method, methodParsed) { | ||
| var mediaType; | ||
| if (methodParsed.formData) { | ||
| methodParsed.additionalAnnotation = "Multipart"; | ||
| } | ||
| if (methodParsed.formEncoded) { | ||
| methodParsed.additionalAnnotation = "FormUrlEncoded"; | ||
| } | ||
| mediaType = "application/json"; | ||
| if (method.body && Object.keys(method.body)[0]) { | ||
| mediaType = Object.keys(method.body)[0]; | ||
| } | ||
| if (methodParsed.annotation === "DELETE") { | ||
| return methodParsed.additionalAnnotation = "Headers({\"Content-type: " + mediaType + "\"})"; | ||
| } | ||
| }; | ||
| generator.parser = function(data) { | ||
| var arg, d, method, methodParse, methodParsePermuted, model, name, newArgs, notReqArgs, options, parsed, permutations, permuted, reqArgs, resource, schemas, shallowMethod, _i, _j, _k, _len, _len1, _len2, _ref; | ||
| parsed = []; | ||
| schemas = utilSchemas.loadSchemas(data); | ||
| options = { | ||
| annotations: { | ||
| path: "@Path", | ||
| query: "@Query", | ||
| body: "@Body", | ||
| multiPart: "@Part", | ||
| form: "@Field" | ||
| }, | ||
| mapping: { | ||
| 'string': "String", | ||
| 'boolean': "Boolean", | ||
| 'number': "BigDecimal", | ||
| 'integer': "Long", | ||
| 'array': "List", | ||
| 'object': "Map", | ||
| 'file': "TypedFile" | ||
| } | ||
| }; | ||
| methodParse = []; | ||
| _ref = data.resources; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| resource = _ref[_i]; | ||
| methodParse.push(parseResource(resource, options, schemas, customAdapter)); | ||
| } | ||
| methodParse = _.flatten(methodParse); | ||
| methodParsePermuted = []; | ||
| for (_j = 0, _len1 = methodParse.length; _j < _len1; _j++) { | ||
| method = methodParse[_j]; | ||
| notReqArgs = _.filter(method.args, function(it) { | ||
| return it.required === false; | ||
| }); | ||
| if (notReqArgs && notReqArgs.length > 0) { | ||
| reqArgs = _.difference(method.args, notReqArgs); | ||
| permutations = (2 * notReqArgs.length) - 1; | ||
| while (permutations >= 0) { | ||
| shallowMethod = _.cloneDeep(method); | ||
| d = arrayFromMask(permutations); | ||
| permuted = resolveArrayByMask(d, notReqArgs); | ||
| name = shallowMethod.name; | ||
| for (_k = 0, _len2 = permuted.length; _k < _len2; _k++) { | ||
| arg = permuted[_k]; | ||
| name = name + ("And" + (utilText.capitalize(arg.name))); | ||
| } | ||
| newArgs = reqArgs.concat(permuted); | ||
| shallowMethod.args = newArgs; | ||
| shallowMethod.name = name; | ||
| methodParsePermuted.push(shallowMethod); | ||
| permutations--; | ||
| } | ||
| } else { | ||
| methodParsePermuted.push(method); | ||
| } | ||
| } | ||
| model = {}; | ||
| model.methods = methodParsePermuted; | ||
| model.version = data.version; | ||
| if (data.extra) { | ||
| data.extra["package"] = "" + data.extra["package"] + "." + data.version; | ||
| data.extra.importPojos = "" + data.extra.importPojos + "." + data.version; | ||
| model.extra = data.extra; | ||
| } | ||
| model.className = data.title.split(" ").join(""); | ||
| parsed.push({ | ||
| name: "" + data.version + "/" + model.className + ".java", | ||
| model: model | ||
| }); | ||
| return parsed; | ||
| }; | ||
| arrayFromMask = function(nMask) { | ||
| var aFromMask, nShifted; | ||
| if (nMask > 0x7fffffff || nMask < -0x80000000) { | ||
| throw new TypeError("arrayFromMask - out of range"); | ||
| } | ||
| nShifted = nMask; | ||
| aFromMask = []; | ||
| while (nShifted) { | ||
| aFromMask.push(Boolean(nShifted & 1)); | ||
| nShifted >>>= 1; | ||
| } | ||
| return aFromMask; | ||
| }; | ||
| resolveArrayByMask = function(mask, array) { | ||
| var i, j, res; | ||
| res = []; | ||
| i = array.length - 1; | ||
| j = 0; | ||
| while (i >= 0) { | ||
| if (mask[j]) { | ||
| res.push(array[i]); | ||
| } | ||
| i--; | ||
| j++; | ||
| } | ||
| return res; | ||
| }; | ||
| module.exports = generator; |
| package {{extra.package}}; | ||
| import retrofit.http.*; | ||
| import retrofit.client.Response; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import rx.Observable; | ||
| import retrofit.mime.TypedFile; | ||
| {{#if extra.importPojos}} | ||
| import {{extra.importPojos}}.*; | ||
| {{/if}} | ||
| public interface {{{className}}} { | ||
| {{#methods}} | ||
| @{{annotation}}("/{{{../version}}}{{{uri}}}") | ||
| {{#if additionalAnnotation}} | ||
| @{{{additionalAnnotation}}} | ||
| {{/if}} | ||
| Observable<{{{respond}}}> {{{name}}}({{#each args}}{{#if @index}},{{/if}} | ||
| {{{kind}}} {{{type}}} {{name}}{{/each}}); | ||
| {{/methods}} | ||
| } |
| var test = require("../helpers").test; | ||
| var chai = require('chai'); | ||
| chai.should(); | ||
| describe('RAML to JAX-RS', function () { | ||
| var generator = require("../../lib/generators/groovy/jaxrsInterface"); | ||
| var gatitosResource = function (done) { | ||
| test(generator, done, {package: 'org.gex', importPojos: 'org.gex.dto'}, "GatitosResource.groovy", "v1/GatitosResource.groovy") | ||
| }; | ||
| var gatitoByIdResource = function (done) { | ||
| test(generator, done, {package: 'org.gex', importPojos: 'org.gex.dto'}, "GatitoByIdResource.groovy", "v1/GatitoByIdResource.groovy") | ||
| }; | ||
| var gatitoByIdPictureResource = function (done) { | ||
| test(generator, done, {package: 'org.gex', importPojos: 'org.gex.dto'}, "GatitoByIdPictureResource.groovy", "v1/GatitoByIdPictureResource.groovy") | ||
| }; | ||
| var gatitopByIdFormResource = function (done) { | ||
| test(generator, done, {package: 'org.gex', importPojos: 'org.gex.dto'}, "GatitopByIdFormResource.groovy", "v1/GatitopByIdFormResource.groovy") | ||
| }; | ||
| var settingsResource = function (done) { | ||
| test(generator, done, {package: 'org.gex', importPojos: 'org.gex.dto'}, "SettingsResource.groovy", "v1/SettingsResource.groovy") | ||
| }; | ||
| var arrayPrimitivesResource = function (done) { | ||
| test(generator, done, {package: 'org.gex', importPojos: 'org.gex.dto'}, "ArrayPrimitivesResource.groovy", "v1/ArrayPrimitivesResource.groovy") | ||
| }; | ||
| it('should generate a resource interface', gatitosResource); | ||
| it('should generate a resourceById interface', gatitoByIdResource); | ||
| it('should generate a GatitoByIdPictureResource upload interface', gatitoByIdPictureResource); | ||
| it('should generate a GatitopByIdFormResource upload interface', gatitopByIdFormResource); | ||
| it('should generate a SettingsResource', settingsResource); | ||
| it('should generate a SettingsResource', arrayPrimitivesResource); | ||
| }); |
| var test = require("../helpers").test; | ||
| var chai = require('chai'); | ||
| chai.should(); | ||
| describe('should generate a Pojo', function () { | ||
| var generator = require("../../lib/generators/groovy/pojo"); | ||
| var catDTO = function(done){ | ||
| test(generator, done, {package: 'org.gex', enableAnnotations: false}, "CatDTO.groovy" , "v1/Cat.groovy") | ||
| }; | ||
| var catDTOJSR303 = function(done){ | ||
| test(generator, done, {package: 'org.gex'}, "CatDTOJSR303.groovy", "v1/Cat.groovy") | ||
| }; | ||
| var widgetDTOInlineRef = function(done){ | ||
| test(generator, done, {package: 'org.gex'}, "WidgetInline.groovy", "v1/Widget.groovy") | ||
| }; | ||
| var widgetDTOInlinePropertyRef = function(done){ | ||
| test(generator, done, {package: 'org.gex'}, "WidgetInlineProperty.groovy", "v1/WidgetInlineProperty.groovy") | ||
| }; | ||
| it('from a RAML file', catDTO ); | ||
| it('from a RAML file with bean validation', catDTOJSR303 ); | ||
| it('from a Schema with inline ref', widgetDTOInlineRef ); | ||
| it('from a Schema with inline Property ref', widgetDTOInlinePropertyRef ); | ||
| }); |
| var test = require("../helpers").test; | ||
| var chai = require('chai'); | ||
| chai.should(); | ||
| describe('RAML to Retrofit client ', function () { | ||
| var generator = require("../../lib/generators/groovy/retrofitClient"); | ||
| var gatitosAPI = function(done){ | ||
| test(generator, done, {package: 'org.gex.client', importPojos: 'com.pojos'}, "GatitosAPI.java", "v1/GatitosAPI.java") | ||
| }; | ||
| it('should generate a retrofit client from RAML file', gatitosAPI ); | ||
| }); |
| var path = require('path'); | ||
| var fs = require('fs'); | ||
| var raml2code = require('..'); | ||
| var gutil = require('gulp-util'); | ||
| var helpers = {}; | ||
| helpers.wrapAssertion= function(fn, done) { | ||
| try { | ||
| fn(); | ||
| done(); | ||
| } catch (e) { | ||
| done(e); | ||
| } | ||
| }; | ||
| helpers.test = function (generator, done, extra, sampleFile, validateWith, logContent ) { | ||
| logContent = logContent || false; | ||
| var raml2codeInstance = raml2code({generator: generator, extra: extra}); | ||
| var ramlPath = path.join(__dirname, './raml/cats.raml'); | ||
| var examplePath = path.join(__dirname, "./examples/" + sampleFile); | ||
| 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 == validateWith) { | ||
| helpers.wrapAssertion(function () { | ||
| file.isBuffer().should.equal(true); | ||
| var content = file.contents.toString('utf8'); | ||
| if(logContent){ | ||
| console.log("=================" + file.path + "================") | ||
| console.log(content); | ||
| console.log("==================================================") | ||
| } | ||
| exampleContents = exampleContents.toString('utf8').split('\n'); | ||
| content.split('\n').forEach(function (e, i) { | ||
| e.trim().should.equal(exampleContents[i].trim(), "In line " + i + " " + sampleFile + " " + validateWith); | ||
| }); | ||
| }, done); | ||
| } | ||
| }); | ||
| raml2codeInstance.on('error', function (error) { | ||
| console.log("error", error); | ||
| }); | ||
| }; | ||
| module.exports = helpers; |
| { | ||
| "id": 123, | ||
| "name": "hola", | ||
| "errors": [ | ||
| { | ||
| "code": "500", | ||
| "messages": "Error", | ||
| "status": 200 | ||
| } | ||
| ] | ||
| } |
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Cat", | ||
| "id": "cat.schema.json", | ||
| "description": "A cat from Atoms catalog", | ||
| "type": "object", | ||
| "properties": { | ||
| "id": { | ||
| "description": "The unique identifier for a cat", | ||
| "type": "integer" | ||
| }, | ||
| "name": { | ||
| "description": "Name of the cat", | ||
| "type": "string", | ||
| "minLength": 5, | ||
| "maxLength": 20 | ||
| }, | ||
| "toy": { | ||
| "description": "Something to play", | ||
| "type": "object" | ||
| }, | ||
| "friends": { | ||
| "description": "friends", | ||
| "$ref": "genericArray.schema.json" | ||
| }, | ||
| "sings": { | ||
| "description": "characteristics", | ||
| "$ref": "genericMap.schema.json" | ||
| }, | ||
| "age": { | ||
| "description": "The age of the cat", | ||
| "type": "integer", | ||
| "minimum": 1, | ||
| "maximum": 15 | ||
| }, | ||
| "weight": { | ||
| "description": "The weight of the cat", | ||
| "type": "number", | ||
| "minimum": ".1", | ||
| "maximum": "10.00" | ||
| }, | ||
| "food": { | ||
| "description": "Something to eat", | ||
| "type": "object", | ||
| "title": "food", | ||
| "properties": { | ||
| "name": { | ||
| "description": "what the cat eats", | ||
| "type": "string" | ||
| } | ||
| } | ||
| }, | ||
| "owner": { | ||
| "type": "object", | ||
| "description": "The owner of the cat.", | ||
| "$ref": "owner.schema.json" | ||
| }, | ||
| "errors": { | ||
| "title": "Errors", | ||
| "description": "Errores al procesar la petición", | ||
| "type": "array", | ||
| "items": {"$ref": "error/error.schema.json"} | ||
| } | ||
| }, | ||
| "required": [ | ||
| "id", | ||
| "name", | ||
| "errors" | ||
| ] | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Cats", | ||
| "description": "A cats collection", | ||
| "type": "object", | ||
| "properties": { | ||
| "cats" : { | ||
| "title": "Cats", | ||
| "description": "A lot of cats", | ||
| "type": "array", | ||
| "items": { "$ref": "cat.schema.json" } | ||
| } | ||
| } | ||
| } |
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Error", | ||
| "id": "error.schema.json", | ||
| "description": "A server error", | ||
| "type": "object", | ||
| "properties": { | ||
| "code": {"type": "string"}, | ||
| "messages": {"type": "string"}, | ||
| "status": {"type": "integer"} | ||
| }, | ||
| "required": [ | ||
| "code", | ||
| "messages", | ||
| "status" | ||
| ] | ||
| } |
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Error", | ||
| "id": "error/error.schema.json", | ||
| "description": "A server error", | ||
| "type": "object", | ||
| "properties": { | ||
| "code": {"type": "string"}, | ||
| "messages": {"type": "string"}, | ||
| "status": {"type": "integer"}, | ||
| "owner" : {"$ref":"../owner.schema.json"} | ||
| }, | ||
| "required": [ | ||
| "code", | ||
| "messages", | ||
| "status", | ||
| "owner" | ||
| ] | ||
| } |
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "id" : "genericArray.schema.json", | ||
| "title": "GenericArray", | ||
| "description": "A single array", | ||
| "type": "array" | ||
| } |
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "id" : "genericMap.schema.json", | ||
| "title": "genericMap", | ||
| "description": "A generic map", | ||
| "type": "object" | ||
| } |
| { | ||
| "id": "widget", | ||
| "type": "object", | ||
| "title": "Widget", | ||
| "description": "A widget is used to generated partials", | ||
| "required": ["id", "name", "groupId", "artifactId", "revision", "description"], | ||
| "properties": { | ||
| "name": { | ||
| "description": "The friendly name of the widget ", | ||
| "type": "string" | ||
| }, | ||
| "etiquetas":{ | ||
| "$ref": "widget#/definitions/innerProperties/tags" | ||
| } | ||
| }, | ||
| "definitions": { | ||
| "innerProperties": { | ||
| "xid": { | ||
| "description": "The unique identifier of the widget ", | ||
| "type": "string" | ||
| }, | ||
| "name": { | ||
| "description": "The friendly name of the widget ", | ||
| "type": "string" | ||
| }, | ||
| "tags": { | ||
| "description": "Common set of keywords to categorize widgets", | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string", | ||
| "format": "[a-z]{1,20}" | ||
| }, | ||
| "uniqueItems": true | ||
| }, | ||
| "groupId": { | ||
| "description": "The version of the Widget ", | ||
| "type": "string" | ||
| }, | ||
| "artifactId": { | ||
| "description": "The version of the Widget ", | ||
| "type": "string" | ||
| }, | ||
| "revision": { | ||
| "description": "The version of the Widget ", | ||
| "type": "string" | ||
| }, | ||
| "description": { | ||
| "description": "The description of the Widget ", | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "something": { | ||
| "xid": { | ||
| "description": "The unique identifier of the widget ", | ||
| "type": "string" | ||
| }, | ||
| "colour": { | ||
| "description": "The friendly name of the widget ", | ||
| "type": "string" | ||
| }, | ||
| "ipsum": { | ||
| "description": "The version of the Widget ", | ||
| "type": "string" | ||
| }, | ||
| "lorem": { | ||
| "description": "The description of the Widget ", | ||
| "type": "string" | ||
| } | ||
| } | ||
| } | ||
| } |
| { | ||
| "id": "widgetInlineProperty", | ||
| "type": "object", | ||
| "title": "WidgetInlineProperty", | ||
| "description": "A widget is used to generated partials", | ||
| "required": ["id", "name", "groupId", "artifactId", "revision", "description"], | ||
| "properties": { | ||
| "name": { | ||
| "description": "The friendly name of the widget ", | ||
| "type": "string" | ||
| }, | ||
| "composite":{ | ||
| "type": "object", | ||
| "description": "Inner properties", | ||
| "$ref": "widget#/definitions/innerProperties" | ||
| }, | ||
| "zid":{ | ||
| "$ref": "widget#/definitions/something" | ||
| }, | ||
| "otherColor":{ | ||
| "$ref": "widget#/definitions/something/colour" | ||
| } | ||
| } | ||
| } |
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "title": "Owner", | ||
| "id": "owner.schema.json", | ||
| "description": "A owner cat from Atoms catalog", | ||
| "type": "object", | ||
| "properties": { | ||
| "id": { | ||
| "description": "The unique identifier for a owner", | ||
| "type": "integer" | ||
| }, | ||
| "name": { | ||
| "description": "Name of the owner", | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": ["id", "name"] | ||
| } |
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "id" : "genericArray.schema.json", | ||
| "title": "GenericArray", | ||
| "description": "A single array", | ||
| "type": "array", | ||
| "items":{ | ||
| "$ref": "cat.schema.json" | ||
| } | ||
| } |
| { | ||
| "$schema": "http://json-schema.org/draft-04/schema#", | ||
| "id" : "genericArray.schema.json", | ||
| "title": "GenericArray", | ||
| "description": "A single array", | ||
| "type": "array", | ||
| "items":{ | ||
| "type": "string" | ||
| } | ||
| } |
| 'use strict'; | ||
| var raml = require('raml-parser'), expect = require('chai').expect; | ||
| var raml2code =require('..'); | ||
| var gutil = require('gulp-util'); | ||
| var stream = require('stream'); | ||
| var path = require('path'); | ||
| var fs = require('fs'); | ||
| var wrapAssertion = require("./helpers").wrapAssertion; | ||
| var chai = require('chai'); | ||
| chai.should(); | ||
| describe('raml2code basic test', function () { | ||
| describe('in streaming mode', function() { | ||
| it('fails with an error (streams are not supported)', function(done) { | ||
| var raml2codeInstance = raml2code(); | ||
| raml2codeInstance.once('error', function(error) { | ||
| error.message.should.match(/streams are not supported/i); | ||
| done(); | ||
| }); | ||
| raml2codeInstance.write(new gutil.File({ | ||
| contents: new stream.Readable() | ||
| })); | ||
| }); | ||
| }); | ||
| describe('in buffer mode', function() { | ||
| it('emits syntax erros in bad RAML file', function(done) { | ||
| var raml2codeInstance = raml2code(); | ||
| var ramlPath = path.join(__dirname, 'raml/cats.bad.raml'); | ||
| var ramlContents = fs.readFileSync(ramlPath); | ||
| raml2codeInstance.once('error', function(error) { | ||
| error.message.should.equal('unknown property resourceTypess'); | ||
| done(); | ||
| }); | ||
| raml2codeInstance.write(new gutil.File({ | ||
| path: ramlPath, | ||
| contents: ramlContents | ||
| })); | ||
| }); | ||
| it('emits syntax erros if generator is not provided', function(done) { | ||
| var raml2codeInstance = raml2code(); | ||
| var ramlPath = path.join(__dirname, 'raml/cats.raml'); | ||
| var ramlContents = fs.readFileSync(ramlPath); | ||
| raml2codeInstance.on('error', function(error) { | ||
| error.message.should.equal('Generator not supplied'); | ||
| done(); | ||
| }); | ||
| raml2codeInstance.write(new gutil.File({ | ||
| path: ramlPath, | ||
| contents: ramlContents | ||
| })); | ||
| }); | ||
| it('can convert an example RAML file', function(done) { | ||
| var simpleGen = {}; | ||
| simpleGen.template = '{{title}}'; | ||
| simpleGen.parser = function (data) { | ||
| return [{ name: "test.test", model: {title:data.title + " finos"}}] | ||
| }; | ||
| var raml2codeInstance = raml2code({generator:simpleGen}); | ||
| var ramlPath = path.join(__dirname, 'raml/cats.raml'); | ||
| var ramlContents = fs.readFileSync(ramlPath); | ||
| raml2codeInstance.write(new gutil.File({ | ||
| path: ramlPath, | ||
| contents: ramlContents | ||
| })); | ||
| raml2codeInstance.on('data', function(file){ | ||
| wrapAssertion(function () { | ||
| file.path.should.equal('test.test'); | ||
| file.contents.toString('utf8').should.equal("Gatitos API finos"); | ||
| }, done); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
139
26.36%0
-100%33924
-31.47%7
16.67%21
-44.74%769
-35.59%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated
Updated