Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add swagger documentation #19

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading