Skip to content

Commit

Permalink
Merge pull request #19 from vitorAzevedo09/add-swagger-documentation
Browse files Browse the repository at this point in the history
Add swagger documentation
  • Loading branch information
mffonseca authored Jul 23, 2024
2 parents 832ec01 + 3bb0abc commit 349af10
Show file tree
Hide file tree
Showing 8 changed files with 529 additions and 6 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Este projeto é uma aplicação Go que integra com o Google Calendar e tem permi

4. **Configurar Variáveis de Ambiente:**

Crie um arquivo .env na raiz do projeto e adicione as seguintes variáveis, incluindo suas credenciais do Google:
Crie um arquivo .env no diretório ./backend e adicione as seguintes variáveis, incluindo suas credenciais do Google:

```env
GOOGLE_MEET_EVENT=https://meet.google.com/link-do-meet-do-evento
Expand Down Expand Up @@ -118,6 +118,23 @@ O comando padrão para acessar essa aba é `Ctrl+Shift+D` ou no Mac `Cmd+Shift+D
Selecione a opção `Connect to server` e clique no botão de Play.
![Run and debug tutorial](.github/images/run_and_debug.png)


## Como atualizar a documentação Swagger?

Instale o pacote golang `swag`:

```bash
go install github.com/swaggo/swag/cmd/swag@latest
```

Vá para a pasta backend e rode o seguinte comando:

```bash
swag init -g ./cmd/api/main.go -o cmd/docs
```

![Run and debug tutorial](.github/images/run_and_debug.png)

## Como Usar

Para acessar a aplicação:
Expand All @@ -144,3 +161,9 @@ Selecione a opção `Connect to server` e clique no botão de Play.
http://localhost:5050/
```

Para acessar a documentação swagger:

```bash
http://localhost:8080/swagger/index.html
```

164 changes: 164 additions & 0 deletions backend/cmd/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"

const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/event-handler": {
"post": {
"description": "Handles event creation, guest addition, email sending, and redirects to Google Meet link.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Handle event creation and interaction",
"parameters": [
{
"type": "string",
"description": "Name of the student",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "Email of the student",
"name": "email",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "Phone number of the student",
"name": "phone",
"in": "formData",
"required": true
}
],
"responses": {
"303": {
"description": "Redirects to Google Meet link",
"schema": {
"type": "string"
}
},
"400": {
"description": "No Google Meet link available or other errors",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/form": {
"get": {
"description": "Renders the form.html page to display user information form.",
"produces": [
"text/html"
],
"summary": "Render form page",
"responses": {
"200": {
"description": "HTML content of the form page",
"schema": {
"type": "string"
}
}
}
}
},
"/oauth/callback": {
"get": {
"description": "Exchange code for token and save it",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Handle OAuth2 callback",
"parameters": [
{
"type": "string",
"description": "State token",
"name": "state",
"in": "query",
"required": true
},
{
"type": "string",
"description": "Authorization code",
"name": "code",
"in": "query",
"required": true
}
],
"responses": {
"303": {
"description": "Redirects to /"
},
"400": {
"description": "State token doesn't match",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Unable to retrieve or save token",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
}
},
"definitions": {
"handlers.ErrorResponse": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "",
Description: "",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
135 changes: 135 additions & 0 deletions backend/cmd/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"swagger": "2.0",
"info": {
"contact": {}
},
"paths": {
"/event-handler": {
"post": {
"description": "Handles event creation, guest addition, email sending, and redirects to Google Meet link.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Handle event creation and interaction",
"parameters": [
{
"type": "string",
"description": "Name of the student",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "Email of the student",
"name": "email",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "Phone number of the student",
"name": "phone",
"in": "formData",
"required": true
}
],
"responses": {
"303": {
"description": "Redirects to Google Meet link",
"schema": {
"type": "string"
}
},
"400": {
"description": "No Google Meet link available or other errors",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
},
"/form": {
"get": {
"description": "Renders the form.html page to display user information form.",
"produces": [
"text/html"
],
"summary": "Render form page",
"responses": {
"200": {
"description": "HTML content of the form page",
"schema": {
"type": "string"
}
}
}
}
},
"/oauth/callback": {
"get": {
"description": "Exchange code for token and save it",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Handle OAuth2 callback",
"parameters": [
{
"type": "string",
"description": "State token",
"name": "state",
"in": "query",
"required": true
},
{
"type": "string",
"description": "Authorization code",
"name": "code",
"in": "query",
"required": true
}
],
"responses": {
"303": {
"description": "Redirects to /"
},
"400": {
"description": "State token doesn't match",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
},
"500": {
"description": "Unable to retrieve or save token",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
}
}
}
}
}
},
"definitions": {
"handlers.ErrorResponse": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
}
}
Loading

0 comments on commit 349af10

Please sign in to comment.