Skip to content

Instantly share code, notes, and snippets.

@FikriRNurhidayat
Created September 2, 2019 04:42
Show Gist options
  • Save FikriRNurhidayat/5fc60fef109e1bc7a390f191e39d425c to your computer and use it in GitHub Desktop.
Save FikriRNurhidayat/5fc60fef109e1bc7a390f191e39d425c to your computer and use it in GitHub Desktop.
{
"swagger": "2.0",
"info": {
"description": "This is API Documentation.",
"version": "1.0.0",
"title": "Express Auth",
"contact": {
"email": "[email protected]"
}
},
"host": "",
"basePath": "/api",
"schemes": [
"https",
"http"
],
"paths": {
"/users": {
"get": {
"tags": [
"User Operation"
],
"summary": "Finding out who current is.",
"description": "",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "User exist and token verified!",
"schema": {
"$ref": "#/definitions/GetUser"
}
},
"401": {
"description": "No token provided",
"schema": {
"$ref": "#/definitions/GetUserNoToken"
}
},
"x-401": {
"descripton": "Token provided is invalid",
"schema": {
"$ref": "#/definitions/GetUserInvalidToken"
}
}
},
"security": [
{
"Authorization": []
}
]
}
},
"/auth/login": {
"post": {
"tags": [
"Authentication Operation"
],
"summary": "Login User",
"description": "User login",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "Will post email and password to database and database will check if it's true or not.",
"required": true,
"schema": {
"$ref": "#/definitions/UserLogin"
}
}
],
"responses": {
"201": {
"description": "If user exist, and the password is matched. It will response token object.",
"schema": {
"$ref": "#/definitions/LoginSuccessResponse"
}
},
"400": {
"description": "If there's a blank field",
"schema": {
"$ref": "#/definitions/LoginBlankFieldResponse"
}
},
"401": {
"description": "If user doesn't exist",
"schema": {
"$ref": "#/definitions/LoginEmailNotExistResponse"
}
},
"403": {
"description": "If password is wrong",
"schema": {
"$ref": "#/definitions/LoginWrongPasswordResponse"
}
}
}
}
},
"/auth/register": {
"post": {
"tags": [
"Authentication Operation"
],
"summary": "Register User",
"description": "",
"operationId": "addUser",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "Users that will be registered on database",
"required": true,
"schema": {
"$ref": "#/definitions/UserRegister"
}
}
],
"responses": {
"201": {
"description": "User successfully registered!",
"schema": {
"$ref": "#/definitions/RegisterSuccessResponse"
}
},
"400": {
"description": "If there's a blank field",
"schema": {
"$ref": "#/definitions/LoginBlankFieldResponse"
}
},
"422": {
"description": "If email has already taken",
"schema": {
"$ref": "#/definitions/RegisterEmailAlreadyTakenResponse"
}
},
"x-422": {
"description": "If password and its confirmation doesn't match",
"schema": {
"$ref": "#/definitions/RegisterWrongConfirmationResponse"
}
}
}
}
}
},
"securityDefinitions": {
"Authorization": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
"example":"Bearer inser_token_here"
}
},
"definitions": {
"GetUser": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": true
},
"data": {
"type": "object",
"properties": {
"name": {
"type": "string",
"example": "Fikri"
},
"isVerified": {
"type": "boolean",
"example": false
}
}
}
}
},
"GetUserNoToken": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"data": {
"type": "string",
"example": "Denied!"
}
}
},
"GetUserInvalidToken": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"data": {
"type": "string",
"example": "Invalid Token!"
}
}
},
"UserRegister": {
"type": "object",
"required": [
"name",
"email",
"password",
"password_confirmation"
],
"properties": {
"name": {
"type": "string",
"example": "Fikri"
},
"email": {
"type": "string",
"example": "[email protected]"
},
"password": {
"type": "string",
"example": "123456"
},
"password_confirmation": {
"type": "string",
"example": "123456"
}
}
},
"UserLogin": {
"type": "object",
"required": [
"email",
"password"
],
"properties": {
"email": {
"type": "string",
"example": "[email protected]"
},
"password": {
"type": "string",
"example": "123456"
}
}
},
"LoginSuccessResponse": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": true
},
"data": {
"type": "string",
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1NDIxMjA5bGtqYXNsZGppMTIwODMiLCJpYXQiOiIwOTgwOTIxODAifQ.Ar42WEfvN893pZ2GiHc8oew12TTxx1kV-8H-4kqe4qU"
}
}
},
"LoginWrongPasswordResponse": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"errors": {
"type": "string",
"example": "Wrong Password!"
}
}
},
"LoginEmailNotExistResponse": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"errors": {
"type": "string",
"example": "User doesn't exist!"
}
}
},
"LoginBlankFieldResponse": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"example": "required"
},
"field": {
"type": "string",
"example": "<Your Blank Field>"
},
"message": {
"type": "string",
"example": "The '<Your Blank Field>' is required!"
}
}
}
}
}
},
"RegisterSuccessResponse": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": true
},
"data": {
"type": "object",
"properties": {
"_id": {
"type": "string",
"example": "5d60bb2b94c73a00178a703a"
},
"name": {
"type": "string",
"example": "Fikri"
},
"email": {
"type": "string",
"example": "[email protected]"
},
"isVerified": {
"type": "boolean",
"example": false
},
"token": {
"type": "string",
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1NDIxMjA5bGtqYXNsZGppMTIwODMiLCJpYXQiOiIwOTgwOTIxODAifQ.Ar42WEfvN893pZ2GiHc8oew12TTxx1kV-8H-4kqe4qU"
}
}
}
}
},
"RegisterEmailAlreadyTakenResponse": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"errors": {
"type": "string",
"example": "Email has already taken!"
}
}
},
"RegisterWrongConfirmationResponse": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"errors": {
"type": "string",
"example": "Password and its confirmation doesn't match!"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment