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

Ht/correting routes url swagger #33

Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Instale o pacote golang `swag`:
Vá para a pasta backend e rode o seguinte comando:

```bash
swag init -g ./cmd/api/main.go -o cmd/docs
path/to/the/go/bin/swag init -g ./cmd/api/main.go -o cmd/docs
```

![Run and debug tutorial](.github/images/run_and_debug.png)
Expand Down
21 changes: 21 additions & 0 deletions backend/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ import (
"golang.org/x/oauth2"
)

// @title Faladev API
// @version 1.0
// @description Esta é uma API exemplo do Faladev, que integra com o Google Calendar e o Gmail.
// @termsOfService http://swagger.io/terms/

// @contact.name Suporte da API Faladev
// @contact.url http://www.faladev.com/support
// @contact.email [email protected]

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host localhost:8080
// @BasePath /

// @securityDefinitions.oauth2 OAuth2
// @securityDefinitions.oauth2.description OAuth2 authorization for accessing the API
// @securityDefinitions.oauth2.flow accessCode

// @externalDocs.description OpenAPI Specification
// @externalDocs.url https://swagger.io/resources/open-api/
func main() {

oauthConfig := config.SetupOAuthConfig()
Expand Down
141 changes: 77 additions & 64 deletions backend/cmd/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,150 +9,163 @@ const docTemplate = `{
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "Suporte da API Faladev",
"url": "http://www.faladev.com/support",
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/event-handler": {
"post": {
"description": "Handles event creation, guest addition, email sending, and redirects to Google Meet link.",
"/": {
"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"
}
}
}
}
},
"/callback": {
"get": {
"description": "Exchange code for token and save it",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Handle event creation and interaction",
"summary": "Handle OAuth2 callback",
"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",
"description": "State token",
"name": "state",
"in": "query",
"required": true
},
{
"type": "string",
"description": "Phone number of the student",
"name": "phone",
"in": "formData",
"description": "Authorization code",
"name": "code",
"in": "query",
"required": true
}
],
"responses": {
"303": {
"description": "Redirects to Google Meet link",
"schema": {
"type": "string"
}
"description": "Redirects to /"
},
"400": {
"description": "No Google Meet link available or other errors",
"description": "State token doesn't match",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
"$ref": "#/definitions/http.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",
"description": "Unable to retrieve or save token",
"schema": {
"type": "string"
"$ref": "#/definitions/http.ErrorResponse"
}
}
}
}
},
"/oauth/callback": {
"get": {
"description": "Exchange code for token and save it",
"/event": {
"post": {
"description": "Handles event creation, guest addition, email sending, and redirects to Google Meet link.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Handle OAuth2 callback",
"summary": "Handle event creation and interaction",
"parameters": [
{
"type": "string",
"description": "State token",
"name": "state",
"in": "query",
"description": "Name of the student",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "Authorization code",
"name": "code",
"in": "query",
"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 /"
"description": "Redirects to Google Meet link",
"schema": {
"type": "string"
}
},
"400": {
"description": "State token doesn't match",
"description": "No Google Meet link available or other errors",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
"$ref": "#/definitions/http.ErrorResponse"
}
},
"500": {
"description": "Unable to retrieve or save token",
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/handlers.ErrorResponse"
"$ref": "#/definitions/http.ErrorResponse"
}
}
}
}
}
},
"definitions": {
"handlers.ErrorResponse": {
"http.ErrorResponse": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
},
"externalDocs": {
"description": "OpenAPI Specification",
"url": "https://swagger.io/resources/open-api/"
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "",
Host: "",
BasePath: "",
Version: "1.0",
Host: "localhost:8080",
BasePath: "/",
Schemes: []string{},
Title: "",
Description: "",
Title: "Faladev API",
Description: "Esta é uma API exemplo do Faladev, que integra com o Google Calendar e o Gmail.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
Expand Down
Loading
Loading