Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
'use strict';

var url = require('url');

{{#operations}}

var {{classname}} = require('./{{classname}}Service');

{{#operation}}

module.exports.{{nickname}} = function {{nickname}} (req, res, next) {
{{classname}}.{{nickname}}(req.swagger.params, res, next);
};
{{/operation}}
{{/operations}}
{{/operations}}
34 changes: 24 additions & 10 deletions modules/swagger-codegen/src/main/resources/nodejs/service.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,40 @@

{{#operations}}
{{#operation}}
exports.{{nickname}} = function(args, res, next) {
exports.{{{operationId}}} = function(args, res, next) {
/**
* parameters expected in the args:
{{#allParams}}* {{paramName}} ({{dataType}})
{{/allParams}}**/
{{^returnType}}// no response value expected for this operation
{{#summary}}
* {{{summary}}}
{{/summary}}
{{#notes}}
* {{{notes}}}
{{/notes}}
*
{{#allParams}}
* {{paramName}} {{{dataType}}} {{{description}}}{{^required}} (optional){{/required}}
{{/allParams}}
{{^returnType}}
* no response value expected for this operation
{{/returnType}}
{{#returnType}}
* returns {{{returnType}}}
{{/returnType}}
**/
{{#returnType}}
var examples = {};
{{#examples}}examples['{{contentType}}'] = {{{example}}};
{{#examples}}
examples['{{contentType}}'] = {{{example}}};
{{/examples}}
if(Object.keys(examples).length > 0) {
if (Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
} else {
res.end();
}
{{/returnType}}
{{^returnType}}res.end();{{/returnType}}
{{^returnType}}
res.end();
{{/returnType}}
}

{{/operation}}
Expand Down
2 changes: 0 additions & 2 deletions samples/server/petstore/nodejs/controllers/Pet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

var url = require('url');


var Pet = require('./PetService');


module.exports.addPet = function addPet (req, res, next) {
Pet.addPet(req.swagger.params, res, next);
};
Expand Down
118 changes: 65 additions & 53 deletions samples/server/petstore/nodejs/controllers/PetService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,36 @@

exports.addPet = function(args, res, next) {
/**
* parameters expected in the args:
* body (Pet)
**/
// no response value expected for this operation
* Add a new pet to the store
*
*
* body Pet Pet object that needs to be added to the store
* no response value expected for this operation
**/
res.end();
}

exports.deletePet = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
* api_key (String)
**/
// no response value expected for this operation
* Deletes a pet
*
*
* petId Long Pet id to delete
* api_key String (optional)
* no response value expected for this operation
**/
res.end();
}

exports.findPetsByStatus = function(args, res, next) {
/**
* parameters expected in the args:
* status (List)
**/
var examples = {};
* Finds Pets by status
* Multiple status values can be provided with comma separated strings
*
* status List Status values that need to be considered for filter
* returns List
**/
var examples = {};
examples['application/json'] = [ {
"tags" : [ {
"id" : 123456789,
Expand All @@ -39,22 +46,23 @@ exports.findPetsByStatus = function(args, res, next) {
"name" : "doggie",
"photoUrls" : [ "aeiou" ]
} ];
if(Object.keys(examples).length > 0) {
if (Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
} else {
res.end();
}

}

exports.findPetsByTags = function(args, res, next) {
/**
* parameters expected in the args:
* tags (List)
**/
var examples = {};
* Finds Pets by tags
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
*
* tags List Tags to filter by
* returns List
**/
var examples = {};
examples['application/json'] = [ {
"tags" : [ {
"id" : 123456789,
Expand All @@ -69,22 +77,23 @@ exports.findPetsByTags = function(args, res, next) {
"name" : "doggie",
"photoUrls" : [ "aeiou" ]
} ];
if(Object.keys(examples).length > 0) {
if (Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
} else {
res.end();
}

}

exports.getPetById = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
**/
var examples = {};
* Find pet by ID
* Returns a single pet
*
* petId Long ID of pet to return
* returns Pet
**/
var examples = {};
examples['application/json'] = {
"tags" : [ {
"id" : 123456789,
Expand All @@ -99,56 +108,59 @@ exports.getPetById = function(args, res, next) {
"name" : "doggie",
"photoUrls" : [ "aeiou" ]
};
if(Object.keys(examples).length > 0) {
if (Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
} else {
res.end();
}

}

exports.updatePet = function(args, res, next) {
/**
* parameters expected in the args:
* body (Pet)
**/
// no response value expected for this operation
* Update an existing pet
*
*
* body Pet Pet object that needs to be added to the store
* no response value expected for this operation
**/
res.end();
}

exports.updatePetWithForm = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
* name (String)
* status (String)
**/
// no response value expected for this operation
* Updates a pet in the store with form data
*
*
* petId Long ID of pet that needs to be updated
* name String Updated name of the pet (optional)
* status String Updated status of the pet (optional)
* no response value expected for this operation
**/
res.end();
}

exports.uploadFile = function(args, res, next) {
/**
* parameters expected in the args:
* petId (Long)
* additionalMetadata (String)
* file (file)
**/
var examples = {};
* uploads an image
*
*
* petId Long ID of pet to update
* additionalMetadata String Additional data to pass to server (optional)
* file File file to upload (optional)
* returns ApiResponse
**/
var examples = {};
examples['application/json'] = {
"message" : "aeiou",
"code" : 123,
"type" : "aeiou"
};
if(Object.keys(examples).length > 0) {
if (Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
} else {
res.end();
}

}

2 changes: 0 additions & 2 deletions samples/server/petstore/nodejs/controllers/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

var url = require('url');


var Store = require('./StoreService');


module.exports.deleteOrder = function deleteOrder (req, res, next) {
Store.deleteOrder(req.swagger.params, res, next);
};
Expand Down
59 changes: 32 additions & 27 deletions samples/server/petstore/nodejs/controllers/StoreService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,43 @@

exports.deleteOrder = function(args, res, next) {
/**
* parameters expected in the args:
* orderId (String)
**/
// no response value expected for this operation
* Delete purchase order by ID
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
*
* orderId String ID of the order that needs to be deleted
* no response value expected for this operation
**/
res.end();
}

exports.getInventory = function(args, res, next) {
/**
* parameters expected in the args:
**/
var examples = {};
* Returns pet inventories by status
* Returns a map of status codes to quantities
*
* returns Map
**/
var examples = {};
examples['application/json'] = {
"key" : 123
};
if(Object.keys(examples).length > 0) {
if (Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
} else {
res.end();
}

}

exports.getOrderById = function(args, res, next) {
/**
* parameters expected in the args:
* orderId (Long)
**/
var examples = {};
* Find purchase order by ID
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
*
* orderId Long ID of pet that needs to be fetched
* returns Order
**/
var examples = {};
examples['application/json'] = {
"id" : 123456789,
"petId" : 123456789,
Expand All @@ -41,22 +47,23 @@ exports.getOrderById = function(args, res, next) {
"quantity" : 123,
"shipDate" : "2000-01-23T04:56:07.000+00:00"
};
if(Object.keys(examples).length > 0) {
if (Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
} else {
res.end();
}

}

exports.placeOrder = function(args, res, next) {
/**
* parameters expected in the args:
* body (Order)
**/
var examples = {};
* Place an order for a pet
*
*
* body Order order placed for purchasing the pet
* returns Order
**/
var examples = {};
examples['application/json'] = {
"id" : 123456789,
"petId" : 123456789,
Expand All @@ -65,13 +72,11 @@ exports.placeOrder = function(args, res, next) {
"quantity" : 123,
"shipDate" : "2000-01-23T04:56:07.000+00:00"
};
if(Object.keys(examples).length > 0) {
if (Object.keys(examples).length > 0) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(examples[Object.keys(examples)[0]] || {}, null, 2));
}
else {
} else {
res.end();
}

}

Loading