forked from loafle/openapi-generator-original
		
	updated with dataType in paths, now validates
This commit is contained in:
		
							parent
							
								
									b7ed61b8f9
								
							
						
					
					
						commit
						6636acf2d3
					
				@ -26,7 +26,7 @@ exports.path = function(name, description, dataType, allowableValues) {
 | 
				
			|||||||
  return {
 | 
					  return {
 | 
				
			||||||
    "name" : name,
 | 
					    "name" : name,
 | 
				
			||||||
    "description" : description,
 | 
					    "description" : description,
 | 
				
			||||||
    "dataType" : dataType,
 | 
					    "dataType" : dataType = "string",
 | 
				
			||||||
    "required" : true,
 | 
					    "required" : true,
 | 
				
			||||||
    "allowMultiple" : false,
 | 
					    "allowMultiple" : false,
 | 
				
			||||||
    "allowableValues" : createEnum(allowableValues),
 | 
					    "allowableValues" : createEnum(allowableValues),
 | 
				
			||||||
 | 
				
			|||||||
@ -310,10 +310,7 @@ function resourceListing(request, response) {
 | 
				
			|||||||
    r.apis.push({"path": "/" + key, "description": "none"}); 
 | 
					    r.apis.push({"path": "/" + key, "description": "none"}); 
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    response.header('Access-Control-Allow-Origin', "*");
 | 
					  writeHeaders(response);
 | 
				
			||||||
    response.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
 | 
					 | 
				
			||||||
    response.header("Access-Control-Allow-Headers", "Content-Type");
 | 
					 | 
				
			||||||
    response.header("Content-Type", "application/json; charset=utf-8");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  response.write(JSON.stringify(r));
 | 
					  response.write(JSON.stringify(r));
 | 
				
			||||||
  response.end();
 | 
					  response.end();
 | 
				
			||||||
@ -361,11 +358,7 @@ function addMethod(app, callback, spec) {
 | 
				
			|||||||
  var currentMethod = spec.method.toLowerCase();
 | 
					  var currentMethod = spec.method.toLowerCase();
 | 
				
			||||||
  if (allowedMethods.indexOf(currentMethod)>-1) {
 | 
					  if (allowedMethods.indexOf(currentMethod)>-1) {
 | 
				
			||||||
    app[currentMethod](fullPath, function(req,res) {
 | 
					    app[currentMethod](fullPath, function(req,res) {
 | 
				
			||||||
        res.header('Access-Control-Allow-Origin', "*");
 | 
					      writeHeaders(res);
 | 
				
			||||||
        res.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
 | 
					 | 
				
			||||||
        res.header("Access-Control-Allow-Headers", "Content-Type");
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        res.header("Content-Type", "application/json; charset=utf-8");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (!canAccessResource(req, req.url.substr(1).split('?')[0].replace('.json', '.*'), req.method)) {
 | 
					      if (!canAccessResource(req, req.url.substr(1).split('?')[0].replace('.json', '.*'), req.method)) {
 | 
				
			||||||
        res.send(JSON.stringify({"description":"forbidden", "code":403}), 403);
 | 
					        res.send(JSON.stringify({"description":"forbidden", "code":403}), 403);
 | 
				
			||||||
@ -457,6 +450,13 @@ function wrap(callback, req, resp){
 | 
				
			|||||||
  callback(req,resp);
 | 
					  callback(req,resp);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function writeHeaders(response) {
 | 
				
			||||||
 | 
						response.header('Access-Control-Allow-Origin', "*");
 | 
				
			||||||
 | 
						response.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
 | 
				
			||||||
 | 
						response.header("Access-Control-Allow-Headers", "Content-Type");
 | 
				
			||||||
 | 
						response.header("Content-Type", "application/json; charset=utf-8");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function appendToApi(rootResource, api, spec) {
 | 
					function appendToApi(rootResource, api, spec) {
 | 
				
			||||||
  if (!api.description) {
 | 
					  if (!api.description) {
 | 
				
			||||||
    api.description = spec.description; 
 | 
					    api.description = spec.description; 
 | 
				
			||||||
 | 
				
			|||||||
@ -23,8 +23,8 @@ exports.getPetById = {
 | 
				
			|||||||
    "summary" : "Find pet by ID",
 | 
					    "summary" : "Find pet by ID",
 | 
				
			||||||
    "method": "GET",
 | 
					    "method": "GET",
 | 
				
			||||||
    "params" : [].concat([param.path("petId", "ID of pet that needs to be fetched")]).concat([]).concat([]),
 | 
					    "params" : [].concat([param.path("petId", "ID of pet that needs to be fetched")]).concat([]).concat([]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "Pet",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('Pet')],
 | 
				
			||||||
    "nickname" : "getPetById"
 | 
					    "nickname" : "getPetById"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -44,7 +44,7 @@ exports.addPet = {
 | 
				
			|||||||
    "params" : [].concat([]).concat([]).concat([param.post("Pet", "Pet object that needs to be added to the store", true)
 | 
					    "params" : [].concat([]).concat([]).concat([param.post("Pet", "Pet object that needs to be added to the store", true)
 | 
				
			||||||
    ]),
 | 
					    ]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('')],
 | 
				
			||||||
    "nickname" : "addPet"
 | 
					    "nickname" : "addPet"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -64,7 +64,7 @@ exports.updatePet = {
 | 
				
			|||||||
    "params" : [].concat([]).concat([]).concat([param.post("Pet", "Pet object that needs to be updated in the store", true)
 | 
					    "params" : [].concat([]).concat([]).concat([param.post("Pet", "Pet object that needs to be updated in the store", true)
 | 
				
			||||||
    ]),
 | 
					    ]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('')],
 | 
				
			||||||
    "nickname" : "updatePet"
 | 
					    "nickname" : "updatePet"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -81,9 +81,9 @@ exports.findPetsByStatus = {
 | 
				
			|||||||
    "notes" : "Multiple status values can be provided with comma seperated strings",
 | 
					    "notes" : "Multiple status values can be provided with comma seperated strings",
 | 
				
			||||||
    "summary" : "Finds Pets by status",
 | 
					    "summary" : "Finds Pets by status",
 | 
				
			||||||
    "method": "GET",
 | 
					    "method": "GET",
 | 
				
			||||||
    "params" : [param.query("status", "Status values that need to be considered for filter", "String", true, true, "LIST[available,pending,sold]", "available")].concat([]).concat([]).concat([]),
 | 
					    "params" : [param.query("status", "Status values that need to be considered for filter", "string", true, true, "LIST[available,pending,sold]", "available")].concat([]).concat([]).concat([]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "List[Pet]",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('List[Pet]')],
 | 
				
			||||||
    "nickname" : "findPetsByStatus"
 | 
					    "nickname" : "findPetsByStatus"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -100,9 +100,9 @@ exports.findPetsByTags = {
 | 
				
			|||||||
    "notes" : "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
 | 
					    "notes" : "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
 | 
				
			||||||
    "summary" : "Finds Pets by tags",
 | 
					    "summary" : "Finds Pets by tags",
 | 
				
			||||||
    "method": "GET",
 | 
					    "method": "GET",
 | 
				
			||||||
    "params" : [param.query("tags", "Tags to filter by", "String", true, true, "")].concat([]).concat([]).concat([]),
 | 
					    "params" : [param.query("tags", "Tags to filter by", "string", true, true, "")].concat([]).concat([]).concat([]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "List[Pet]",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('List[Pet]')],
 | 
				
			||||||
    "nickname" : "findPetsByTags"
 | 
					    "nickname" : "findPetsByTags"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
 | 
				
			|||||||
@ -23,8 +23,8 @@ exports.getOrderById = {
 | 
				
			|||||||
    "summary" : "Find purchase order by ID",
 | 
					    "summary" : "Find purchase order by ID",
 | 
				
			||||||
    "method": "GET",
 | 
					    "method": "GET",
 | 
				
			||||||
    "params" : [].concat([param.path("orderId", "ID of pet that needs to be fetched")]).concat([]).concat([]),
 | 
					    "params" : [].concat([param.path("orderId", "ID of pet that needs to be fetched")]).concat([]).concat([]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "Order",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('Order')],
 | 
				
			||||||
    "nickname" : "getOrderById"
 | 
					    "nickname" : "getOrderById"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -43,7 +43,7 @@ exports.deleteOrder = {
 | 
				
			|||||||
    "method": "DELETE",
 | 
					    "method": "DELETE",
 | 
				
			||||||
    "params" : [].concat([param.path("orderId", "ID of the order that needs to be deleted")]).concat([]).concat([]),
 | 
					    "params" : [].concat([param.path("orderId", "ID of the order that needs to be deleted")]).concat([]).concat([]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('')],
 | 
				
			||||||
    "nickname" : "deleteOrder"
 | 
					    "nickname" : "deleteOrder"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -63,7 +63,7 @@ exports.placeOrder = {
 | 
				
			|||||||
    "params" : [].concat([]).concat([]).concat([param.post("Order", "order placed for purchasing the pet", true)
 | 
					    "params" : [].concat([]).concat([]).concat([param.post("Order", "order placed for purchasing the pet", true)
 | 
				
			||||||
    ]),
 | 
					    ]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('')],
 | 
				
			||||||
    "nickname" : "placeOrder"
 | 
					    "nickname" : "placeOrder"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
 | 
				
			|||||||
@ -25,7 +25,7 @@ exports.createUsersWithArrayInput = {
 | 
				
			|||||||
    "params" : [].concat([]).concat([]).concat([param.post("Array[User]", "List of user object", true)
 | 
					    "params" : [].concat([]).concat([]).concat([param.post("Array[User]", "List of user object", true)
 | 
				
			||||||
    ]),
 | 
					    ]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('')],
 | 
				
			||||||
    "nickname" : "createUsersWithArrayInput"
 | 
					    "nickname" : "createUsersWithArrayInput"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -45,7 +45,7 @@ exports.createUser = {
 | 
				
			|||||||
    "params" : [].concat([]).concat([]).concat([param.post("User", "Created user object", true)
 | 
					    "params" : [].concat([]).concat([]).concat([param.post("User", "Created user object", true)
 | 
				
			||||||
    ]),
 | 
					    ]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('')],
 | 
				
			||||||
    "nickname" : "createUser"
 | 
					    "nickname" : "createUser"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -65,7 +65,7 @@ exports.createUsersWithListInput = {
 | 
				
			|||||||
    "params" : [].concat([]).concat([]).concat([param.post("List[User]", "List of user object", true)
 | 
					    "params" : [].concat([]).concat([]).concat([param.post("List[User]", "List of user object", true)
 | 
				
			||||||
    ]),
 | 
					    ]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('')],
 | 
				
			||||||
    "nickname" : "createUsersWithListInput"
 | 
					    "nickname" : "createUsersWithListInput"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -85,7 +85,7 @@ exports.updateUser = {
 | 
				
			|||||||
    "params" : [].concat([param.path("username", "name that need to be deleted")]).concat([]).concat([param.post("User", "Updated user object", true)
 | 
					    "params" : [].concat([param.path("username", "name that need to be deleted")]).concat([]).concat([param.post("User", "Updated user object", true)
 | 
				
			||||||
    ]),
 | 
					    ]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('')],
 | 
				
			||||||
    "nickname" : "updateUser"
 | 
					    "nickname" : "updateUser"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -107,7 +107,7 @@ exports.deleteUser = {
 | 
				
			|||||||
    "method": "DELETE",
 | 
					    "method": "DELETE",
 | 
				
			||||||
    "params" : [].concat([param.path("username", "The name that needs to be deleted")]).concat([]).concat([]),
 | 
					    "params" : [].concat([param.path("username", "The name that needs to be deleted")]).concat([]).concat([]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('')],
 | 
				
			||||||
    "nickname" : "deleteUser"
 | 
					    "nickname" : "deleteUser"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -125,8 +125,8 @@ exports.getUserByName = {
 | 
				
			|||||||
    "summary" : "Get user by user name",
 | 
					    "summary" : "Get user by user name",
 | 
				
			||||||
    "method": "GET",
 | 
					    "method": "GET",
 | 
				
			||||||
    "params" : [].concat([param.path("username", "The name that needs to be fetched. Use user1 for testing.")]).concat([]).concat([]),
 | 
					    "params" : [].concat([param.path("username", "The name that needs to be fetched. Use user1 for testing.")]).concat([]).concat([]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "User",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('User')],
 | 
				
			||||||
    "nickname" : "getUserByName"
 | 
					    "nickname" : "getUserByName"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -143,9 +143,9 @@ exports.loginUser = {
 | 
				
			|||||||
    "notes" : "",
 | 
					    "notes" : "",
 | 
				
			||||||
    "summary" : "Logs user into the system",
 | 
					    "summary" : "Logs user into the system",
 | 
				
			||||||
    "method": "GET",
 | 
					    "method": "GET",
 | 
				
			||||||
    "params" : [param.query("username", "The user name for login", "String", true, false, ""),param.query("password", "The password for login in clear text", "String", true, false, "")].concat([]).concat([]).concat([]),
 | 
					    "params" : [param.query("username", "The user name for login", "string", true, false, ""),param.query("password", "The password for login in clear text", "string", true, false, "")].concat([]).concat([]).concat([]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "String",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('String')],
 | 
				
			||||||
    "nickname" : "loginUser"
 | 
					    "nickname" : "loginUser"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
@ -167,7 +167,7 @@ exports.logoutUser = {
 | 
				
			|||||||
    "method": "GET",
 | 
					    "method": "GET",
 | 
				
			||||||
    "params" : [].concat([]).concat([]).concat([]),
 | 
					    "params" : [].concat([]).concat([]).concat([]),
 | 
				
			||||||
    "responseClass" : "",
 | 
					    "responseClass" : "",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('')],
 | 
				
			||||||
    "nickname" : "logoutUser"
 | 
					    "nickname" : "logoutUser"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
 | 
				
			|||||||
@ -9,26 +9,26 @@ app.use(express.bodyParser());
 | 
				
			|||||||
swagger.setAppHandler(app);  
 | 
					swagger.setAppHandler(app);  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// resources for the demo
 | 
					// resources for the demo
 | 
				
			||||||
var UserApi = require("./apis/UserApi.js");
 | 
					var petApi = require("./apis/PetApi.js");
 | 
				
			||||||
var StoreApi = require("./apis/StoreApi.js");
 | 
					var storeApi = require("./apis/StoreApi.js");
 | 
				
			||||||
var PetApi = require("./apis/PetApi.js");
 | 
					var userApi = require("./apis/UserApi.js");
 | 
				
			||||||
swagger.addModels(models)
 | 
					swagger.addModels(models)
 | 
				
			||||||
  .addPOST(UserApi.createUsersWithArrayInput)
 | 
					  .addGET(petApi.getPetById)
 | 
				
			||||||
  .addPOST(UserApi.createUser)
 | 
					  .addPOST(petApi.addPet)
 | 
				
			||||||
  .addPOST(UserApi.createUsersWithListInput)
 | 
					  .addPUT(petApi.updatePet)
 | 
				
			||||||
  .addPUT(UserApi.updateUser)
 | 
					  .addGET(petApi.findPetsByStatus)
 | 
				
			||||||
  .addDELETE(UserApi.deleteUser)
 | 
					  .addGET(petApi.findPetsByTags)
 | 
				
			||||||
  .addGET(UserApi.getUserByName)
 | 
					  .addGET(storeApi.getOrderById)
 | 
				
			||||||
  .addGET(UserApi.loginUser)
 | 
					  .addDELETE(storeApi.deleteOrder)
 | 
				
			||||||
  .addGET(UserApi.logoutUser)
 | 
					  .addPOST(storeApi.placeOrder)
 | 
				
			||||||
  .addGET(StoreApi.getOrderById)
 | 
					  .addPOST(userApi.createUsersWithArrayInput)
 | 
				
			||||||
  .addDELETE(StoreApi.deleteOrder)
 | 
					  .addPOST(userApi.createUser)
 | 
				
			||||||
  .addPOST(StoreApi.placeOrder)
 | 
					  .addPOST(userApi.createUsersWithListInput)
 | 
				
			||||||
  .addGET(PetApi.getPetById)
 | 
					  .addPUT(userApi.updateUser)
 | 
				
			||||||
  .addPOST(PetApi.addPet)
 | 
					  .addDELETE(userApi.deleteUser)
 | 
				
			||||||
  .addPUT(PetApi.updatePet)
 | 
					  .addGET(userApi.getUserByName)
 | 
				
			||||||
  .addGET(PetApi.findPetsByStatus)
 | 
					  .addGET(userApi.loginUser)
 | 
				
			||||||
  .addGET(PetApi.findPetsByTags)
 | 
					  .addGET(userApi.logoutUser)
 | 
				
			||||||
  ;
 | 
					  ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// configures the app
 | 
					// configures the app
 | 
				
			||||||
 | 
				
			|||||||
@ -26,7 +26,7 @@ exports.path = function(name, description, dataType, allowableValues) {
 | 
				
			|||||||
  return {
 | 
					  return {
 | 
				
			||||||
    "name" : name,
 | 
					    "name" : name,
 | 
				
			||||||
    "description" : description,
 | 
					    "description" : description,
 | 
				
			||||||
    "dataType" : dataType,
 | 
					    "dataType" : dataType = "string",
 | 
				
			||||||
    "required" : true,
 | 
					    "required" : true,
 | 
				
			||||||
    "allowMultiple" : false,
 | 
					    "allowMultiple" : false,
 | 
				
			||||||
    "allowableValues" : createEnum(allowableValues),
 | 
					    "allowableValues" : createEnum(allowableValues),
 | 
				
			||||||
 | 
				
			|||||||
@ -310,10 +310,7 @@ function resourceListing(request, response) {
 | 
				
			|||||||
    r.apis.push({"path": "/" + key, "description": "none"}); 
 | 
					    r.apis.push({"path": "/" + key, "description": "none"}); 
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    response.header('Access-Control-Allow-Origin', "*");
 | 
					  writeHeaders(response);
 | 
				
			||||||
    response.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
 | 
					 | 
				
			||||||
    response.header("Access-Control-Allow-Headers", "Content-Type");
 | 
					 | 
				
			||||||
    response.header("Content-Type", "application/json; charset=utf-8");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  response.write(JSON.stringify(r));
 | 
					  response.write(JSON.stringify(r));
 | 
				
			||||||
  response.end();
 | 
					  response.end();
 | 
				
			||||||
@ -361,11 +358,7 @@ function addMethod(app, callback, spec) {
 | 
				
			|||||||
  var currentMethod = spec.method.toLowerCase();
 | 
					  var currentMethod = spec.method.toLowerCase();
 | 
				
			||||||
  if (allowedMethods.indexOf(currentMethod)>-1) {
 | 
					  if (allowedMethods.indexOf(currentMethod)>-1) {
 | 
				
			||||||
    app[currentMethod](fullPath, function(req,res) {
 | 
					    app[currentMethod](fullPath, function(req,res) {
 | 
				
			||||||
        res.header('Access-Control-Allow-Origin', "*");
 | 
					      writeHeaders(res);
 | 
				
			||||||
        res.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
 | 
					 | 
				
			||||||
        res.header("Access-Control-Allow-Headers", "Content-Type");
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        res.header("Content-Type", "application/json; charset=utf-8");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (!canAccessResource(req, req.url.substr(1).split('?')[0].replace('.json', '.*'), req.method)) {
 | 
					      if (!canAccessResource(req, req.url.substr(1).split('?')[0].replace('.json', '.*'), req.method)) {
 | 
				
			||||||
        res.send(JSON.stringify({"description":"forbidden", "code":403}), 403);
 | 
					        res.send(JSON.stringify({"description":"forbidden", "code":403}), 403);
 | 
				
			||||||
@ -457,6 +450,13 @@ function wrap(callback, req, resp){
 | 
				
			|||||||
  callback(req,resp);
 | 
					  callback(req,resp);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function writeHeaders(response) {
 | 
				
			||||||
 | 
						response.header('Access-Control-Allow-Origin', "*");
 | 
				
			||||||
 | 
						response.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
 | 
				
			||||||
 | 
						response.header("Access-Control-Allow-Headers", "Content-Type");
 | 
				
			||||||
 | 
						response.header("Content-Type", "application/json; charset=utf-8");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function appendToApi(rootResource, api, spec) {
 | 
					function appendToApi(rootResource, api, spec) {
 | 
				
			||||||
  if (!api.description) {
 | 
					  if (!api.description) {
 | 
				
			||||||
    api.description = spec.description; 
 | 
					    api.description = spec.description; 
 | 
				
			||||||
 | 
				
			|||||||
@ -25,16 +25,16 @@ exports.{{nickname}} = {
 | 
				
			|||||||
    "summary" : "{{{summary}}}",
 | 
					    "summary" : "{{{summary}}}",
 | 
				
			||||||
    "method": "{{httpMethod}}",
 | 
					    "method": "{{httpMethod}}",
 | 
				
			||||||
    "params" : [{{#queryParams}}
 | 
					    "params" : [{{#queryParams}}
 | 
				
			||||||
      param.query("{{paramName}}", "{{description}}", "{{dataType}}", {{required}}, {{allowMultiple}}, "{{{allowableValues}}}"{{#defaultValue}}, {{{defaultValue}}}{{/defaultValue}}){{#hasMore}},{{/hasMore}}
 | 
					      param.query("{{paramName}}", "{{description}}", "{{swaggerDataType}}", {{required}}, {{allowMultiple}}, "{{{allowableValues}}}"{{#defaultValue}}, {{{defaultValue}}}{{/defaultValue}}){{#hasMore}},{{/hasMore}}
 | 
				
			||||||
    {{/queryParams}}].concat([{{#pathParams}}
 | 
					    {{/queryParams}}].concat([{{#pathParams}}
 | 
				
			||||||
      param.path("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
 | 
					      param.path("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
 | 
				
			||||||
    {{/pathParams}}]).concat([{{#headerParams}}
 | 
					    {{/pathParams}}]).concat([{{#headerParams}}
 | 
				
			||||||
      param.header("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
 | 
					      param.header("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
 | 
				
			||||||
    {{/headerParams}}]).concat([{{#bodyParams}}
 | 
					    {{/headerParams}}]).concat([{{#bodyParams}}
 | 
				
			||||||
      param.post("{{dataType}}", "{{description}}", {{required}})
 | 
					      param.post("{{swaggerDataType}}", "{{description}}", {{required}})
 | 
				
			||||||
    {{/bodyParams}}]),
 | 
					    {{/bodyParams}}]),
 | 
				
			||||||
    "responseClass" : "{{responseClass}}",
 | 
					    "responseClass" : "{{returnType}}",
 | 
				
			||||||
    "errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
 | 
					    "errorResponses" : [swe.invalid('id'), swe.notFound('{{returnType}}')],
 | 
				
			||||||
    "nickname" : "{{nickname}}"
 | 
					    "nickname" : "{{nickname}}"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  'action': function (req,res) {
 | 
					  'action': function (req,res) {
 | 
				
			||||||
 | 
				
			|||||||
@ -10,13 +10,13 @@ swagger.setAppHandler(app);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// resources for the demo
 | 
					// resources for the demo
 | 
				
			||||||
{{#apis}}
 | 
					{{#apis}}
 | 
				
			||||||
var {{name}} = require("./apis/{{name}}.js");
 | 
					var {{name}}Api = require("./apis/{{className}}.js");
 | 
				
			||||||
{{/apis}}
 | 
					{{/apis}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
swagger.addModels(models)
 | 
					swagger.addModels(models)
 | 
				
			||||||
  {{#apis}}
 | 
					  {{#apis}}
 | 
				
			||||||
  {{#operations}}
 | 
					  {{#operations}}
 | 
				
			||||||
  {{#operation}}.add{{httpMethod}}({{name}}.{{nickname}}){{/operation}}{{newline}}
 | 
					  {{#operation}}.add{{httpMethod}}({{name}}Api.{{nickname}}){{/operation}}{{newline}}
 | 
				
			||||||
  {{/operations}}
 | 
					  {{/operations}}
 | 
				
			||||||
  {{/apis}};
 | 
					  {{/apis}};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user