Procházet zdrojové kódy

Swagger is now stored in single js file

pull/61/head
dusan-lazarevic před 3 roky
rodič
revize
48f67c0603

+ 0
- 7
src/documentation/basicInfo.js Zobrazit soubor

@@ -1,7 +0,0 @@
module.exports = {
openapi: "3.0.3",
info: {
title: "Trampa",
description: "Trampa api"
}
}

+ 0
- 41
src/documentation/components.js Zobrazit soubor

@@ -1,41 +0,0 @@
module.exports = {
components: {
schemas: {
id: {
type: "string",
description: "An id of a user"
},
User: {
type: "object",
properties: {
name: {
type: "string"
},
email: {
type: "string"
},
password: {
type: "string"
},
tokens: {
type: "array",
items: {
type: "string"
}
}
}
},
Token: {
type: "object",
properties: {
token: {
type: "string"
},
userId: {
type: "string"
}
}
}
}
}
}

+ 0
- 14
src/documentation/index.js Zobrazit soubor

@@ -1,14 +0,0 @@
const basicInfo = require('./basicInfo');
const servers = require('./servers');
const components = require('./components');
const tags = require('./tags');
const routesDesc = require('./routesDesc');
module.exports = {
...basicInfo,
...servers,
...components,
...tags,
...routesDesc
}

+ 0
- 34
src/documentation/routesDesc/index.js Zobrazit soubor

@@ -1,34 +0,0 @@
const getUser = require('./user/getUserDesc');
const getUsers = require('./user/getUsersDesc');
const createUser = require('./user/createUserDesc');
const updateUser = require('./user/updateUserDesc');
const updateUserContacts = require('./user/updateUserContactsDesc');
const deleteUserDesc = require('./user/deleteUserDesc');
const loginUserDesc = require('./token/loginUserDesc');
const logoutDesc = require('./token/logoutDesc');
const refreshTokenDesc = require('./token/refreshTokenDesc');
module.exports = {
paths: {
'/users': {
...getUsers,
...createUser
},
'/users/{id}': {
...getUser,
...updateUser,
...updateUserContacts,
...deleteUserDesc
},
'/auth/token': {
...loginUserDesc
},
'/auth/logout': {
...logoutDesc
},
'/auth/refresh': {
...refreshTokenDesc
}
}
}

+ 0
- 35
src/documentation/routesDesc/token/loginUserDesc.js Zobrazit soubor

@@ -1,35 +0,0 @@
module.exports = {
post: {
tags: ["Token"],
description: "Log in user",
parameters: [],
requestBody: {
content: {
"application/json": {
schema: {
type: "object",
properties: {
email: {
type: "string"
},
password: {
type: "string"
}
}
}
}
}
},
responses: {
201: {
description: "User logged in successfully!"
},
400: {
description: "Wrong credentials!"
},
500: {
description: "Internal server error"
}
}
}
}

+ 0
- 27
src/documentation/routesDesc/token/logoutDesc.js Zobrazit soubor

@@ -1,27 +0,0 @@
module.exports = {
post: {
tags: ["Token"],
description: "Log out user",
parameters: [],
requestBody: {
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Token"
}
}
}
},
responses: {
201: {
description: "User logged out successfully"
},
404: {
description: "No user has the token provided!"
},
500: {
description: "Internal server error"
}
}
}
}

+ 0
- 24
src/documentation/routesDesc/token/refreshTokenDesc.js Zobrazit soubor

@@ -1,24 +0,0 @@
module.exports = {
post: {
tags: ["Token"],
description: "Log out user",
parameters: [],
requestBody: {
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Token"
}
}
}
},
responses: {
201: {
description: "User refreshed successfully"
},
404: {
description: "Token not valid!"
}
}
}
}

+ 0
- 48
src/documentation/routesDesc/user/createUserDesc.js Zobrazit soubor

@@ -1,48 +0,0 @@
module.exports = {
post: {
tags: ["User"],
description: "Create user",
parameters: [],
requestBody: {
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: {
type: "string"
},
email: {
type: "string"
},
password: {
type: "string"
}
}
}
}
}
},
responses: {
201: {
description: "User created successfully",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/User"
},
},
},
},
400: {
description: "Object cant be empty",
},
401: {
description: "Invalid input parameters",
},
500: {
description: "Internal server error",
}
}
}
}

+ 0
- 30
src/documentation/routesDesc/user/deleteUserDesc.js Zobrazit soubor

@@ -1,30 +0,0 @@
module.exports = {
delete: {
tags: ["User"],
description: "Delete user",
parameters: [
{
name: "id",
in: "path",
schema: {
$ref: "#/components/schemas/id",
},
required: true,
},
],
responses: {
204: {
description: "User deleted successfully",
},
400: {
description: "You need to provide valid Id'",
},
404: {
description: "User not found",
},
500: {
description: "Internal server error",
},
},
},
};

+ 0
- 38
src/documentation/routesDesc/user/getUserDesc.js Zobrazit soubor

@@ -1,38 +0,0 @@
module.exports = {
get: {
tags: ["User"],
description: "Get user by id",
parameters: [
{
name: "id",
in: "path",
schema: {
$ref: "#/components/schemas/id",
},
required: true,
description: "A single user id",
}
],
responses: {
200: {
description: "Success",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/User",
}
}
}
},
400: {
description: "Bad request"
},
404: {
description: "User with specified id does not exist"
},
500: {
description: "Internal server error"
}
}
}
}

+ 0
- 25
src/documentation/routesDesc/user/getUsersDesc.js Zobrazit soubor

@@ -1,25 +0,0 @@
module.exports = {
get: {
tags: ["User"],
description: "Get all users",
parameters: [],
responses: {
200: {
description: "Success",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/User",
}
}
}
},
200: {
description: "Users returned successfully"
},
500: {
description: "Internal server error"
}
}
}
}

+ 0
- 25
src/documentation/routesDesc/user/updateUserContactsDesc.js Zobrazit soubor

@@ -1,25 +0,0 @@
module.exports = {
patch: {
tags: ["User"],
description: "Update user",
parameters: [
{
name: "id",
in: "path",
// schema: {
// $ref: "#/components/schemas/id", // data model of the param
// },
required: true,
description: "A single user id",
}
],
requestBody: {
content: {
}
},
responses: {
}
}
}

+ 0
- 48
src/documentation/routesDesc/user/updateUserDesc.js Zobrazit soubor

@@ -1,48 +0,0 @@
module.exports = {
put: {
tags: ["User"],
description: "Update user",
parameters: [
{
name: "id",
in: "path",
schema: {
$ref: "#/components/schemas/id", // data model of the param
},
required: true,
description: "A single user id",
}
],
requestBody: {
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: {
type: "string"
},
email: {
type: "string"
},
password: {
type: "string"
}
}
}
}
}
},
responses: {
200: {
description: "User updated successfully",
},
400: {
description: "Invalid input parameters",
},
500: {
description: "Server error",
}
}
}
}

+ 0
- 8
src/documentation/servers.js Zobrazit soubor

@@ -1,8 +0,0 @@
module.exports = {
servers: [
{
url: "http://localhost:3000/",
description: "Local server",
},
],
}

+ 0
- 7
src/documentation/tags.js Zobrazit soubor

@@ -1,7 +0,0 @@
module.exports = {
tags: [
{
name: "User"
},
],
}

+ 2
- 2
src/server.js Zobrazit soubor

@@ -5,8 +5,8 @@ const port = process.env.NODE_ENV === 'production' ? 80 : 3001
require('./database/mongoose')
const userRouter = require('./routes/user')
const tokenRouter = require('./routes/token')
const docs = require('./documentation');
const swaggerUI = require("swagger-ui-express")
const docs = require('./swagger.js');
const swaggerUI = require('swagger-ui-express')
const { errorLogger, errorResponder } = require('./middleware/errorHandling.js')
const requestLogging = require('./middleware/requestLogging.js')
const cors = require('cors') //Cross-origin resource sharing

+ 351
- 0
src/swagger.js Zobrazit soubor

@@ -0,0 +1,351 @@
module.exports = {
servers: [
{
url: "http://localhost:3001/",
description: "Local server",
},
],
tags: [
{
name: "User"
},
],
openapi: "3.0.3",
info: {
title: "Trampa",
description: "Trampa api"
},
paths: {
'/users': {
get: {
tags: ["User"],
description: "Get all users",
parameters: [],
responses: {
200: {
description: "Success",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/User",
}
}
}
},
200: {
description: "Users returned successfully"
},
500: {
description: "Internal server error"
}
}
},
post: {
tags: ["User"],
description: "Create user",
parameters: [],
requestBody: {
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: {
type: "string"
},
email: {
type: "string"
},
password: {
type: "string"
}
}
}
}
}
},
responses: {
201: {
description: "User created successfully",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/User"
},
},
},
},
400: {
description: "Object cant be empty",
},
401: {
description: "Invalid input parameters",
},
500: {
description: "Internal server error",
}
}
}
},
'/users/{id}': {
get: {
tags: ["User"],
description: "Get user by id",
parameters: [
{
name: "id",
in: "path",
schema: {
$ref: "#/components/schemas/id",
},
required: true,
description: "A single user id",
}
],
responses: {
200: {
description: "Success",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/User",
}
}
}
},
400: {
description: "Bad request"
},
404: {
description: "User with specified id does not exist"
},
500: {
description: "Internal server error"
}
}
},
put: {
tags: ["User"],
description: "Update user",
parameters: [
{
name: "id",
in: "path",
schema: {
$ref: "#/components/schemas/id", // data model of the param
},
required: true,
description: "A single user id",
}
],
requestBody: {
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: {
type: "string"
},
email: {
type: "string"
},
password: {
type: "string"
}
}
}
}
}
},
responses: {
200: {
description: "User updated successfully",
},
400: {
description: "Invalid input parameters",
},
500: {
description: "Server error",
}
}
},
patch: {
tags: ["User"],
description: "Update user",
parameters: [
{
name: "id",
in: "path",
// schema: {
// $ref: "#/components/schemas/id", // data model of the param
// },
required: true,
description: "A single user id",
}
],
requestBody: {
content: {
}
},
responses: {
}
},
delete: {
tags: ["User"],
description: "Delete user",
parameters: [
{
name: "id",
in: "path",
schema: {
$ref: "#/components/schemas/id",
},
required: true,
},
],
responses: {
204: {
description: "User deleted successfully",
},
400: {
description: "You need to provide valid Id'",
},
404: {
description: "User not found",
},
500: {
description: "Internal server error",
},
},
}
},
'/auth/token': {
post: {
tags: ["Token"],
description: "Log in user",
parameters: [],
requestBody: {
content: {
"application/json": {
schema: {
type: "object",
properties: {
email: {
type: "string"
},
password: {
type: "string"
}
}
}
}
}
},
responses: {
201: {
description: "User logged in successfully!"
},
400: {
description: "Wrong credentials!"
},
500: {
description: "Internal server error"
}
}
}
},
'/auth/logout': {
post: {
tags: ["Token"],
description: "Log out user",
parameters: [],
requestBody: {
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Token"
}
}
}
},
responses: {
201: {
description: "User logged out successfully"
},
404: {
description: "No user has the token provided!"
},
500: {
description: "Internal server error"
}
}
}
},
'/auth/refresh': {
post: {
tags: ["Token"],
description: "Log out user",
parameters: [],
requestBody: {
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Token"
}
}
}
},
responses: {
201: {
description: "User refreshed successfully"
},
404: {
description: "Token not valid!"
}
}
}
}
},
components: {
schemas: {
id: {
type: "string",
description: "An id of a user"
},
User: {
type: "object",
properties: {
name: {
type: "string"
},
email: {
type: "string"
},
password: {
type: "string"
},
tokens: {
type: "array",
items: {
type: "string"
}
}
}
},
Token: {
type: "object",
properties: {
token: {
type: "string"
},
userId: {
type: "string"
}
}
}
}
}
}

Načítá se…
Zrušit
Uložit