@@ -24,9 +24,14 @@ var commonHelpers, dirname, fs, generator, path, template, util, _; | ||
| generator.parser = function(data) { | ||
| var first, k, methodParse, model, parsed, resource, resourceGroup, v, _i, _len, _ref; | ||
| var annotations, first, k, methodParse, model, parsed, resource, resourceGroup, v, _i, _len, _ref; | ||
| parsed = []; | ||
| methodParse = []; | ||
| annotations = { | ||
| path: "@PathParam", | ||
| query: "@QueryParam", | ||
| body: "" | ||
| }; | ||
| _ref = data.resources; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| resource = _ref[_i]; | ||
| util.parseResource(resource, methodParse); | ||
| util.parseResource(resource, methodParse, annotations); | ||
| } | ||
@@ -33,0 +38,0 @@ resourceGroup = _.groupBy(methodParse, function(method) { |
@@ -22,9 +22,14 @@ var commonHelpers, dirname, fs, generator, path, template, util; | ||
| generator.parser = function(data) { | ||
| var methodParse, model, parsed, resource, _i, _len, _ref; | ||
| var annotations, methodParse, model, parsed, resource, _i, _len, _ref; | ||
| parsed = []; | ||
| methodParse = []; | ||
| annotations = { | ||
| path: "@Path", | ||
| query: "@Query", | ||
| body: "@Body" | ||
| }; | ||
| _ref = data.resources; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| resource = _ref[_i]; | ||
| util.parseResource(resource, methodParse); | ||
| util.parseResource(resource, methodParse, annotations); | ||
| } | ||
@@ -31,0 +36,0 @@ model = {}; |
@@ -7,2 +7,3 @@ package {{extra.package}} | ||
| import javax.ws.rs.PathParam | ||
| import javax.ws.rs.QueryParam | ||
| import javax.ws.rs.Produces | ||
@@ -25,2 +26,4 @@ import javax.ws.rs.core.Context | ||
| */ | ||
| @Consumes("application/json") | ||
| @Produces("application/json") | ||
| @{{annotation}} | ||
@@ -27,0 +30,0 @@ public Response {{{name}}}({{#each args}}{{#if @index}}, {{/if}}{{{kind}}} {{type}} {{name}}{{/each}}); |
@@ -5,3 +5,3 @@ var util; | ||
| util.getUriParameter = function(resource) { | ||
| util.getUriParameter = function(resource, annotation) { | ||
| var key, p, uriParameters; | ||
@@ -11,3 +11,3 @@ uriParameters = []; | ||
| p = resource.uriParameters[key]; | ||
| uriParameters.push(util.mapProperty(p, key)); | ||
| uriParameters.push(util.mapProperty(p, key, annotation)); | ||
| } | ||
@@ -17,3 +17,13 @@ return uriParameters; | ||
| util.mapProperty = function(property, name) { | ||
| util.getQueryparams = function(queryParams, annotation) { | ||
| var key, p, params; | ||
| params = []; | ||
| for (key in queryParams) { | ||
| p = queryParams[key]; | ||
| params.push(util.mapProperty(p, key, annotation)); | ||
| } | ||
| return params; | ||
| }; | ||
| util.mapProperty = function(property, name, annotation) { | ||
| var p; | ||
@@ -40,7 +50,7 @@ p = {}; | ||
| } | ||
| p.kind = "@Path(\"" + p.name + "\")"; | ||
| p.kind = annotation + ("(\"" + p.name + "\")"); | ||
| return p; | ||
| }; | ||
| util.parseResource = function(resource, parsed, parentUri, parentUriArgs) { | ||
| util.parseResource = function(resource, parsed, annotations, parentUri, parentUriArgs) { | ||
| var innerResource, m, methodDef, request, respond, uriArgs, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3; | ||
@@ -58,4 +68,5 @@ if (parentUri == null) { | ||
| methodDef.uri = parentUri + resource.relativeUri; | ||
| uriArgs = util.getUriParameter(resource); | ||
| uriArgs = util.getUriParameter(resource, annotations.path); | ||
| methodDef.args = parentUriArgs.concat(uriArgs); | ||
| methodDef.args = methodDef.args.concat(util.getQueryparams(m.queryParameters, annotations.query)); | ||
| request = util.parseSchema(m.body, "" + methodDef.uri + " body"); | ||
@@ -66,3 +77,3 @@ respond = util.parseSchema(util.getBestValidResponse(m.responses).body, "" + methodDef.uri + " response"); | ||
| methodDef.args.push({ | ||
| 'kind': '@Body', | ||
| 'kind': annotations.body, | ||
| 'type': request.title, | ||
@@ -83,3 +94,3 @@ 'name': request.title.toLowerCase() | ||
| innerResource = _ref3[_j]; | ||
| util.parseResource(innerResource, parsed, resource.relativeUri, uriArgs); | ||
| util.parseResource(innerResource, parsed, annotations, resource.relativeUri, uriArgs); | ||
| } | ||
@@ -86,0 +97,0 @@ } |
+3
-3
| { | ||
| "name": "raml2code", | ||
| "version": "0.0.4", | ||
| "version": "0.0.5", | ||
| "description": "Raml spec to code", | ||
@@ -27,3 +27,4 @@ "main": "index.js", | ||
| "raml-parser": "~0.8.7", | ||
| "through2": "~0.6.1" | ||
| "through2": "~0.6.1", | ||
| "lodash": "^2.4.1" | ||
| }, | ||
@@ -37,5 +38,4 @@ "devDependencies": { | ||
| "gulp-util": "3.0.1", | ||
| "lodash": "^2.4.1", | ||
| "mocha": "^1.20.1" | ||
| } | ||
| } |
@@ -16,4 +16,9 @@ fs = require('fs') | ||
| methodParse = [] | ||
| annotations = | ||
| path: "@PathParam" | ||
| query: "@QueryParam" | ||
| body: "" | ||
| for resource in data.resources | ||
| util.parseResource(resource, methodParse) | ||
| util.parseResource(resource, methodParse, annotations) | ||
@@ -20,0 +25,0 @@ resourceGroup = _.groupBy(methodParse, (method) -> |
@@ -15,4 +15,8 @@ fs = require('fs') | ||
| methodParse = [] | ||
| annotations = | ||
| path: "@Path" | ||
| query: "@Query" | ||
| body: "@Body" | ||
| for resource in data.resources | ||
| util.parseResource(resource, methodParse) | ||
| util.parseResource(resource, methodParse, annotations) | ||
@@ -19,0 +23,0 @@ model = {} |
@@ -7,2 +7,3 @@ package {{extra.package}} | ||
| import javax.ws.rs.PathParam | ||
| import javax.ws.rs.QueryParam | ||
| import javax.ws.rs.Produces | ||
@@ -25,2 +26,4 @@ import javax.ws.rs.core.Context | ||
| */ | ||
| @Consumes("application/json") | ||
| @Produces("application/json") | ||
| @{{annotation}} | ||
@@ -27,0 +30,0 @@ public Response {{{name}}}({{#each args}}{{#if @index}}, {{/if}}{{{kind}}} {{type}} {{name}}{{/each}}); |
| util = {} | ||
| util.getUriParameter = (resource)-> | ||
| util.getUriParameter = (resource, annotation)-> | ||
| uriParameters = [] | ||
| for key of resource.uriParameters | ||
| p = resource.uriParameters[key] | ||
| uriParameters.push util.mapProperty(p, key) | ||
| uriParameters.push util.mapProperty(p, key, annotation) | ||
| uriParameters | ||
| util.mapProperty = (property, name)-> | ||
| util.getQueryparams = (queryParams, annotation)-> | ||
| params = [] | ||
| for key of queryParams | ||
| p = queryParams[key] | ||
| params.push util.mapProperty(p, key, annotation) | ||
| params | ||
| util.mapProperty = (property, name, annotation)-> | ||
| p = {} | ||
@@ -21,3 +29,3 @@ p.name = name | ||
| when 'integer' then p.type = "Integer" | ||
| p.kind = "@Path(\"#{p.name}\")" | ||
| p.kind = annotation + "(\"#{p.name}\")" | ||
| p | ||
@@ -27,9 +35,10 @@ | ||
| util.parseResource = (resource, parsed, parentUri = "", parentUriArgs = []) -> | ||
| # console.log "resource>", resource | ||
| util.parseResource = (resource, parsed, annotations, parentUri = "", parentUriArgs = []) -> | ||
| for m in resource.methods | ||
| methodDef = {} | ||
| methodDef.uri = parentUri + resource.relativeUri | ||
| uriArgs = util.getUriParameter(resource) | ||
| uriArgs = util.getUriParameter(resource, annotations.path) | ||
| methodDef.args = parentUriArgs.concat(uriArgs) | ||
| methodDef.args = methodDef.args.concat(util.getQueryparams(m.queryParameters, annotations.query)) | ||
| request = util.parseSchema(m.body, "#{methodDef.uri} body" ) | ||
@@ -39,3 +48,3 @@ respond = util.parseSchema(util.getBestValidResponse(m.responses).body, "#{methodDef.uri} response" ) | ||
| methodDef.args = methodDef.args ? [] | ||
| methodDef.args.push {'kind': '@Body', 'type': request.title, 'name': request.title.toLowerCase()} | ||
| methodDef.args.push {'kind': annotations.body, 'type': request.title, 'name': request.title.toLowerCase()} | ||
@@ -50,3 +59,3 @@ methodDef.request = request.title ? null | ||
| for innerResource in resource.resources | ||
| util.parseResource(innerResource, parsed, resource.relativeUri, uriArgs) | ||
| util.parseResource(innerResource, parsed, annotations, resource.relativeUri, uriArgs) | ||
| undefined | ||
@@ -75,2 +84,2 @@ | ||
| module.exports = util | ||
| module.exports = util |
@@ -7,2 +7,3 @@ package org.gex | ||
| import javax.ws.rs.PathParam | ||
| import javax.ws.rs.QueryParam | ||
| import javax.ws.rs.Produces | ||
@@ -21,4 +22,6 @@ import javax.ws.rs.core.Context | ||
| */ | ||
| @Consumes("application/json") | ||
| @Produces("application/json") | ||
| @GET | ||
| public Response getGatitos(); | ||
| public Response getGatitos(@QueryParam("search") String search); | ||
@@ -28,6 +31,8 @@ /*** | ||
| */ | ||
| @Consumes("application/json") | ||
| @Produces("application/json") | ||
| @POST | ||
| public Response postGatitos(@Body Cat cat); | ||
| public Response postGatitos( Cat cat); | ||
| } |
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.
33773
5.6%7
-12.5%594
3.48%0
-100%5
25%+ Added
+ Added