added all routes to swagger

This commit is contained in:
David Baldwynn 2016-08-26 15:09:16 -07:00
parent 74c4f0b416
commit b195b0f813
5 changed files with 337 additions and 142 deletions

View file

@ -174,7 +174,6 @@ exports.signin = function(req, res, next) {
*/ */
exports.signout = function(req, res) { exports.signout = function(req, res) {
req.logout(); req.logout();
//res.redirect('/');
return res.status(200).send('You have successfully logged out.'); return res.status(200).send('You have successfully logged out.');
}; };

View file

@ -23,7 +23,9 @@ exports.userByID = function (req, res, next, id) {
if (err) { if (err) {
return next(err); return next(err);
} else if (!user) { } else if (!user) {
return next(new Error('Failed to load User ' + id)); return res.status(404).send({
message: 'User does not exist'
});
} }
req.profile = user; req.profile = user;

View file

@ -27,13 +27,13 @@ exports.update = function(req, res) {
user.save(function(err) { user.save(function(err) {
if (err) { if (err) {
return res.status(400).send({ return res.status(500).send({
message: errorHandler.getErrorMessage(err) message: errorHandler.getErrorMessage(err)
}); });
} else { } else {
req.login(user, function(err) { req.login(user, function(err) {
if (err) { if (err) {
res.status(400).send(err); res.status(500).send(err);
} else { } else {
res.json(user); res.json(user);
} }
@ -41,7 +41,7 @@ exports.update = function(req, res) {
} }
}); });
} else { } else {
res.status(400).send({ res.status(401).send({
message: 'User is not signed in' message: 'User is not signed in'
}); });
} }

View file

@ -14,14 +14,14 @@ module.exports = function(app) {
// Setting up the users profile api // Setting up the users profile api
app.route('/users/me').get(auth.isAuthenticatedOrApiKey, users.getUser); app.route('/users/me').get(auth.isAuthenticatedOrApiKey, users.getUser);
app.route('/users').put(auth.isAuthenticatedOrApiKey, users.update); app.route('/users').put(auth.isAuthenticatedOrApiKey, users.update);
app.route('/users/accounts').delete(auth.isAuthenticatedOrApiKey, users.removeOAuthProvider); app.route('/users/accounts').delete(users.requiresLogin, users.removeOAuthProvider);
// Setting up the users account verification api // Setting up the users account verification api
app.route('/auth/verify/:token').get(users.validateVerificationToken); app.route('/auth/verify/:token').get(users.validateVerificationToken);
app.route('/auth/verify').post(users.resendVerificationEmail); app.route('/auth/verify').post(users.resendVerificationEmail);
// Setting up the users password api // Setting up the users password api
app.route('/users/password').post(auth.isAuthenticatedOrApiKey, users.changePassword); app.route('/users/password').post(users.requiresLogin, users.changePassword);
app.route('/auth/forgot').post(users.forgot); app.route('/auth/forgot').post(users.forgot);
app.route('/auth/reset/:token').get(users.validateResetToken); app.route('/auth/reset/:token').get(users.validateResetToken);
app.route('/auth/reset/:token').post(users.reset); app.route('/auth/reset/:token').post(users.reset);

View file

@ -5,21 +5,43 @@
"title": "TellForm API", "title": "TellForm API",
"contact": { "contact": {
"name": "TellForm Team", "name": "TellForm Team",
"url": "http://www.tellform.com" "email": "team@tellform.com"
} }
}, },
"externalDocs": {
"description": "Find out how to host your own TellForm instance.",
"url": "https://github.com/whitef0x0/tellform"
},
"host": "api.tellform.com", "host": "api.tellform.com",
"basePath": "/api", "basePath": "/",
"schemes": [ "schemes": [
"http" "http",
"https"
], ],
"tags": [
{
"name": "form",
"description": "Everything about your Forms"
},
{
"name": "user",
"description": "Everything about your Account"
}
],
"securityDefinitions": {
"api_key": {
"type": "apiKey",
"name": "apikey",
"in": "header"
}
},
"paths": { "paths": {
"/forms": { "/forms": {
"get": { "get": {
"tags": [ "tags": [
"Form Operations" "form"
], ],
"summary": "Finds all forms", "summary": "Find all forms",
"responses": { "responses": {
"405": { "405": {
"description": "Missing Form Input" "description": "Missing Form Input"
@ -37,20 +59,20 @@
"items": { "items": {
"$ref": "#/definitions/Form" "$ref": "#/definitions/Form"
} }
},
"headers": {
"x-expires": {
"type": "string"
}
} }
} }
} },
"security": [
{
"api_key": []
}
]
} }
}, },
"/form/:form_id": { "/form/:form_id": {
"get": { "get": {
"tags": [ "tags": [
"Form Operations" "form"
], ],
"summary": "Find form by ID", "summary": "Find form by ID",
"responses": { "responses": {
@ -65,11 +87,16 @@
} }
} }
} }
} },
"security": [
{
"api_key": []
}
]
}, },
"post": { "post": {
"tags": [ "tags": [
"Form Operations" "form"
], ],
"summary": "Create a new form", "summary": "Create a new form",
"description": "Create and save a new form", "description": "Create and save a new form",
@ -83,7 +110,7 @@
"parameters": [ "parameters": [
{ {
"in": "body", "in": "body",
"name": "form", "name": "body",
"description": "Form object that is to be created", "description": "Form object that is to be created",
"required": true, "required": true,
"schema": { "schema": {
@ -109,23 +136,24 @@
} }
}, },
"security": [ "security": [
{
"api_key": []
}
], ],
"x-code-samples": [ "x-code-samples": [
] ]
}, },
"put": { "put": {
"tags": [ "tags": [
"Form Operations" "form"
], ],
"summary": "Update an existing form", "summary": "Update an existing form",
"description": "", "description": "",
"operationId": "updateForm", "operationId": "updateForm",
"consumes": [ "consumes": [
"application/json", "application/json"
"application/xml"
], ],
"produces": [ "produces": [
"application/xml",
"application/json" "application/json"
], ],
"parameters": [ "parameters": [
@ -158,6 +186,99 @@
}, },
"security": [ "security": [
{ {
"api_key": []
}
],
"x-code-samples": [
]
}
},
"/users/me": {
"get": {
"tags": [
"user"
],
"summary": "Retrieve current User",
"description": "",
"operationId": "getUser",
"produces": [
"application/json"
],
"responses": {
"500": {
"description": "Could not Update User"
},
"401": {
"description": "User is not Signed in"
},
"403": {
"description": "User is not Authorized"
},
"404": {
"description": "User does not exsit"
},
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/User"
}
}
},
"security": [
{
"api_key": []
}
]
}
},
"/users": {
"put": {
"tags": [
"user"
],
"summary": "Update the current user",
"description": "",
"operationId": "updateUser",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "User object that needs to be updated",
"required": true,
"schema": {
"$ref": "#/definitions/User"
}
}
],
"responses": {
"500": {
"description": "Could not Update User"
},
"401": {
"description": "User is not Signed in"
},
"403": {
"description": "User is not Authorized"
},
"404": {
"description": "User does not exsit"
},
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/User"
}
}
},
"security": [
{
"api_key": []
} }
], ],
"x-code-samples": [ "x-code-samples": [
@ -175,14 +296,15 @@
"username" "username"
], ],
"properties": { "properties": {
"id": {
"type": "string",
},
"firstName": { "firstName": {
"type": "string" "type": "string",
"description": "First name of User",
"example": "John"
}, },
"lastName": { "lastName": {
"type": "string" "type": "string",
"description": "First name of User",
"example": "Doe"
}, },
"language": { "language": {
"type": "string", "type": "string",
@ -194,36 +316,24 @@
"de" "de"
], ],
"default": "en", "default": "en",
"required": "User must have a language" "required": "User must have a language",
"description": "Language of User (for internationalization)",
"example": "fr"
}, },
"email": { "email": {
"type": "string", "type": "string",
"format": "email", "format": "email",
"required": "User email cannot be blank", "required": "User email cannot be blank",
"unique": "true" "unique": "true",
"description": "Email of User",
"example": "john.doe@somewhere.com"
}, },
"username": { "username": {
"type": "string", "type": "string",
"required": "Username cannot be blank", "required": "Username cannot be blank",
"unique": "true" "unique": "true",
}, "description": "Username of User",
"passwordHash": { "example": "johndoe"
"type": "string",
"default": ""
},
"salt": {
"type": "string"
},
"provider": {
"type": "string",
"required": "provider is required",
"default": "local"
},
"providerData": {
"type": "object"
},
"additionalProvidersData": {
"type": "object"
}, },
"roles": { "roles": {
"type": "array", "type": "array",
@ -235,31 +345,42 @@
"superuser" "superuser"
] ]
}, },
"default": [ "default": [ "user" ],
"user" "description": "Security Roles of User"
]
} }
}, },
"lastModified": { "lastModified": {
"type": "date" "type": "date",
"description": "Date that user was last modified",
"example": "2016-08-26T20:19:30.146Z"
}, },
"created": { "created": {
"type": "date" "type": "date",
"description": "Date that user was created on",
"example": "5dHuKJgeCZmFOdJTnmg0lrxApmz0tbbBrM59rTv4k79"
}, },
"resetPasswordToken": { "resetPasswordToken": {
"type": "string" "type": "string",
"description": "Reset password token of User",
"example": "5dHuKJgeCZmFOdJTnmg0lrxApmz0tbbBrM59rTv4k79"
}, },
"resetPasswordExpires": { "resetPasswordExpires": {
"type": "date" "type": "date",
"example": "2016-08-26T20:19:30.146Z",
"description": "Date that the User's password reset token expires"
}, },
"token": { "token": {
"type": "string" "type": "string",
"description": "Verification token of User",
"example": "5dHuKJgeCZmFOdJTnmg0lrxApmz0tbbBrM59rTv4k79"
}, },
"apiKey": { "apiKey": {
"type": "string", "type": "string",
"unique": true, "unique": true,
"index": true, "index": true,
"sparse": true "sparse": true,
"description": "API Key of User",
"example": "5dHuKJgeCZmFOdJTnmg0lrxApmz0tbbBrM59rTv4k79"
} }
}, },
"LogicJump": { "LogicJump": {
@ -281,13 +402,13 @@
] ]
}, },
"fieldA": { "fieldA": {
$ref: "#/definitions/FormField", "$ref": "#/definitions/FormField"
}, },
"valueB": { "valueB": {
"type": "string" "type": "string"
}, },
"jumpTo": { "jumpTo": {
"$ref": "#/definitions/FormField", "$ref": "#/definitions/FormField"
} }
}, },
"FieldOption": { "FieldOption": {
@ -347,41 +468,57 @@
"properties": { "properties": {
"isSubmission": { "isSubmission": {
"type": "boolean", "type": "boolean",
"default": false "default": false,
"description": "Specifies whether Field is part of a Submission or not",
"example": true
}, },
"submissionId": { "submissionId": {
"type": "string" "type": "string",
"description": "ID of Submission that this Field belongs to",
"example": "57bca0969ca8e18b825bcc2b"
}, },
"title": { "title": {
"type": "string", "type": "string",
"trim": true, "trim": true,
"required": "Field Title cannot be blank" "required": "Field Title cannot be blank",
"description": "Description of Field",
"example": "Your Current University"
}, },
"description": { "description": {
"type": "string", "type": "string",
"default": "" "default": "",
"description": "Description of Field",
"example": "Please do not use abbreviations for your school name"
}, },
"logicJump": { "logicJump": {
"$ref": "#/definitions/FormField" "$ref": "#/definitions/FormField"
}, },
"ratingOptions": { "ratingOptions": {
"type": "#/definitions/RatingField", "type": "#/definitions/RatingField"
}, },
"fieldOptions": { "fieldOptions": {
"type": "array", "type": "array",
"items": "#/definitions/FieldOption" "items": {
"type": "FieldOption"
}
}, },
"required": { "required": {
"type": "boolean", "type": "boolean",
"default": true "default": true,
"description": "Specifies whether Field is required",
"example": true
}, },
"disabled": { "disabled": {
"type": "boolean", "type": "boolean",
"default": false "default": false,
"description": "Specifies whether Field is disabled",
"example": true
}, },
"deletePreserved": { "deletePreserved": {
"type": "boolean", "type": "boolean",
"default": false "default": false,
"description": "Specifies whether Field should be preserved if it is deleted",
"example": false
}, },
"validFieldTypes": { "validFieldTypes": {
"type": "array", "type": "array",
@ -414,10 +551,14 @@
"natural", "natural",
"stripe", "stripe",
"number" "number"
] ],
"description": "Type of Field",
"example": "textfield"
}, },
"fieldValue": { "fieldValue": {
"type": "string" "type": "string",
"description": "Value of Field",
"example": "University of British Columbia"
} }
} }
}, },
@ -425,23 +566,35 @@
"type": "object", "type": "object",
"properties": { "properties": {
"referrer": { "referrer": {
"type": "string" "type": "string",
"description": "Referring site of Form Visitor",
"example": "http://google.com"
}, },
"lastActiveField": { "lastActiveField": {
"type": "string" "type": "string",
"description": "ID of Last Active Field",
"example": "57bca0969ca8e18b825bcc2b"
}, },
"timeElapsed": { "timeElapsed": {
"type": "number" "type": "number",
"description": "Time Elasped for Visitor on Form (in seconds)",
"example": "333.33"
}, },
"isSubmitted": { "isSubmitted": {
"type": "boolean" "type": "boolean",
"description": "Specifies whether user submitted form before leaving page",
"example": false
}, },
"language": { "language": {
"type": "string" "type": "string",
"description": "Language of User using form",
"example": "en"
}, },
"ipAddr": { "ipAddr": {
"type": "string", "type": "string",
"default": "" "default": "",
"description": "IP Address of User",
"example": "324.332.322.333"
}, },
"deviceType": { "deviceType": {
"type": "string", "type": "string",
@ -451,10 +604,14 @@
"tablet", "tablet",
"other" "other"
], ],
"default": "other" "default": "other",
"description": "Device Type of User",
"example": "phone"
}, },
"userAgent": { "userAgent": {
"type": "string" "type": "string",
"description": "User Agent of User",
"example": "Mozilla/5.0 (Linux; <Android Version>; <Build Tag etc.>) AppleWebKit/<WebKit Rev> (KHTML, like Gecko) Chrome/<Chrome Rev> Mobile Safari/<WebKit Rev>"
} }
} }
}, },
@ -463,23 +620,33 @@
"properties": { "properties": {
"url": { "url": {
"type": "string", "type": "string",
"format": "url" "format": "url",
"description": "URL of Button Link",
"example": "http://you-are-awesome.com"
}, },
"action": { "action": {
"type": "string" "type": "string",
"description": "Angular Action fired during Button click",
"example": "openModal()"
}, },
"text": { "text": {
"type": "string" "type": "string",
"description": "Text of Button",
"example": "Go to HomePage"
}, },
"bgColor": { "bgColor": {
"type": "string", "type": "string",
"pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/", "pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "5bc0de" "default": "#5bc0de",
"description": "Background Color of Button (in hex)",
"example": "#5bc0de"
}, },
"color": { "color": {
"type": "string", "type": "string",
"pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/", "pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "#ffffff" "default": "#ffffff",
"description": "Font Color of Button (in hex)",
"example": "#ffffff"
} }
} }
}, },
@ -561,12 +728,12 @@
"title" "title"
], ],
"properties": { "properties": {
"id": {
"type": "string",
},
"title": { "title": {
"type": "string", "type": "string",
"required": "Form Title cannot be blank" "required": "Form Title cannot be blank",
"description": "Public Title of Form",
"example": "UBC CPSC221 Course Waitlist Form"
}, },
"language": { "language": {
"type": "string", "type": "string",
@ -578,13 +745,18 @@
"de" "de"
], ],
"default": "en", "default": "en",
"required": "Form must have a language" "required": "Form must have a language",
"description": "Language of Form",
"example": "en"
}, },
"analytics": { "analytics": {
"type": "object", "type": "object",
"description": "Analytics of Form",
"properties": { "properties": {
"gaCode": { "gaCode": {
"type": "string" "type": "string",
"description": "Analytics of Form",
"example": "UA-000000-01"
}, },
"visitors": { "visitors": {
"type": "array", "type": "array",
@ -596,7 +768,9 @@
}, },
"form_fields": { "form_fields": {
"type": "array", "type": "array",
"items": "#/definitions/FormField" "items": {
"type": "FormField"
}
}, },
"submissions": { "submissions": {
"type": "array", "type": "array",
@ -605,82 +779,102 @@
} }
}, },
"admin": { "admin": {
"$ref": "#/definitions/User" "type": "User",
}, "description": "User that this Form belongs to"
"pdf": {
"type": "object"
},
"pdfFieldMap": {
"type": "object"
}, },
"startPage": { "startPage": {
"type": "object",
"properties": { "properties": {
"showStart": { "showStart": {
"type": "boolean", "type": "boolean",
"default": false "default": false,
"description": "Specifies whether Form StarPage should be displayed",
"example": false
}, },
"introTitle": { "introTitle": {
"type": "string", "type": "string",
"default": "Welcome to Form" "default": "Welcome to Form",
"description": "Title of Form's StartPage",
"example": "Welcome to our Awesome Form!"
}, },
"introParagraph": { "introParagraph": {
"type": "string" "type": "string",
"description": "Introduction paragraph for Form's StartPage.",
"example": "Welcome to our Awesome Form!"
}, },
"introButtonText": { "introButtonText": {
"type": "string", "type": "string",
"default": "Start" "default": "Start",
"description": "StartPage Continue Button",
"example": "Continue"
}, },
"buttons": { "buttons": {
"type": "array", "type": "array",
"items": "#/definitions/Button" "items": {
type: "Button"
}
} }
} }
}, },
"hideFooter": { "hideFooter": {
"type": "boolean", "type": "boolean",
"default": false "default": false,
}, "description": "Specifies whether to hide or show Form Footer",
"isGenerated": { "example": true
"type": "boolean",
"default": false
}, },
"isLive": { "isLive": {
"type": "boolean", "type": "boolean",
"default": false "default": false,
}, "description": "Specifies whether form is Publically available or Private",
"autofillPDFs": { "example": true
"type": "boolean",
"default": false
}, },
"design": { "design": {
"colors": { "type": "object",
"backgroundColor": { "properties": {
"type": "string", "colors": {
"pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/", "type": "object",
"default": "#fff" "properties": {
"backgroundColor": {
"type": "string",
"pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "#fff",
"description": "Background color of Form",
"example": "#4c4c4c"
},
"questionColor": {
"type": "string",
"match": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "#333",
"description": "Question text font color (in hex)",
"example": "#fff"
},
"answerColor": {
"type": "string",
"match": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "#333",
"description": "Answer text font color (in hex)",
"example": "#f9f9f9"
},
"buttonColor": {
"type": "string",
"match": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "#fff",
"description": "Background color of Form Buttons (in hex)",
"example": "#555"
},
"buttonTextColor": {
"type": "string",
"pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "#333",
"description": "Font color of Form Buttons (in hex)",
"example": "#fff"
}
}
}, },
"questionColor": { "font": {
"type": "string", "type": "string"
"match": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "#333"
},
"answerColor": {
"type": "string",
"match": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "#333"
},
"buttonColor": {
"type": "string",
"match": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "#fff"
},
"buttonTextColor": {
"type": "string",
"pattern": "/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/",
"default": "#333"
} }
}, }
"font": "string"
} }
} }
} }