Browse Source

wip integrated swagger docs

pull/28/head
Dimas Restu H 4 years ago
parent
commit
3017a930db
  1. 1
      .goreleaser.yml
  2. 6
      cmd/main/main.go
  3. 200
      docs/docs.go
  4. 179
      docs/swagger.json
  5. 114
      docs/swagger.yaml
  6. 8
      internal/auth/auth.go
  7. 31
      internal/whatsapp/whatsapp.go

1
.goreleaser.yml

@ -1,6 +1,7 @@
before: before:
hooks: hooks:
- make vendor - make vendor
- make gen-docs
builds: builds:
- main: ./cmd/main/main.go - main: ./cmd/main/main.go
env: env:

6
cmd/main/main.go

@ -11,6 +11,12 @@ package main
// @schemes http // @schemes http
// @host 127.0.0.1:3000 // @host 127.0.0.1:3000
// @securityDefinitions.basic BasicAuth
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
import ( import (
"context" "context"
"net/http" "net/http"

200
docs/docs.go

@ -0,0 +1,200 @@
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
package docs
import "github.com/swaggo/swag"
const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {
"name": "Dimas Restu Hidayanto",
"url": "https://github.com/dimaskiddo",
"email": "drh.dimasrestu@gmail.com"
},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/v1/whatsapp": {
"get": {
"description": "Get The Server Status",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"tags": [
"Root"
],
"summary": "Show The Status of The Server",
"responses": {
"200": {
"description": ""
}
}
}
},
"/api/v1/whatsapp/auth": {
"get": {
"security": [
{
"BasicAuth": []
}
],
"description": "Get Authentication Token",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"tags": [
"Root"
],
"summary": "Generate Authentication Token",
"responses": {
"200": {
"description": ""
}
}
}
},
"/api/v1/whatsapp/login": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Get QR Code for WhatsApp Multi-Device Login",
"consumes": [
"*/*"
],
"produces": [
"application/json",
"text/html"
],
"tags": [
"WhatsApp"
],
"summary": "Generate QR Code for WhatsApp Multi-Device Login",
"parameters": [
{
"enum": [
"html",
"json"
],
"type": "string",
"default": "html",
"description": "Change Output Format in HTML or JSON",
"name": "output",
"in": "query"
}
],
"responses": {
"200": {
"description": ""
}
}
}
},
"/api/v1/whatsapp/logout": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Make Device Logout from WhatsApp Multi-Device",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"tags": [
"WhatsApp"
],
"summary": "Logout Device from WhatsApp Multi-Device",
"responses": {
"200": {
"description": ""
}
}
}
},
"/api/v1/whatsapp/send/text": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Make Device Logout from WhatsApp Multi-Device",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"tags": [
"WhatsApp"
],
"summary": "Logout Device from WhatsApp Multi-Device",
"parameters": [
{
"type": "string",
"description": "Destination Phone Number",
"name": "msisdn",
"in": "query",
"required": true
},
{
"type": "string",
"description": "Text Message Content",
"name": "message",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": ""
}
}
}
}
},
"securityDefinitions": {
"BasicAuth": {
"type": "basic"
},
"BearerAuth": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}`
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.x",
Host: "127.0.0.1:3000",
BasePath: "",
Schemes: []string{"http"},
Title: "Go WhatsApp Multi-Device REST API",
Description: "This is WhatsApp Multi-Device Implementation in Go REST API",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
}
func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}

179
docs/swagger.json

@ -0,0 +1,179 @@
{
"schemes": [
"http"
],
"swagger": "2.0",
"info": {
"description": "This is WhatsApp Multi-Device Implementation in Go REST API",
"title": "Go WhatsApp Multi-Device REST API",
"contact": {
"name": "Dimas Restu Hidayanto",
"url": "https://github.com/dimaskiddo",
"email": "drh.dimasrestu@gmail.com"
},
"version": "1.x"
},
"host": "127.0.0.1:3000",
"paths": {
"/api/v1/whatsapp": {
"get": {
"description": "Get The Server Status",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"tags": [
"Root"
],
"summary": "Show The Status of The Server",
"responses": {
"200": {
"description": ""
}
}
}
},
"/api/v1/whatsapp/auth": {
"get": {
"security": [
{
"BasicAuth": []
}
],
"description": "Get Authentication Token",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"tags": [
"Root"
],
"summary": "Generate Authentication Token",
"responses": {
"200": {
"description": ""
}
}
}
},
"/api/v1/whatsapp/login": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Get QR Code for WhatsApp Multi-Device Login",
"consumes": [
"*/*"
],
"produces": [
"application/json",
"text/html"
],
"tags": [
"WhatsApp"
],
"summary": "Generate QR Code for WhatsApp Multi-Device Login",
"parameters": [
{
"enum": [
"html",
"json"
],
"type": "string",
"default": "html",
"description": "Change Output Format in HTML or JSON",
"name": "output",
"in": "query"
}
],
"responses": {
"200": {
"description": ""
}
}
}
},
"/api/v1/whatsapp/logout": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Make Device Logout from WhatsApp Multi-Device",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"tags": [
"WhatsApp"
],
"summary": "Logout Device from WhatsApp Multi-Device",
"responses": {
"200": {
"description": ""
}
}
}
},
"/api/v1/whatsapp/send/text": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Make Device Logout from WhatsApp Multi-Device",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"tags": [
"WhatsApp"
],
"summary": "Logout Device from WhatsApp Multi-Device",
"parameters": [
{
"type": "string",
"description": "Destination Phone Number",
"name": "msisdn",
"in": "query",
"required": true
},
{
"type": "string",
"description": "Text Message Content",
"name": "message",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": ""
}
}
}
}
},
"securityDefinitions": {
"BasicAuth": {
"type": "basic"
},
"BearerAuth": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}

114
docs/swagger.yaml

@ -0,0 +1,114 @@
host: 127.0.0.1:3000
info:
contact:
email: drh.dimasrestu@gmail.com
name: Dimas Restu Hidayanto
url: https://github.com/dimaskiddo
description: This is WhatsApp Multi-Device Implementation in Go REST API
title: Go WhatsApp Multi-Device REST API
version: 1.x
paths:
/api/v1/whatsapp:
get:
consumes:
- '*/*'
description: Get The Server Status
produces:
- application/json
responses:
"200":
description: ""
summary: Show The Status of The Server
tags:
- Root
/api/v1/whatsapp/auth:
get:
consumes:
- '*/*'
description: Get Authentication Token
produces:
- application/json
responses:
"200":
description: ""
security:
- BasicAuth: []
summary: Generate Authentication Token
tags:
- Root
/api/v1/whatsapp/login:
post:
consumes:
- '*/*'
description: Get QR Code for WhatsApp Multi-Device Login
parameters:
- default: html
description: Change Output Format in HTML or JSON
enum:
- html
- json
in: query
name: output
type: string
produces:
- application/json
- text/html
responses:
"200":
description: ""
security:
- BearerAuth: []
summary: Generate QR Code for WhatsApp Multi-Device Login
tags:
- WhatsApp
/api/v1/whatsapp/logout:
post:
consumes:
- '*/*'
description: Make Device Logout from WhatsApp Multi-Device
produces:
- application/json
responses:
"200":
description: ""
security:
- BearerAuth: []
summary: Logout Device from WhatsApp Multi-Device
tags:
- WhatsApp
/api/v1/whatsapp/send/text:
post:
consumes:
- '*/*'
description: Make Device Logout from WhatsApp Multi-Device
parameters:
- description: Destination Phone Number
in: query
name: msisdn
required: true
type: string
- description: Text Message Content
in: query
name: message
required: true
type: string
produces:
- application/json
responses:
"200":
description: ""
security:
- BearerAuth: []
summary: Logout Device from WhatsApp Multi-Device
tags:
- WhatsApp
schemes:
- http
securityDefinitions:
BasicAuth:
type: basic
BearerAuth:
in: header
name: Authorization
type: apiKey
swagger: "2.0"

8
internal/auth/auth.go

@ -14,6 +14,14 @@ import (
) )
// Auth // Auth
// @Summary Generate Authentication Token
// @Description Get Authentication Token
// @Tags Root
// @Accept */*
// @Produce json
// @Success 200
// @Security BasicAuth
// @Router /api/v1/whatsapp/auth [get]
func Auth(c echo.Context) error { func Auth(c echo.Context) error {
var reqAuthBasicInfo typAuth.RequestAuthBasicInfo var reqAuthBasicInfo typAuth.RequestAuthBasicInfo
var resAuthJWTData typAuth.ResponseAuthJWTData var resAuthJWTData typAuth.ResponseAuthJWTData

31
internal/whatsapp/whatsapp.go

@ -40,6 +40,17 @@ func convertFileToBytes(file multipart.File) ([]byte, error) {
return buffer.Bytes(), nil return buffer.Bytes(), nil
} }
// Login
// @Summary Generate QR Code for WhatsApp Multi-Device Login
// @Description Get QR Code for WhatsApp Multi-Device Login
// @Tags WhatsApp
// @Accept */*
// @Produce json
// @Produce html
// @Param output query string false "Change Output Format in HTML or JSON" Enums(html, json) default(html)
// @Success 200
// @Security BearerAuth
// @Router /api/v1/whatsapp/login [post]
func Login(c echo.Context) error { func Login(c echo.Context) error {
var err error var err error
jid := jwtPayload(c).JID jid := jwtPayload(c).JID
@ -93,6 +104,15 @@ func Login(c echo.Context) error {
return router.ResponseSuccessWithData(c, "Successfully Generated QR Code", resLogin) return router.ResponseSuccessWithData(c, "Successfully Generated QR Code", resLogin)
} }
// Logout
// @Summary Logout Device from WhatsApp Multi-Device
// @Description Make Device Logout from WhatsApp Multi-Device
// @Tags WhatsApp
// @Accept */*
// @Produce json
// @Success 200
// @Security BearerAuth
// @Router /api/v1/whatsapp/logout [post]
func Logout(c echo.Context) error { func Logout(c echo.Context) error {
var err error var err error
jid := jwtPayload(c).JID jid := jwtPayload(c).JID
@ -105,6 +125,17 @@ func Logout(c echo.Context) error {
return router.ResponseSuccess(c, "Successfully Logged Out") return router.ResponseSuccess(c, "Successfully Logged Out")
} }
// SendText
// @Summary Logout Device from WhatsApp Multi-Device
// @Description Make Device Logout from WhatsApp Multi-Device
// @Tags WhatsApp
// @Accept */*
// @Produce json
// @Param msisdn query string true "Destination Phone Number"
// @Param message query string true "Text Message Content"
// @Success 200
// @Security BearerAuth
// @Router /api/v1/whatsapp/send/text [post]
func SendText(c echo.Context) error { func SendText(c echo.Context) error {
var err error var err error
jid := jwtPayload(c).JID jid := jwtPayload(c).JID

Loading…
Cancel
Save