diff --git a/lib/swagger.js b/lib/swagger.js index f97f27b..936fb2e 100644 --- a/lib/swagger.js +++ b/lib/swagger.js @@ -38,7 +38,7 @@ function Swagger(remotes, options) { // A class is an endpoint root; e.g. /users, /products, and so on. classes.forEach(function (item) { resourceDoc.apis.push({ - path: name + item.http.path, + path: '/' + name + item.http.path, description: item.ctor.sharedCtor && item.ctor.sharedCtor.description }); @@ -92,6 +92,15 @@ function Swagger(remotes, options) { // HACK: makes autogenerated REST routes return the correct model name. var returns = route.returns && route.returns[0]; + if(typeof returns === 'object') { + // Clone the object as it's shared by multiple models + var originalReturns = returns; + returns = {}; + for(var p in originalReturns) { + returns[p] = originalReturns[p]; + } + route.returns[0] = returns; + } if (returns && returns.arg === 'data') { if (returns.type === 'object') { returns.type = classDef.name; @@ -180,7 +189,7 @@ function addDynamicBasePathGetter(remotes, path, obj) { */ function generateModelDefinition(aClass) { var def = aClass.ctor.definition; - var name = aClass.name; + var name = def.name; var required = []; // Keys that are different between LDL and Swagger @@ -197,10 +206,15 @@ function generateModelDefinition(aClass) { Object.keys(def.properties).forEach(function(key) { var prop = def.properties[key]; // Required props sit in a different array. - if (prop.required || prop.id) required.push(key); + if (prop.required || prop.id) { + required.push(key); + } // Eke a type out of the constructors we were passed. if (typeof prop.type === "function") { prop.type = prop.type.name.toLowerCase(); + } else if(Array.isArray(prop.type)) { + prop.type = 'array'; + // prop.items.type = prop.type[0] ? prop.type[0].name.toLowerCase(): 'any'; } // Change mismatched keys. Object.keys(keyTranslations).forEach(function(LDLKey){ @@ -233,6 +247,8 @@ function generateModelDefinition(aClass) { function routeToAPI(route) { var returnDesc = route.returns && route.returns[0]; + console.log(route); + return { path: convertPathFragments(route.path), operations: [{ @@ -304,6 +320,11 @@ function acceptToParameter(route) { allowMultiple: false }; + // HACK: Derive the type from model + if(out.name === 'data' && out.type === 'object') { + out.type = route.method.split('.')[0]; + } + if (out.type === 'array') { out.items = { type: prepareDataType(accepts.type[0])