updated node sample

This commit is contained in:
Tony Tam
2014-06-11 06:41:31 -07:00
parent 209e8e066c
commit 218f514005
12 changed files with 439 additions and 183 deletions

View File

@@ -20,24 +20,34 @@ import scala.collection.mutable.{ HashMap, ListBuffer }
object NodeServerGenerator extends BasicScalaGenerator {
def main(args: Array[String]) = generateClient(args)
val codeDir = "app"
val apiDir = "apis"
override def templateDir = "samples/server-generator/node/templates"
val outputFolder = "samples/server-generator/node/output"
// where to write generated code
override def destinationDir = outputFolder + "/App"
override def destinationDir = outputFolder + java.io.File.separator + codeDir
override def apiPackage = Option(apiDir)
// template used for apis
apiTemplateFiles ++= Map("api.mustache" -> ".js")
modelTemplateFiles.clear
override def apiPackage = Some("apis")
additionalParams ++= Map(
"artifactId" -> "swagger-sample-app",
"artifactVersion" -> "1.0.0",
"homepage" -> "http://swagger.wordnik.com",
"codeDir" -> codeDir,
"apiFolder" -> apiDir
)
// supporting classes
override def supportingFiles = List(
("package.json", outputFolder, "package.json"),
("package.mustache", outputFolder, "package.json"),
("README.mustache", outputFolder, "README.md"),
("main.mustache", destinationDir, "main.js"),
("models.mustache", destinationDir, "models.js"))

View File

@@ -1,6 +1,7 @@
var swagger = require("swagger-node-express");
var url = require("url");
var errors = swagger.errors;
var params = swagger.params;
/* add model includes */
@@ -17,13 +18,13 @@ exports.models = models = require("../models.js");
exports.getPetById = {
'spec': {
"description" : "Operations about pets",
"path" : "/pet.{format}/{petId}",
"path" : "/pet/{petId}",
"notes" : "Returns a pet based on ID",
"summary" : "Find pet by ID",
"method": "GET",
"params" : [].concat([swagger.pathParam("petId", "ID of pet that needs to be fetched")]).concat([]).concat([]),
"responseClass" : "Pet",
"errorResponses" : [errors.invalid('id'), errors.notFound('Pet')],
"params" : [].concat([params.path("petId", "ID of pet that needs to be fetched")]).concat([]).concat([]),
"type" : "Pet",
"responseMessages" : [errors.invalid('id'), errors.notFound('Pet')],
"nickname" : "getPetById"
},
'action': function (req,res) {
@@ -33,17 +34,95 @@ exports.getPetById = {
writeResponse(res, {message: "how about implementing getPetById as a GET method?"});
}
};
exports.deletePet = {
'spec': {
"description" : "Operations about pets",
"path" : "/pet/{petId}",
"notes" : "",
"summary" : "Deletes a pet",
"method": "DELETE",
"params" : [].concat([params.path("petId", "Pet id to delete")]).concat([]).concat([]),
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "deletePet"
},
'action': function (req,res) {
if (!req.params.petId) {
throw errors.invalid('petId');
}
writeResponse(res, {message: "how about implementing deletePet as a DELETE method?"});
}
};
exports.partialUpdate = {
'spec': {
"description" : "Operations about pets",
"path" : "/pet/{petId}",
"notes" : "",
"summary" : "partial updates to a pet",
"method": "PATCH",
"params" : [].concat([params.path("petId", "ID of pet that needs to be fetched")]).concat([]).concat([params.body("body", "Pet", "Pet object that needs to be added to the store", true)
]),
"type" : "List[Pet]",
"responseMessages" : [errors.invalid('id'), errors.notFound('List[Pet]')],
"nickname" : "partialUpdate"
},
'action': function (req,res) {
if (!req.params.petId) {
throw errors.invalid('petId');
}
if (!req.params.body) {
throw errors.invalid('body');
}
writeResponse(res, {message: "how about implementing partialUpdate as a PATCH method?"});
}
};
exports.updatePetWithForm = {
'spec': {
"description" : "Operations about pets",
"path" : "/pet/{petId}",
"notes" : "",
"summary" : "Updates a pet in the store with form data",
"method": "POST",
"params" : [].concat([params.path("petId", "ID of pet that needs to be updated")]).concat([]).concat([]),
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "updatePetWithForm"
},
'action': function (req,res) {
if (!req.params.petId) {
throw errors.invalid('petId');
}
writeResponse(res, {message: "how about implementing updatePetWithForm as a POST method?"});
}
};
exports.uploadFile = {
'spec': {
"description" : "Operations about pets",
"path" : "/pet/uploadImage",
"notes" : "",
"summary" : "uploads an image",
"method": "POST",
"params" : [].concat([]).concat([]).concat([params.body("body", "File", "file to upload", false)
]),
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "uploadFile"
},
'action': function (req,res) {
writeResponse(res, {message: "how about implementing uploadFile as a POST method?"});
}
};
exports.addPet = {
'spec': {
"description" : "Operations about pets",
"path" : "/pet.{format}",
"path" : "/pet",
"notes" : "",
"summary" : "Add a new pet to the store",
"method": "POST",
"params" : [].concat([]).concat([]).concat([swagger.postParam("Pet", "Pet object that needs to be added to the store", true)
"params" : [].concat([]).concat([]).concat([params.body("body", "Pet", "Pet object that needs to be added to the store", true)
]),
"responseClass" : "",
"errorResponses" : [errors.invalid('id'), errors.notFound('')],
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "addPet"
},
'action': function (req,res) {
@@ -56,14 +135,14 @@ exports.addPet = {
exports.updatePet = {
'spec': {
"description" : "Operations about pets",
"path" : "/pet.{format}",
"path" : "/pet",
"notes" : "",
"summary" : "Update an existing pet",
"method": "PUT",
"params" : [].concat([]).concat([]).concat([swagger.postParam("Pet", "Pet object that needs to be updated in the store", true)
"params" : [].concat([]).concat([]).concat([params.body("body", "Pet", "Pet object that needs to be updated in the store", true)
]),
"responseClass" : "",
"errorResponses" : [errors.invalid('id'), errors.notFound('')],
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "updatePet"
},
'action': function (req,res) {
@@ -76,13 +155,13 @@ exports.updatePet = {
exports.findPetsByStatus = {
'spec': {
"description" : "Operations about pets",
"path" : "/pet.{format}/findByStatus",
"path" : "/pet/findByStatus",
"notes" : "Multiple status values can be provided with comma seperated strings",
"summary" : "Finds Pets by status",
"method": "GET",
"params" : [swagger.queryParam("status", "Status values that need to be considered for filter", "string", true, true, "", "available")].concat([]).concat([]).concat([]),
"responseClass" : "List[Pet]",
"errorResponses" : [errors.invalid('id'), errors.notFound('List[Pet]')],
"params" : [params.query("status", "Status values that need to be considered for filter", "string", true, true, "LIST[available,pending,sold]", "available")].concat([]).concat([]).concat([]),
"type" : "List[Pet]",
"responseMessages" : [errors.invalid('id'), errors.notFound('List[Pet]')],
"nickname" : "findPetsByStatus"
},
'action': function (req,res) {
@@ -95,13 +174,13 @@ exports.findPetsByStatus = {
exports.findPetsByTags = {
'spec': {
"description" : "Operations about pets",
"path" : "/pet.{format}/findByTags",
"path" : "/pet/findByTags",
"notes" : "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
"summary" : "Finds Pets by tags",
"method": "GET",
"params" : [swagger.queryParam("tags", "Tags to filter by", "string", true, true, "")].concat([]).concat([]).concat([]),
"responseClass" : "List[Pet]",
"errorResponses" : [errors.invalid('id'), errors.notFound('List[Pet]')],
"params" : [params.query("tags", "Tags to filter by", "string", true, true, "")].concat([]).concat([]).concat([]),
"type" : "List[Pet]",
"responseMessages" : [errors.invalid('id'), errors.notFound('List[Pet]')],
"nickname" : "findPetsByTags"
},
'action': function (req,res) {

View File

@@ -1,6 +1,7 @@
var swagger = require("swagger-node-express");
var url = require("url");
var errors = swagger.errors;
var params = swagger.params;
/* add model includes */
@@ -17,13 +18,13 @@ exports.models = models = require("../models.js");
exports.getOrderById = {
'spec': {
"description" : "Operations about pets",
"path" : "/store.{format}/order/{orderId}",
"path" : "/store/order/{orderId}",
"notes" : "For valid response try integer IDs with value <= 5. Anything above 5 or nonintegers will generate API errors",
"summary" : "Find purchase order by ID",
"method": "GET",
"params" : [].concat([swagger.pathParam("orderId", "ID of pet that needs to be fetched")]).concat([]).concat([]),
"responseClass" : "Order",
"errorResponses" : [errors.invalid('id'), errors.notFound('Order')],
"params" : [].concat([params.path("orderId", "ID of pet that needs to be fetched")]).concat([]).concat([]),
"type" : "Order",
"responseMessages" : [errors.invalid('id'), errors.notFound('Order')],
"nickname" : "getOrderById"
},
'action': function (req,res) {
@@ -36,13 +37,13 @@ exports.getOrderById = {
exports.deleteOrder = {
'spec': {
"description" : "Operations about pets",
"path" : "/store.{format}/order/{orderId}",
"notes" : "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
"path" : "/store/order/{orderId}",
"notes" : "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
"summary" : "Delete purchase order by ID",
"method": "DELETE",
"params" : [].concat([swagger.pathParam("orderId", "ID of the order that needs to be deleted")]).concat([]).concat([]),
"responseClass" : "",
"errorResponses" : [errors.invalid('id'), errors.notFound('')],
"params" : [].concat([params.path("orderId", "ID of the order that needs to be deleted")]).concat([]).concat([]),
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "deleteOrder"
},
'action': function (req,res) {
@@ -55,14 +56,14 @@ exports.deleteOrder = {
exports.placeOrder = {
'spec': {
"description" : "Operations about pets",
"path" : "/store.{format}/order",
"path" : "/store/order",
"notes" : "",
"summary" : "Place an order for a pet",
"method": "POST",
"params" : [].concat([]).concat([]).concat([swagger.postParam("Order", "order placed for purchasing the pet", true)
"params" : [].concat([]).concat([]).concat([params.body("body", "Order", "order placed for purchasing the pet", true)
]),
"responseClass" : "",
"errorResponses" : [errors.invalid('id'), errors.notFound('')],
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "placeOrder"
},
'action': function (req,res) {

View File

@@ -1,6 +1,7 @@
var swagger = require("swagger-node-express");
var url = require("url");
var errors = swagger.errors;
var params = swagger.params;
/* add model includes */
@@ -14,77 +15,17 @@ function writeResponse (response, data) {
exports.models = models = require("../models.js");
exports.createUsersWithArrayInput = {
'spec': {
"description" : "Operations about pets",
"path" : "/user.{format}/createWithArray",
"notes" : "",
"summary" : "Creates list of users with given input array",
"method": "POST",
"params" : [].concat([]).concat([]).concat([swagger.postParam("Array[User]", "List of user object", true)
]),
"responseClass" : "",
"errorResponses" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "createUsersWithArrayInput"
},
'action': function (req,res) {
if (!req.params.body) {
throw errors.invalid('body');
}
writeResponse(res, {message: "how about implementing createUsersWithArrayInput as a POST method?"});
}
};
exports.createUser = {
'spec': {
"description" : "Operations about pets",
"path" : "/user.{format}",
"notes" : "This can only be done by the logged in user.",
"summary" : "Create user",
"method": "POST",
"params" : [].concat([]).concat([]).concat([swagger.postParam("User", "Created user object", true)
]),
"responseClass" : "",
"errorResponses" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "createUser"
},
'action': function (req,res) {
if (!req.params.body) {
throw errors.invalid('body');
}
writeResponse(res, {message: "how about implementing createUser as a POST method?"});
}
};
exports.createUsersWithListInput = {
'spec': {
"description" : "Operations about pets",
"path" : "/user.{format}/createWithList",
"notes" : "",
"summary" : "Creates list of users with given list input",
"method": "POST",
"params" : [].concat([]).concat([]).concat([swagger.postParam("List[User]", "List of user object", true)
]),
"responseClass" : "",
"errorResponses" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "createUsersWithListInput"
},
'action': function (req,res) {
if (!req.params.body) {
throw errors.invalid('body');
}
writeResponse(res, {message: "how about implementing createUsersWithListInput as a POST method?"});
}
};
exports.updateUser = {
'spec': {
"description" : "Operations about pets",
"path" : "/user.{format}/{username}",
"path" : "/user/{username}",
"notes" : "This can only be done by the logged in user.",
"summary" : "Updated user",
"method": "PUT",
"params" : [].concat([swagger.pathParam("username", "name that need to be deleted")]).concat([]).concat([swagger.postParam("User", "Updated user object", true)
"params" : [].concat([params.path("username", "name that need to be deleted")]).concat([]).concat([params.body("body", "User", "Updated user object", true)
]),
"responseClass" : "",
"errorResponses" : [errors.invalid('id'), errors.notFound('')],
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "updateUser"
},
'action': function (req,res) {
@@ -100,13 +41,13 @@ exports.updateUser = {
exports.deleteUser = {
'spec': {
"description" : "Operations about pets",
"path" : "/user.{format}/{username}",
"path" : "/user/{username}",
"notes" : "This can only be done by the logged in user.",
"summary" : "Delete user",
"method": "DELETE",
"params" : [].concat([swagger.pathParam("username", "The name that needs to be deleted")]).concat([]).concat([]),
"responseClass" : "",
"errorResponses" : [errors.invalid('id'), errors.notFound('')],
"params" : [].concat([params.path("username", "The name that needs to be deleted")]).concat([]).concat([]),
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "deleteUser"
},
'action': function (req,res) {
@@ -119,13 +60,13 @@ exports.deleteUser = {
exports.getUserByName = {
'spec': {
"description" : "Operations about pets",
"path" : "/user.{format}/{username}",
"path" : "/user/{username}",
"notes" : "",
"summary" : "Get user by user name",
"method": "GET",
"params" : [].concat([swagger.pathParam("username", "The name that needs to be fetched. Use user1 for testing.")]).concat([]).concat([]),
"responseClass" : "User",
"errorResponses" : [errors.invalid('id'), errors.notFound('User')],
"params" : [].concat([params.path("username", "The name that needs to be fetched. Use user1 for testing.")]).concat([]).concat([]),
"type" : "User",
"responseMessages" : [errors.invalid('id'), errors.notFound('User')],
"nickname" : "getUserByName"
},
'action': function (req,res) {
@@ -138,13 +79,13 @@ exports.getUserByName = {
exports.loginUser = {
'spec': {
"description" : "Operations about pets",
"path" : "/user.{format}/login",
"path" : "/user/login",
"notes" : "",
"summary" : "Logs user into the system",
"method": "GET",
"params" : [swagger.queryParam("username", "The user name for login", "string", true, false, ""),swagger.queryParam("password", "The password for login in clear text", "string", true, false, "")].concat([]).concat([]).concat([]),
"responseClass" : "String",
"errorResponses" : [errors.invalid('id'), errors.notFound('String')],
"params" : [params.query("username", "The user name for login", "string", true, false, ""),params.query("password", "The password for login in clear text", "string", true, false, "")].concat([]).concat([]).concat([]),
"type" : "String",
"responseMessages" : [errors.invalid('id'), errors.notFound('String')],
"nickname" : "loginUser"
},
'action': function (req,res) {
@@ -160,17 +101,77 @@ exports.loginUser = {
exports.logoutUser = {
'spec': {
"description" : "Operations about pets",
"path" : "/user.{format}/logout",
"path" : "/user/logout",
"notes" : "",
"summary" : "Logs out current logged in user session",
"method": "GET",
"params" : [].concat([]).concat([]).concat([]),
"responseClass" : "",
"errorResponses" : [errors.invalid('id'), errors.notFound('')],
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "logoutUser"
},
'action': function (req,res) {
writeResponse(res, {message: "how about implementing logoutUser as a GET method?"});
}
};
exports.createUser = {
'spec': {
"description" : "Operations about pets",
"path" : "/user",
"notes" : "This can only be done by the logged in user.",
"summary" : "Create user",
"method": "POST",
"params" : [].concat([]).concat([]).concat([params.body("body", "User", "Created user object", true)
]),
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "createUser"
},
'action': function (req,res) {
if (!req.params.body) {
throw errors.invalid('body');
}
writeResponse(res, {message: "how about implementing createUser as a POST method?"});
}
};
exports.createUsersWithArrayInput = {
'spec': {
"description" : "Operations about pets",
"path" : "/user/createWithArray",
"notes" : "",
"summary" : "Creates list of users with given input array",
"method": "POST",
"params" : [].concat([]).concat([]).concat([params.body("body", "Array[User]", "List of user object", true)
]),
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "createUsersWithArrayInput"
},
'action': function (req,res) {
if (!req.params.body) {
throw errors.invalid('body');
}
writeResponse(res, {message: "how about implementing createUsersWithArrayInput as a POST method?"});
}
};
exports.createUsersWithListInput = {
'spec': {
"description" : "Operations about pets",
"path" : "/user/createWithList",
"notes" : "",
"summary" : "Creates list of users with given list input",
"method": "POST",
"params" : [].concat([]).concat([]).concat([params.body("body", "Array[User]", "List of user object", true)
]),
"type" : "",
"responseMessages" : [errors.invalid('id'), errors.notFound('')],
"nickname" : "createUsersWithListInput"
},
'action': function (req,res) {
if (!req.params.body) {
throw errors.invalid('body');
}
writeResponse(res, {message: "how about implementing createUsersWithListInput as a POST method?"});
}
};

View File

@@ -1,37 +1,56 @@
var express = require("express")
, url = require("url")
, cors = require("cors")
, swagger = require("swagger-node-express")
, db = false
var app = express();
app.use(express.bodyParser());
var corsOptions = {
credentials: true,
origin: function(origin,callback) {
if(origin===undefined) {
callback(null,false);
} else {
callback(null,true);
}
}
};
app.use(cors(corsOptions));
swagger.setAppHandler(app);
swagger.configureSwaggerPaths("", "api-docs", "")
// resources for the demo
var petApi = require("./apis/PetApi.js");
var storeApi = require("./apis/StoreApi.js");
var userApi = require("./apis/UserApi.js");
var models = require("./models.js");
var UserApi = require("./apis/UserApi.js");
var PetApi = require("./apis/PetApi.js");
var StoreApi = require("./apis/StoreApi.js");
swagger.addModels(models)
.addGET(petApi.getPetById)
.addPOST(petApi.addPet)
.addPUT(petApi.updatePet)
.addGET(petApi.findPetsByStatus)
.addGET(petApi.findPetsByTags)
.addGET(storeApi.getOrderById)
.addDELETE(storeApi.deleteOrder)
.addPOST(storeApi.placeOrder)
.addPOST(userApi.createUsersWithArrayInput)
.addPOST(userApi.createUser)
.addPOST(userApi.createUsersWithListInput)
.addPUT(userApi.updateUser)
.addDELETE(userApi.deleteUser)
.addGET(userApi.getUserByName)
.addGET(userApi.loginUser)
.addGET(userApi.logoutUser)
;
// configures the app
.addPUT(UserApi.updateUser)
.addDELETE(UserApi.deleteUser)
.addGET(UserApi.getUserByName)
.addGET(UserApi.loginUser)
.addGET(UserApi.logoutUser)
.addPOST(UserApi.createUser)
.addPOST(UserApi.createUsersWithArrayInput)
.addPOST(UserApi.createUsersWithListInput)
.addGET(PetApi.getPetById)
.addDELETE(PetApi.deletePet)
.addPATCH(PetApi.partialUpdate)
.addPOST(PetApi.updatePetWithForm)
.addPOST(PetApi.uploadFile)
.addPOST(PetApi.addPet)
.addPUT(PetApi.updatePet)
.addGET(PetApi.findPetsByStatus)
.addGET(PetApi.findPetsByTags)
.addGET(StoreApi.getOrderById)
.addDELETE(StoreApi.deleteOrder)
.addPOST(StoreApi.placeOrder)
;
// configures the app
swagger.configure("http://localhost:8002", "0.1");
// start the server

View File

@@ -1,2 +1,129 @@
exports.models = {
"Pet": {"id":"Pet","name":"","properties":{"name":{"type":"string","required":false},"tags":{"type":"Array","required":false,"items":{"$ref":"Tag"}},"photoUrls":{"type":"Array","required":false,"items":{"type":"string"}},"id":{"type":"long","required":false},"status":{"type":"string","required":false,"description":"pet status in the store"},"category":{"type":"Category","required":false}}},"Category": {"id":"Category","name":"","properties":{"id":{"type":"long","required":false},"name":{"type":"string","required":false}}},"Tag": {"id":"Tag","name":"","properties":{"id":{"type":"long","required":false},"name":{"type":"string","required":false}}},"User": {"id":"User","name":"","properties":{"email":{"type":"string","required":false},"username":{"type":"string","required":false},"userStatus":{"type":"int","required":false,"description":"User Status"},"lastName":{"type":"string","required":false},"firstName":{"type":"string","required":false},"id":{"type":"long","required":false},"phone":{"type":"string","required":false},"password":{"type":"string","required":false}}},"Order": {"id":"Order","name":"","properties":{"shipDate":{"type":"Date","required":false},"quantity":{"type":"int","required":false},"petId":{"type":"long","required":false},"id":{"type":"long","required":false},"status":{"type":"string","required":false,"description":"Order Status"}}}}
"Tag": {
"id" : "Tag",
"name" : "",
"properties" : {
"id" : {
"type" : "integer",
"format" : "int64"
},
"name" : {
"type" : "string"
}
}
},
"User": {
"id" : "User",
"name" : "",
"properties" : {
"email" : {
"type" : "string"
},
"username" : {
"type" : "string"
},
"userStatus" : {
"type" : "integer",
"format" : "int32",
"description" : "User Status",
"enum" : [ "1-registered", "2-active", "3-closed" ]
},
"lastName" : {
"type" : "string"
},
"firstName" : {
"type" : "string"
},
"id" : {
"type" : "integer",
"format" : "int64"
},
"phone" : {
"type" : "string"
},
"password" : {
"type" : "string"
}
}
},
"Order": {
"id" : "Order",
"name" : "",
"properties" : {
"shipDate" : {
"type" : "string",
"format" : "date-time"
},
"quantity" : {
"type" : "integer",
"format" : "int32"
},
"petId" : {
"type" : "integer",
"format" : "int64"
},
"id" : {
"type" : "integer",
"format" : "int64"
},
"status" : {
"type" : "string",
"description" : "Order Status",
"enum" : [ "placed", " approved", " delivered" ]
}
}
},
"Category": {
"id" : "Category",
"name" : "",
"properties" : {
"id" : {
"type" : "integer",
"format" : "int64"
},
"name" : {
"type" : "string"
}
}
},
"Pet": {
"id" : "Pet",
"name" : "",
"required" : [ "id", "name" ],
"properties" : {
"name" : {
"type" : "string"
},
"tags" : {
"type" : "array",
"items" : {
"$ref" : "Tag"
}
},
"photoUrls" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
"id" : {
"type" : "integer",
"format" : "int64",
"description" : "unique identifier for the pet"
},
"status" : {
"type" : "string",
"description" : "pet status in the store",
"enum" : [ "available", "pending", "sold" ]
},
"category" : {
"type" : "Category"
}
}
}
}

View File

@@ -1,18 +1,16 @@
{
"name": "sample-app",
"description": "Wordnik node.js server generator",
"version": "1.0.0",
"homepage": "https://github.com/wordnik/swagger-codegen",
"main": "./Common/node/swagger.js",
"directories": {
"lib": "./Common/node"
},
"engines": {
"node": ">= 0.8.x"
},
"dependencies": {
"swagger-node-express": ">= 1.2.x",
"connect": ">= 1.8.x",
"express": "3.x"
}
"name": "swagger-sample-app",
"description": "Wordnik node.js server generator",
"version": "1.0.0",
"homepage": "http://swagger.wordnik.com",
"main": "./app/main.js",
"engines": {
"node": ">= 0.8.x"
},
"dependencies": {
"swagger-node-express": ">= 2.0.x",
"connect": ">= 1.8.x",
"cors": "2.1.1",
"express": "3.x"
}
}

View File

@@ -23,7 +23,7 @@ exports.{{nickname}} = {
"path" : "{{path}}",
"notes" : "{{{notes}}}",
"summary" : "{{{summary}}}",
"httpMethod": "{{httpMethod}}",
"method": "{{httpMethod}}",
"params" : [{{#queryParams}}
params.query("{{paramName}}", "{{description}}", "{{swaggerDataType}}", {{required}}, {{allowMultiple}}, "{{{allowableValues}}}"{{#defaultValue}}, {{{defaultValue}}}{{/defaultValue}}){{#hasMore}},{{/hasMore}}
{{/queryParams}}].concat([{{#pathParams}}
@@ -31,10 +31,10 @@ exports.{{nickname}} = {
{{/pathParams}}]).concat([{{#headerParams}}
params.header("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
{{/headerParams}}]).concat([{{#bodyParams}}
params.body("body", "{{swaggerDataType}}", "{{description}}", {{required}})
params.body("body", "{{swaggerDataType}}", "{{description}}", {{#required}}{{required}}{{/required}}{{^required}}false{{/required}})
{{/bodyParams}}]),
"responseClass" : "{{returnType}}",
"errorResponses" : [errors.invalid('id'), errors.notFound('{{returnType}}')],
"type" : "{{returnType}}",
"responseMessages" : [errors.invalid('id'), errors.notFound('{{returnType}}')],
"nickname" : "{{nickname}}"
},
'action': function (req,res) {

View File

@@ -1,23 +1,44 @@
var express = require("express")
, url = require("url")
, cors = require("cors")
, swagger = require("swagger-node-express")
, db = false
var app = express();
app.use(express.bodyParser());
swagger.setAppHandler(app);
var corsOptions = {
credentials: true,
origin: function(origin,callback) {
if(origin===undefined) {
callback(null,false);
} else {
callback(null,true);
}
}
};
app.use(cors(corsOptions));
swagger.setAppHandler(app);
swagger.configureSwaggerPaths("", "api-docs", "")
var models = require("./models.js");
{{#apiInfo}}
{{#apis}}
var {{name}}Api = require("./apis/{{className}}.js");
var {{name}} = require("./{{apiFolder}}/{{classname}}.js");
{{/apis}}
{{/apiInfo}}
swagger.addModels(models)
{{#apiInfo}}
{{#apis}}
{{#operations}}
{{#operation}}.add{{method}}({{name}}Api.{{nickname}}){{/operation}}{{newline}}
{{#operation}}.add{{httpMethod}}({{name}}.{{nickname}}){{newline}}{{/operation}}
{{/operations}}
{{/apis}};
{{/apiInfo}}
// configures the app
swagger.configure("http://localhost:8002", "0.1");

View File

@@ -1,5 +1,7 @@
exports.models = {
{{#models}}
"{{modelName}}": {{{modelJson}}}{{#hasMore}},{{/hasMore}}
{{/models}}
{{#model}}
"{{classVarName}}": {{{modelJson}}}{{#hasMoreModels}},{{/hasMoreModels}}{{newline}}
{{/model}}
{{/models}}
}

View File

@@ -1,18 +0,0 @@
{
"name": "sample-app",
"description": "Wordnik node.js server generator",
"version": "1.0.0",
"homepage": "https://github.com/wordnik/swagger-codegen",
"main": "./Common/node/swagger.js",
"directories": {
"lib": "./Common/node"
},
"engines": {
"node": ">= 0.8.x"
},
"dependencies": {
"swagger-node-express": ">= 1.2.x",
"connect": ">= 1.8.x",
"express": "3.x"
}
}

View File

@@ -0,0 +1,16 @@
{
"name": "{{{artifactId}}}",
"description": "Wordnik node.js server generator",
"version": "{{{artifactVersion}}}",
"homepage": "{{{homepage}}}",
"main": "./{{codeDir}}/main.js",
"engines": {
"node": ">= 0.8.x"
},
"dependencies": {
"swagger-node-express": ">= 2.0.x",
"connect": ">= 1.8.x",
"cors": "2.1.1",
"express": "3.x"
}
}