Skip to content

Commit

Permalink
docs: add all components api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
betomossmann committed Mar 13, 2023
1 parent b824371 commit d356684
Show file tree
Hide file tree
Showing 29 changed files with 498 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
coverage
.vscode
.vscode
globalConfig.json
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
"build": "rimraf dist && tsc -p tsconfig-build.json",
"dev": "sucrase-node src/main/server.ts",
"check": "npm-check -s -u",
"test": "jest --passWithNoTests --silent --noStackTrace --runInBand",
"test:verbose": "jest --passWithNoTests --runInBand",
"test": "jest --passWithNoTests --runInBand --no-cache",
"test:unit": "npm test -- --watch -c jest-unit-config.js",
"test:verbose": "jest --passWithNoTests --runInBand",
"test:integration": "npm test -- --watch -c jest-integration-config.js",
"test:staged": "npm test -- --findRelatedTests",
"test:ci": "npm test -- --coverage",
"prepare": "husky install"
},
"keywords": [],
"author": "Gilberto Mossmann",
"license": "ISC",
"license": "GPL-3.0-or-later",
"devDependencies": {
"@shelf/jest-mongodb": "^4.1.7",
"@types/bcrypt": "^5.0.0",
Expand Down Expand Up @@ -60,6 +60,9 @@
"swagger-ui-express": "^4.6.2",
"validator": "^13.9.0"
},
"engines": {
"node": "16.x"
},
"_moduleAliases": {
"@": "dist"
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/docs/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { apiKeyAuthSchema } from './schemas/'
import {
badRequest,
serverError,
unauthorized,
notFound,
forbidden
} from './components/'

export default {
securitySchemes: {
apiKeyAuth: apiKeyAuthSchema
},
badRequest,
serverError,
unauthorized,
notFound,
forbidden
}
10 changes: 10 additions & 0 deletions src/main/docs/components/bad-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const badRequest = {
description: 'Requisição inválida',
content: {
'application/json': {
schema: {
$ref: '#/schemas/error'
}
}
}
}
10 changes: 10 additions & 0 deletions src/main/docs/components/forbidden.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const forbidden = {
description: 'Acesso negado',
content: {
'application/json': {
schema: {
$ref: '#/schemas/error'
}
}
}
}
5 changes: 5 additions & 0 deletions src/main/docs/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './bad-request'
export * from './server-error'
export * from './unauthorized'
export * from './not-found'
export * from './forbidden'
3 changes: 3 additions & 0 deletions src/main/docs/components/not-found.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const notFound = {
description: 'API não encontrada'
}
10 changes: 10 additions & 0 deletions src/main/docs/components/server-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const serverError = {
description: 'Erro interno no servidor',
content: {
'application/json': {
schema: {
$ref: '#/schemas/error'
}
}
}
}
10 changes: 10 additions & 0 deletions src/main/docs/components/unauthorized.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const unauthorized = {
description: 'Credenciais inválidas',
content: {
'application/json': {
schema: {
$ref: '#/schemas/error'
}
}
}
}
25 changes: 13 additions & 12 deletions src/main/docs/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { loginPath } from './paths/login-path'
import { accountSchema } from './schemas/account-schema'
import { loginParamsSchema } from './schemas/login-params-schema'
import paths from './paths'
import components from './components'
import schemas from './schemas'

export default {
openapi: '3.0.0',
Expand All @@ -14,16 +14,17 @@ export default {
}
},
servers: [{
url: '/api'
url: '/api',
description: 'Servidor Principal'
}],
tags: [{
name: 'Login'
name: 'Login',
description: 'APIs relacionadas a Login'
}, {
name: 'Enquete',
description: 'APIs relacionadas a Enquete'
}],
paths: {
'/login': loginPath
},
schemas: {
account: accountSchema,
loginParams: loginParamsSchema
}
paths,
schemas,
components
}
13 changes: 13 additions & 0 deletions src/main/docs/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
loginPath,
surveyPath,
signUpPath,
surveyResultPath
} from './paths/'

export default {
'/login': loginPath,
'/signup': signUpPath,
'/surveys': surveyPath,
'/surveys/{surveyId}/results': surveyResultPath
}
4 changes: 4 additions & 0 deletions src/main/docs/paths/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './login-path'
export * from './survey-path'
export * from './signup-path'
export * from './survey-result-path'
14 changes: 14 additions & 0 deletions src/main/docs/paths/login-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export const loginPath = {
post: {
tags: ['Login'],
summary: 'API para autenticar usuário',
description: 'Essa rota pode ser executada por **qualquer usuário**',
requestBody: {
required: true,
content: {
'application/json': {
schema: {
Expand All @@ -21,6 +23,18 @@ export const loginPath = {
}
}
}
},
400: {
$ref: '#/components/badRequest'
},
401: {
$ref: '#/components/unauthorized'
},
404: {
$ref: '#/components/notFound'
},
500: {
$ref: '#/components/serverError'
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions src/main/docs/paths/signup-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export const signUpPath = {
post: {
tags: ['Login'],
summary: 'API para criar conta de um usuário',
description: 'Essa rota pode ser executada por **qualquer usuário**',
requestBody: {
required: true,
content: {
'application/json': {
schema: {
$ref: '#/schemas/signUpParams'
}
}
}
},
responses: {
200: {
description: 'Sucesso',
content: {
'application/json': {
schema: {
$ref: '#/schemas/account'
}
}
}
},
400: {
$ref: '#/components/badRequest'
},
403: {
$ref: '#/components/forbidden'
},
404: {
$ref: '#/components/notFound'
},
500: {
$ref: '#/components/serverError'
}
}
}
}
66 changes: 66 additions & 0 deletions src/main/docs/paths/survey-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
export const surveyPath = {
get: {
security: [{
apiKeyAuth: []
}],
tags: ['Enquete'],
summary: 'API para listar todas as enquetes',
description: 'Essa rota só pode ser executada por **usuários autenticados**',
responses: {
200: {
description: 'Sucesso',
content: {
'application/json': {
schema: {
$ref: '#/schemas/surveys'
}
}
}
},
204: {
description: 'Sucesso, mas sem dados para exibir'
},
403: {
$ref: '#/components/forbidden'
},
404: {
$ref: '#/components/notFound'
},
500: {
$ref: '#/components/serverError'
}
}
},
post: {
security: [{
apiKeyAuth: []
}],
tags: ['Enquete'],
summary: 'API para criar uma enquete',
description: 'Essa rota só pode ser executada por **administradores**',
requestBody: {
required: true,
content: {
'application/json': {
schema: {
$ref: '#/schemas/addSurveyParams'
}
}
}
},
responses: {
204: {
description: 'Sucesso, mas sem dados para exibir'
},
403: {
$ref: '#/components/forbidden'
},
404: {
$ref: '#/components/notFound'
},
500: {
$ref: '#/components/serverError'
}
}
}
}
88 changes: 88 additions & 0 deletions src/main/docs/paths/survey-result-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
export const surveyResultPath = {
put: {
security: [{
apiKeyAuth: []
}],
tags: ['Enquete'],
summary: 'API para criar a resposta de uma enquete',
description: 'Essa rota só pode ser executada por **usuários autenticados**',
parameters: [{
in: 'path',
name: 'surveyId',
description: 'ID da enquete a ser respondida',
required: true,
schema: {
type: 'string'
}
}],
requestBody: {
required: true,
content: {
'application/json': {
schema: {
$ref: '#/schemas/saveSurveyParams'
}
}
}
},
responses: {
200: {
description: 'Sucesso',
content: {
'application/json': {
schema: {
$ref: '#/schemas/surveyResult'
}
}
}
},
403: {
$ref: '#/components/forbidden'
},
404: {
$ref: '#/components/notFound'
},
500: {
$ref: '#/components/serverError'
}
}
},
get: {
security: [{
apiKeyAuth: []
}],
tags: ['Enquete'],
summary: 'API para consultar o resultado de uma enquete',
description: 'Essa rota só pode ser executada por **usuários autenticados**',
parameters: [{
in: 'path',
name: 'surveyId',
description: 'ID da enquete a ser respondida',
required: true,
schema: {
type: 'string'
}
}],
responses: {
200: {
description: 'Sucesso',
content: {
'application/json': {
schema: {
$ref: '#/schemas/surveyResult'
}
}
}
},
403: {
$ref: '#/components/forbidden'
},
404: {
$ref: '#/components/notFound'
},
500: {
$ref: '#/components/serverError'
}
}
}
}
Loading

0 comments on commit d356684

Please sign in to comment.