Browse Source

update openapi / swagger to follow dynamic ip and user defined base path from env of http base url

pull/61/head
Dimas Restu H 2 years ago
parent
commit
1df9038934
  1. 3
      cmd/main/main.go
  2. 36
      docs/docs.go
  3. 36
      docs/swagger.json
  4. 35
      docs/swagger.yaml
  5. 2
      internal/auth/auth.go
  6. 2
      internal/index/index.go
  7. 8
      internal/route.go
  8. 28
      internal/whatsapp/whatsapp.go

3
cmd/main/main.go

@ -8,9 +8,6 @@ package main
// @contact.url https://github.com/dimaskiddo // @contact.url https://github.com/dimaskiddo
// @contact.email drh.dimasrestu@gmail.com // @contact.email drh.dimasrestu@gmail.com
// @schemes http
// @host 127.0.0.1:3000
// @securityDefinitions.basic BasicAuth // @securityDefinitions.basic BasicAuth
// @securityDefinitions.apikey BearerAuth // @securityDefinitions.apikey BearerAuth

36
docs/docs.go

@ -19,7 +19,7 @@ const docTemplate = `{
"host": "{{.Host}}", "host": "{{.Host}}",
"basePath": "{{.BasePath}}", "basePath": "{{.BasePath}}",
"paths": { "paths": {
"/api/v1/whatsapp": {
"/": {
"get": { "get": {
"description": "Get The Server Status", "description": "Get The Server Status",
"produces": [ "produces": [
@ -36,7 +36,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/auth": {
"/auth": {
"get": { "get": {
"security": [ "security": [
{ {
@ -58,7 +58,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/group": {
"/group": {
"get": { "get": {
"security": [ "security": [
{ {
@ -80,7 +80,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/login": {
"/login": {
"post": { "post": {
"security": [ "security": [
{ {
@ -119,7 +119,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/login/pair": {
"/login/pair": {
"post": { "post": {
"security": [ "security": [
{ {
@ -144,7 +144,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/logout": {
"/logout": {
"post": { "post": {
"security": [ "security": [
{ {
@ -166,7 +166,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/registered": {
"/registered": {
"get": { "get": {
"security": [ "security": [
{ {
@ -197,7 +197,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/send/audio": {
"/send/audio": {
"post": { "post": {
"security": [ "security": [
{ {
@ -238,7 +238,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/send/contact": {
"/send/contact": {
"post": { "post": {
"security": [ "security": [
{ {
@ -286,7 +286,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/send/document": {
"/send/document": {
"post": { "post": {
"security": [ "security": [
{ {
@ -327,7 +327,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/send/image": {
"/send/image": {
"post": { "post": {
"security": [ "security": [
{ {
@ -382,7 +382,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/send/link": {
"/send/link": {
"post": { "post": {
"security": [ "security": [
{ {
@ -429,7 +429,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/send/location": {
"/send/location": {
"post": { "post": {
"security": [ "security": [
{ {
@ -477,7 +477,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/send/sticker": {
"/send/sticker": {
"post": { "post": {
"security": [ "security": [
{ {
@ -518,7 +518,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/send/text": {
"/send/text": {
"post": { "post": {
"security": [ "security": [
{ {
@ -559,7 +559,7 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/whatsapp/send/video": {
"/send/video": {
"post": { "post": {
"security": [ "security": [
{ {
@ -630,9 +630,9 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it // SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{ var SwaggerInfo = &swag.Spec{
Version: "1.x", Version: "1.x",
Host: "127.0.0.1:3000",
Host: "",
BasePath: "", BasePath: "",
Schemes: []string{"http"},
Schemes: []string{},
Title: "Go WhatsApp Multi-Device REST API", Title: "Go WhatsApp Multi-Device REST API",
Description: "This is WhatsApp Multi-Device Implementation in Go REST API", Description: "This is WhatsApp Multi-Device Implementation in Go REST API",
InfoInstanceName: "swagger", InfoInstanceName: "swagger",

36
docs/swagger.json

@ -1,7 +1,4 @@
{ {
"schemes": [
"http"
],
"swagger": "2.0", "swagger": "2.0",
"info": { "info": {
"description": "This is WhatsApp Multi-Device Implementation in Go REST API", "description": "This is WhatsApp Multi-Device Implementation in Go REST API",
@ -13,9 +10,8 @@
}, },
"version": "1.x" "version": "1.x"
}, },
"host": "127.0.0.1:3000",
"paths": { "paths": {
"/api/v1/whatsapp": {
"/": {
"get": { "get": {
"description": "Get The Server Status", "description": "Get The Server Status",
"produces": [ "produces": [
@ -32,7 +28,7 @@
} }
} }
}, },
"/api/v1/whatsapp/auth": {
"/auth": {
"get": { "get": {
"security": [ "security": [
{ {
@ -54,7 +50,7 @@
} }
} }
}, },
"/api/v1/whatsapp/group": {
"/group": {
"get": { "get": {
"security": [ "security": [
{ {
@ -76,7 +72,7 @@
} }
} }
}, },
"/api/v1/whatsapp/login": {
"/login": {
"post": { "post": {
"security": [ "security": [
{ {
@ -115,7 +111,7 @@
} }
} }
}, },
"/api/v1/whatsapp/login/pair": {
"/login/pair": {
"post": { "post": {
"security": [ "security": [
{ {
@ -140,7 +136,7 @@
} }
} }
}, },
"/api/v1/whatsapp/logout": {
"/logout": {
"post": { "post": {
"security": [ "security": [
{ {
@ -162,7 +158,7 @@
} }
} }
}, },
"/api/v1/whatsapp/registered": {
"/registered": {
"get": { "get": {
"security": [ "security": [
{ {
@ -193,7 +189,7 @@
} }
} }
}, },
"/api/v1/whatsapp/send/audio": {
"/send/audio": {
"post": { "post": {
"security": [ "security": [
{ {
@ -234,7 +230,7 @@
} }
} }
}, },
"/api/v1/whatsapp/send/contact": {
"/send/contact": {
"post": { "post": {
"security": [ "security": [
{ {
@ -282,7 +278,7 @@
} }
} }
}, },
"/api/v1/whatsapp/send/document": {
"/send/document": {
"post": { "post": {
"security": [ "security": [
{ {
@ -323,7 +319,7 @@
} }
} }
}, },
"/api/v1/whatsapp/send/image": {
"/send/image": {
"post": { "post": {
"security": [ "security": [
{ {
@ -378,7 +374,7 @@
} }
} }
}, },
"/api/v1/whatsapp/send/link": {
"/send/link": {
"post": { "post": {
"security": [ "security": [
{ {
@ -425,7 +421,7 @@
} }
} }
}, },
"/api/v1/whatsapp/send/location": {
"/send/location": {
"post": { "post": {
"security": [ "security": [
{ {
@ -473,7 +469,7 @@
} }
} }
}, },
"/api/v1/whatsapp/send/sticker": {
"/send/sticker": {
"post": { "post": {
"security": [ "security": [
{ {
@ -514,7 +510,7 @@
} }
} }
}, },
"/api/v1/whatsapp/send/text": {
"/send/text": {
"post": { "post": {
"security": [ "security": [
{ {
@ -555,7 +551,7 @@
} }
} }
}, },
"/api/v1/whatsapp/send/video": {
"/send/video": {
"post": { "post": {
"security": [ "security": [
{ {

35
docs/swagger.yaml

@ -1,4 +1,3 @@
host: 127.0.0.1:3000
info: info:
contact: contact:
email: drh.dimasrestu@gmail.com email: drh.dimasrestu@gmail.com
@ -8,7 +7,7 @@ info:
title: Go WhatsApp Multi-Device REST API title: Go WhatsApp Multi-Device REST API
version: 1.x version: 1.x
paths: paths:
/api/v1/whatsapp:
/:
get: get:
description: Get The Server Status description: Get The Server Status
produces: produces:
@ -19,7 +18,7 @@ paths:
summary: Show The Status of The Server summary: Show The Status of The Server
tags: tags:
- Root - Root
/api/v1/whatsapp/auth:
/auth:
get: get:
description: Get Authentication Token description: Get Authentication Token
produces: produces:
@ -32,7 +31,7 @@ paths:
summary: Generate Authentication Token summary: Generate Authentication Token
tags: tags:
- Root - Root
/api/v1/whatsapp/group:
/group:
get: get:
description: Get Joined Groups Information from WhatsApp description: Get Joined Groups Information from WhatsApp
produces: produces:
@ -45,7 +44,7 @@ paths:
summary: Get Joined Groups Information summary: Get Joined Groups Information
tags: tags:
- WhatsApp Information - WhatsApp Information
/api/v1/whatsapp/login:
/login:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -70,7 +69,7 @@ paths:
summary: Generate QR Code for WhatsApp Multi-Device Login summary: Generate QR Code for WhatsApp Multi-Device Login
tags: tags:
- WhatsApp Authentication - WhatsApp Authentication
/api/v1/whatsapp/login/pair:
/login/pair:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -85,7 +84,7 @@ paths:
summary: Pair Phone for WhatsApp Multi-Device Login summary: Pair Phone for WhatsApp Multi-Device Login
tags: tags:
- WhatsApp Authentication - WhatsApp Authentication
/api/v1/whatsapp/logout:
/logout:
post: post:
description: Make Device Logout from WhatsApp Multi-Device description: Make Device Logout from WhatsApp Multi-Device
produces: produces:
@ -98,7 +97,7 @@ paths:
summary: Logout Device from WhatsApp Multi-Device summary: Logout Device from WhatsApp Multi-Device
tags: tags:
- WhatsApp Authentication - WhatsApp Authentication
/api/v1/whatsapp/registered:
/registered:
get: get:
description: Check WhatsApp Personal ID is Registered description: Check WhatsApp Personal ID is Registered
parameters: parameters:
@ -117,7 +116,7 @@ paths:
summary: Check If WhatsApp Personal ID is Registered summary: Check If WhatsApp Personal ID is Registered
tags: tags:
- WhatsApp Information - WhatsApp Information
/api/v1/whatsapp/send/audio:
/send/audio:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -143,7 +142,7 @@ paths:
summary: Send Audio Message summary: Send Audio Message
tags: tags:
- WhatsApp Message - WhatsApp Message
/api/v1/whatsapp/send/contact:
/send/contact:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -175,7 +174,7 @@ paths:
summary: Send Contact Message summary: Send Contact Message
tags: tags:
- WhatsApp Message - WhatsApp Message
/api/v1/whatsapp/send/document:
/send/document:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -202,7 +201,7 @@ paths:
summary: Send Document Message summary: Send Document Message
tags: tags:
- WhatsApp Message - WhatsApp Message
/api/v1/whatsapp/send/image:
/send/image:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -238,7 +237,7 @@ paths:
summary: Send Image Message summary: Send Image Message
tags: tags:
- WhatsApp Message - WhatsApp Message
/api/v1/whatsapp/send/link:
/send/link:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -268,7 +267,7 @@ paths:
summary: Send Link Message summary: Send Link Message
tags: tags:
- WhatsApp Message - WhatsApp Message
/api/v1/whatsapp/send/location:
/send/location:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -300,7 +299,7 @@ paths:
summary: Send Location Message summary: Send Location Message
tags: tags:
- WhatsApp Message - WhatsApp Message
/api/v1/whatsapp/send/sticker:
/send/sticker:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -327,7 +326,7 @@ paths:
summary: Send Sticker Message summary: Send Sticker Message
tags: tags:
- WhatsApp Message - WhatsApp Message
/api/v1/whatsapp/send/text:
/send/text:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -353,7 +352,7 @@ paths:
summary: Send Text Message summary: Send Text Message
tags: tags:
- WhatsApp Message - WhatsApp Message
/api/v1/whatsapp/send/video:
/send/video:
post: post:
consumes: consumes:
- multipart/form-data - multipart/form-data
@ -389,8 +388,6 @@ paths:
summary: Send Video Message summary: Send Video Message
tags: tags:
- WhatsApp Message - WhatsApp Message
schemes:
- http
securityDefinitions: securityDefinitions:
BasicAuth: BasicAuth:
type: basic type: basic

2
internal/auth/auth.go

@ -20,7 +20,7 @@ import (
// @Produce json // @Produce json
// @Success 200 // @Success 200
// @Security BasicAuth // @Security BasicAuth
// @Router /api/v1/whatsapp/auth [get]
// @Router /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

2
internal/index/index.go

@ -12,7 +12,7 @@ import (
// @Tags Root // @Tags Root
// @Produce json // @Produce json
// @Success 200 // @Success 200
// @Router /api/v1/whatsapp [get]
// @Router / [get]
func Index(c echo.Context) error { func Index(c echo.Context) error {
return router.ResponseSuccess(c, "Go WhatsApp Multi-Device REST is running") return router.ResponseSuccess(c, "Go WhatsApp Multi-Device REST is running")
} }

8
internal/route.go

@ -6,6 +6,7 @@ import (
eSwagger "github.com/swaggo/echo-swagger" eSwagger "github.com/swaggo/echo-swagger"
"github.com/dimaskiddo/go-whatsapp-multidevice-rest/docs"
"github.com/dimaskiddo/go-whatsapp-multidevice-rest/pkg/auth" "github.com/dimaskiddo/go-whatsapp-multidevice-rest/pkg/auth"
"github.com/dimaskiddo/go-whatsapp-multidevice-rest/pkg/router" "github.com/dimaskiddo/go-whatsapp-multidevice-rest/pkg/router"
@ -19,9 +20,16 @@ import (
) )
func Routes(e *echo.Echo) { func Routes(e *echo.Echo) {
// Configure OpenAPI / Swagger
docs.SwaggerInfo.BasePath = router.BaseURL
// Route for Index // Route for Index
// --------------------------------------------- // ---------------------------------------------
e.GET(router.BaseURL, ctlIndex.Index) e.GET(router.BaseURL, ctlIndex.Index)
e.GET(router.BaseURL+"/", ctlIndex.Index)
// Route for OpenAPI / Swagger
// ---------------------------------------------
e.GET(router.BaseURL+"/docs/*", eSwagger.WrapHandler) e.GET(router.BaseURL+"/docs/*", eSwagger.WrapHandler)
// Route for Auth // Route for Auth

28
internal/whatsapp/whatsapp.go

@ -47,7 +47,7 @@ func convertFileToBytes(file multipart.File) ([]byte, error) {
// @Param output formData string false "Change Output Format in HTML or JSON" Enums(html, json) default(html) // @Param output formData string false "Change Output Format in HTML or JSON" Enums(html, json) default(html)
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/login [post]
// @Router /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
@ -109,7 +109,7 @@ func Login(c echo.Context) error {
// @Produce json // @Produce json
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/login/pair [post]
// @Router /login/pair [post]
func LoginPair(c echo.Context) error { func LoginPair(c echo.Context) error {
var err error var err error
jid := jwtPayload(c).JID jid := jwtPayload(c).JID
@ -143,7 +143,7 @@ func LoginPair(c echo.Context) error {
// @Produce json // @Produce json
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/logout [post]
// @Router /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
@ -164,7 +164,7 @@ func Logout(c echo.Context) error {
// @Param msisdn query string true "WhatsApp Personal ID to Check" // @Param msisdn query string true "WhatsApp Personal ID to Check"
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/registered [get]
// @Router /registered [get]
func Registered(c echo.Context) error { func Registered(c echo.Context) error {
jid := jwtPayload(c).JID jid := jwtPayload(c).JID
remoteJID := strings.TrimSpace(c.QueryParam("msisdn")) remoteJID := strings.TrimSpace(c.QueryParam("msisdn"))
@ -188,7 +188,7 @@ func Registered(c echo.Context) error {
// @Produce json // @Produce json
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/group [get]
// @Router /group [get]
func GetGroup(c echo.Context) error { func GetGroup(c echo.Context) error {
var err error var err error
jid := jwtPayload(c).JID jid := jwtPayload(c).JID
@ -211,7 +211,7 @@ func GetGroup(c echo.Context) error {
// @Param message formData string true "Text Message" // @Param message formData string true "Text Message"
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/send/text [post]
// @Router /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
@ -248,7 +248,7 @@ func SendText(c echo.Context) error {
// @Param longitude formData number true "Location Longitude" // @Param longitude formData number true "Location Longitude"
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/send/location [post]
// @Router /send/location [post]
func SendLocation(c echo.Context) error { func SendLocation(c echo.Context) error {
var err error var err error
jid := jwtPayload(c).JID jid := jwtPayload(c).JID
@ -290,7 +290,7 @@ func SendLocation(c echo.Context) error {
// @Param phone formData string true "Contact Phone" // @Param phone formData string true "Contact Phone"
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/send/contact [post]
// @Router /send/contact [post]
func SendContact(c echo.Context) error { func SendContact(c echo.Context) error {
var err error var err error
jid := jwtPayload(c).JID jid := jwtPayload(c).JID
@ -332,7 +332,7 @@ func SendContact(c echo.Context) error {
// @Param url formData string true "Link URL" // @Param url formData string true "Link URL"
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/send/link [post]
// @Router /send/link [post]
func SendLink(c echo.Context) error { func SendLink(c echo.Context) error {
var err error var err error
jid := jwtPayload(c).JID jid := jwtPayload(c).JID
@ -369,7 +369,7 @@ func SendLink(c echo.Context) error {
// @Param document formData file true "Document File" // @Param document formData file true "Document File"
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/send/document [post]
// @Router /send/document [post]
func SendDocument(c echo.Context) error { func SendDocument(c echo.Context) error {
return sendMedia(c, "document") return sendMedia(c, "document")
} }
@ -386,7 +386,7 @@ func SendDocument(c echo.Context) error {
// @Param viewonce formData bool false "Is View Once" default(false) // @Param viewonce formData bool false "Is View Once" default(false)
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/send/image [post]
// @Router /send/image [post]
func SendImage(c echo.Context) error { func SendImage(c echo.Context) error {
return sendMedia(c, "image") return sendMedia(c, "image")
} }
@ -401,7 +401,7 @@ func SendImage(c echo.Context) error {
// @Param audio formData file true "Audio File" // @Param audio formData file true "Audio File"
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/send/audio [post]
// @Router /send/audio [post]
func SendAudio(c echo.Context) error { func SendAudio(c echo.Context) error {
return sendMedia(c, "audio") return sendMedia(c, "audio")
} }
@ -418,7 +418,7 @@ func SendAudio(c echo.Context) error {
// @Param viewonce formData bool false "Is View Once" default(false) // @Param viewonce formData bool false "Is View Once" default(false)
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/send/video [post]
// @Router /send/video [post]
func SendVideo(c echo.Context) error { func SendVideo(c echo.Context) error {
return sendMedia(c, "video") return sendMedia(c, "video")
} }
@ -433,7 +433,7 @@ func SendVideo(c echo.Context) error {
// @Param sticker formData file true "Sticker File" // @Param sticker formData file true "Sticker File"
// @Success 200 // @Success 200
// @Security BearerAuth // @Security BearerAuth
// @Router /api/v1/whatsapp/send/sticker [post]
// @Router /send/sticker [post]
func SendSticker(c echo.Context) error { func SendSticker(c echo.Context) error {
return sendMedia(c, "sticker") return sendMedia(c, "sticker")
} }

Loading…
Cancel
Save