mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 10:58:55 +00:00
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 {
|
||||
"name" : name,
|
||||
"description" : description,
|
||||
"dataType" : dataType,
|
||||
"dataType" : dataType = "string",
|
||||
"required" : true,
|
||||
"allowMultiple" : false,
|
||||
"allowableValues" : createEnum(allowableValues),
|
||||
|
@ -310,10 +310,7 @@ function resourceListing(request, response) {
|
||||
r.apis.push({"path": "/" + key, "description": "none"});
|
||||
}
|
||||
|
||||
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");
|
||||
writeHeaders(response);
|
||||
|
||||
response.write(JSON.stringify(r));
|
||||
response.end();
|
||||
@ -361,11 +358,7 @@ function addMethod(app, callback, spec) {
|
||||
var currentMethod = spec.method.toLowerCase();
|
||||
if (allowedMethods.indexOf(currentMethod)>-1) {
|
||||
app[currentMethod](fullPath, function(req,res) {
|
||||
res.header('Access-Control-Allow-Origin', "*");
|
||||
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");
|
||||
writeHeaders(res);
|
||||
|
||||
if (!canAccessResource(req, req.url.substr(1).split('?')[0].replace('.json', '.*'), req.method)) {
|
||||
res.send(JSON.stringify({"description":"forbidden", "code":403}), 403);
|
||||
@ -457,6 +450,13 @@ function wrap(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) {
|
||||
if (!api.description) {
|
||||
api.description = spec.description;
|
||||
|
@ -23,8 +23,8 @@ exports.getPetById = {
|
||||
"summary" : "Find pet by ID",
|
||||
"method": "GET",
|
||||
"params" : [].concat([param.path("petId", "ID of pet that needs to be fetched")]).concat([]).concat([]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"responseClass" : "Pet",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('Pet')],
|
||||
"nickname" : "getPetById"
|
||||
},
|
||||
'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)
|
||||
]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('')],
|
||||
"nickname" : "addPet"
|
||||
},
|
||||
'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)
|
||||
]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('')],
|
||||
"nickname" : "updatePet"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
@ -81,9 +81,9 @@ exports.findPetsByStatus = {
|
||||
"notes" : "Multiple status values can be provided with comma seperated strings",
|
||||
"summary" : "Finds Pets by status",
|
||||
"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([]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"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" : "List[Pet]",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('List[Pet]')],
|
||||
"nickname" : "findPetsByStatus"
|
||||
},
|
||||
'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.",
|
||||
"summary" : "Finds Pets by tags",
|
||||
"method": "GET",
|
||||
"params" : [param.query("tags", "Tags to filter by", "String", true, true, "")].concat([]).concat([]).concat([]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"params" : [param.query("tags", "Tags to filter by", "string", true, true, "")].concat([]).concat([]).concat([]),
|
||||
"responseClass" : "List[Pet]",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('List[Pet]')],
|
||||
"nickname" : "findPetsByTags"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
|
@ -23,8 +23,8 @@ exports.getOrderById = {
|
||||
"summary" : "Find purchase order by ID",
|
||||
"method": "GET",
|
||||
"params" : [].concat([param.path("orderId", "ID of pet that needs to be fetched")]).concat([]).concat([]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"responseClass" : "Order",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('Order')],
|
||||
"nickname" : "getOrderById"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
@ -43,7 +43,7 @@ exports.deleteOrder = {
|
||||
"method": "DELETE",
|
||||
"params" : [].concat([param.path("orderId", "ID of the order that needs to be deleted")]).concat([]).concat([]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('')],
|
||||
"nickname" : "deleteOrder"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
@ -63,7 +63,7 @@ exports.placeOrder = {
|
||||
"params" : [].concat([]).concat([]).concat([param.post("Order", "order placed for purchasing the pet", true)
|
||||
]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('')],
|
||||
"nickname" : "placeOrder"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
|
@ -25,7 +25,7 @@ exports.createUsersWithArrayInput = {
|
||||
"params" : [].concat([]).concat([]).concat([param.post("Array[User]", "List of user object", true)
|
||||
]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('')],
|
||||
"nickname" : "createUsersWithArrayInput"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
@ -45,7 +45,7 @@ exports.createUser = {
|
||||
"params" : [].concat([]).concat([]).concat([param.post("User", "Created user object", true)
|
||||
]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('')],
|
||||
"nickname" : "createUser"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
@ -65,7 +65,7 @@ exports.createUsersWithListInput = {
|
||||
"params" : [].concat([]).concat([]).concat([param.post("List[User]", "List of user object", true)
|
||||
]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('')],
|
||||
"nickname" : "createUsersWithListInput"
|
||||
},
|
||||
'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)
|
||||
]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('')],
|
||||
"nickname" : "updateUser"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
@ -107,7 +107,7 @@ exports.deleteUser = {
|
||||
"method": "DELETE",
|
||||
"params" : [].concat([param.path("username", "The name that needs to be deleted")]).concat([]).concat([]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('')],
|
||||
"nickname" : "deleteUser"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
@ -125,8 +125,8 @@ exports.getUserByName = {
|
||||
"summary" : "Get user by user name",
|
||||
"method": "GET",
|
||||
"params" : [].concat([param.path("username", "The name that needs to be fetched. Use user1 for testing.")]).concat([]).concat([]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"responseClass" : "User",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('User')],
|
||||
"nickname" : "getUserByName"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
@ -143,9 +143,9 @@ exports.loginUser = {
|
||||
"notes" : "",
|
||||
"summary" : "Logs user into the system",
|
||||
"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([]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"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" : "String",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('String')],
|
||||
"nickname" : "loginUser"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
@ -167,7 +167,7 @@ exports.logoutUser = {
|
||||
"method": "GET",
|
||||
"params" : [].concat([]).concat([]).concat([]),
|
||||
"responseClass" : "",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('')],
|
||||
"nickname" : "logoutUser"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
|
@ -9,26 +9,26 @@ app.use(express.bodyParser());
|
||||
swagger.setAppHandler(app);
|
||||
|
||||
// resources for the demo
|
||||
var UserApi = require("./apis/UserApi.js");
|
||||
var StoreApi = require("./apis/StoreApi.js");
|
||||
var PetApi = require("./apis/PetApi.js");
|
||||
var petApi = require("./apis/PetApi.js");
|
||||
var storeApi = require("./apis/StoreApi.js");
|
||||
var userApi = require("./apis/UserApi.js");
|
||||
swagger.addModels(models)
|
||||
.addPOST(UserApi.createUsersWithArrayInput)
|
||||
.addPOST(UserApi.createUser)
|
||||
.addPOST(UserApi.createUsersWithListInput)
|
||||
.addPUT(UserApi.updateUser)
|
||||
.addDELETE(UserApi.deleteUser)
|
||||
.addGET(UserApi.getUserByName)
|
||||
.addGET(UserApi.loginUser)
|
||||
.addGET(UserApi.logoutUser)
|
||||
.addGET(StoreApi.getOrderById)
|
||||
.addDELETE(StoreApi.deleteOrder)
|
||||
.addPOST(StoreApi.placeOrder)
|
||||
.addGET(PetApi.getPetById)
|
||||
.addPOST(PetApi.addPet)
|
||||
.addPUT(PetApi.updatePet)
|
||||
.addGET(PetApi.findPetsByStatus)
|
||||
.addGET(PetApi.findPetsByTags)
|
||||
.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
|
||||
|
@ -26,7 +26,7 @@ exports.path = function(name, description, dataType, allowableValues) {
|
||||
return {
|
||||
"name" : name,
|
||||
"description" : description,
|
||||
"dataType" : dataType,
|
||||
"dataType" : dataType = "string",
|
||||
"required" : true,
|
||||
"allowMultiple" : false,
|
||||
"allowableValues" : createEnum(allowableValues),
|
||||
|
@ -310,10 +310,7 @@ function resourceListing(request, response) {
|
||||
r.apis.push({"path": "/" + key, "description": "none"});
|
||||
}
|
||||
|
||||
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");
|
||||
writeHeaders(response);
|
||||
|
||||
response.write(JSON.stringify(r));
|
||||
response.end();
|
||||
@ -361,11 +358,7 @@ function addMethod(app, callback, spec) {
|
||||
var currentMethod = spec.method.toLowerCase();
|
||||
if (allowedMethods.indexOf(currentMethod)>-1) {
|
||||
app[currentMethod](fullPath, function(req,res) {
|
||||
res.header('Access-Control-Allow-Origin', "*");
|
||||
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");
|
||||
writeHeaders(res);
|
||||
|
||||
if (!canAccessResource(req, req.url.substr(1).split('?')[0].replace('.json', '.*'), req.method)) {
|
||||
res.send(JSON.stringify({"description":"forbidden", "code":403}), 403);
|
||||
@ -457,6 +450,13 @@ function wrap(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) {
|
||||
if (!api.description) {
|
||||
api.description = spec.description;
|
||||
|
@ -25,16 +25,16 @@ exports.{{nickname}} = {
|
||||
"summary" : "{{{summary}}}",
|
||||
"method": "{{httpMethod}}",
|
||||
"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}}
|
||||
param.path("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
|
||||
{{/pathParams}}]).concat([{{#headerParams}}
|
||||
param.header("{{paramName}}", "{{description}}"){{#hasMore}},{{/hasMore}}
|
||||
{{/headerParams}}]).concat([{{#bodyParams}}
|
||||
param.post("{{dataType}}", "{{description}}", {{required}})
|
||||
param.post("{{swaggerDataType}}", "{{description}}", {{required}})
|
||||
{{/bodyParams}}]),
|
||||
"responseClass" : "{{responseClass}}",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('pet')],
|
||||
"responseClass" : "{{returnType}}",
|
||||
"errorResponses" : [swe.invalid('id'), swe.notFound('{{returnType}}')],
|
||||
"nickname" : "{{nickname}}"
|
||||
},
|
||||
'action': function (req,res) {
|
||||
|
@ -10,13 +10,13 @@ swagger.setAppHandler(app);
|
||||
|
||||
// resources for the demo
|
||||
{{#apis}}
|
||||
var {{name}} = require("./apis/{{name}}.js");
|
||||
var {{name}}Api = require("./apis/{{className}}.js");
|
||||
{{/apis}}
|
||||
|
||||
swagger.addModels(models)
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
{{#operation}}.add{{httpMethod}}({{name}}.{{nickname}}){{/operation}}{{newline}}
|
||||
{{#operation}}.add{{httpMethod}}({{name}}Api.{{nickname}}){{/operation}}{{newline}}
|
||||
{{/operations}}
|
||||
{{/apis}};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user