diff --git a/cmd/main/main.go b/cmd/main/main.go index 128c99d..fc68748 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -8,9 +8,6 @@ package main // @contact.url https://github.com/dimaskiddo // @contact.email drh.dimasrestu@gmail.com -// @schemes http -// @host 127.0.0.1:3000 - // @securityDefinitions.basic BasicAuth // @securityDefinitions.apikey BearerAuth diff --git a/docs/docs.go b/docs/docs.go index 816e6d0..17e2593 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -19,7 +19,7 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/api/v1/whatsapp": { + "/": { "get": { "description": "Get The Server Status", "produces": [ @@ -36,7 +36,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/auth": { + "/auth": { "get": { "security": [ { @@ -58,7 +58,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/group": { + "/group": { "get": { "security": [ { @@ -80,7 +80,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/login": { + "/login": { "post": { "security": [ { @@ -119,7 +119,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/login/pair": { + "/login/pair": { "post": { "security": [ { @@ -144,7 +144,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/logout": { + "/logout": { "post": { "security": [ { @@ -166,7 +166,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/registered": { + "/registered": { "get": { "security": [ { @@ -197,7 +197,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/send/audio": { + "/send/audio": { "post": { "security": [ { @@ -238,7 +238,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/send/contact": { + "/send/contact": { "post": { "security": [ { @@ -286,7 +286,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/send/document": { + "/send/document": { "post": { "security": [ { @@ -327,7 +327,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/send/image": { + "/send/image": { "post": { "security": [ { @@ -382,7 +382,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/send/link": { + "/send/link": { "post": { "security": [ { @@ -429,7 +429,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/send/location": { + "/send/location": { "post": { "security": [ { @@ -477,7 +477,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/send/sticker": { + "/send/sticker": { "post": { "security": [ { @@ -518,7 +518,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/send/text": { + "/send/text": { "post": { "security": [ { @@ -559,7 +559,7 @@ const docTemplate = `{ } } }, - "/api/v1/whatsapp/send/video": { + "/send/video": { "post": { "security": [ { @@ -630,9 +630,9 @@ const docTemplate = `{ // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ Version: "1.x", - Host: "127.0.0.1:3000", + Host: "", BasePath: "", - Schemes: []string{"http"}, + Schemes: []string{}, Title: "Go WhatsApp Multi-Device REST API", Description: "This is WhatsApp Multi-Device Implementation in Go REST API", InfoInstanceName: "swagger", diff --git a/docs/swagger.json b/docs/swagger.json index 1d633fd..9d40b4f 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1,7 +1,4 @@ { - "schemes": [ - "http" - ], "swagger": "2.0", "info": { "description": "This is WhatsApp Multi-Device Implementation in Go REST API", @@ -13,9 +10,8 @@ }, "version": "1.x" }, - "host": "127.0.0.1:3000", "paths": { - "/api/v1/whatsapp": { + "/": { "get": { "description": "Get The Server Status", "produces": [ @@ -32,7 +28,7 @@ } } }, - "/api/v1/whatsapp/auth": { + "/auth": { "get": { "security": [ { @@ -54,7 +50,7 @@ } } }, - "/api/v1/whatsapp/group": { + "/group": { "get": { "security": [ { @@ -76,7 +72,7 @@ } } }, - "/api/v1/whatsapp/login": { + "/login": { "post": { "security": [ { @@ -115,7 +111,7 @@ } } }, - "/api/v1/whatsapp/login/pair": { + "/login/pair": { "post": { "security": [ { @@ -140,7 +136,7 @@ } } }, - "/api/v1/whatsapp/logout": { + "/logout": { "post": { "security": [ { @@ -162,7 +158,7 @@ } } }, - "/api/v1/whatsapp/registered": { + "/registered": { "get": { "security": [ { @@ -193,7 +189,7 @@ } } }, - "/api/v1/whatsapp/send/audio": { + "/send/audio": { "post": { "security": [ { @@ -234,7 +230,7 @@ } } }, - "/api/v1/whatsapp/send/contact": { + "/send/contact": { "post": { "security": [ { @@ -282,7 +278,7 @@ } } }, - "/api/v1/whatsapp/send/document": { + "/send/document": { "post": { "security": [ { @@ -323,7 +319,7 @@ } } }, - "/api/v1/whatsapp/send/image": { + "/send/image": { "post": { "security": [ { @@ -378,7 +374,7 @@ } } }, - "/api/v1/whatsapp/send/link": { + "/send/link": { "post": { "security": [ { @@ -425,7 +421,7 @@ } } }, - "/api/v1/whatsapp/send/location": { + "/send/location": { "post": { "security": [ { @@ -473,7 +469,7 @@ } } }, - "/api/v1/whatsapp/send/sticker": { + "/send/sticker": { "post": { "security": [ { @@ -514,7 +510,7 @@ } } }, - "/api/v1/whatsapp/send/text": { + "/send/text": { "post": { "security": [ { @@ -555,7 +551,7 @@ } } }, - "/api/v1/whatsapp/send/video": { + "/send/video": { "post": { "security": [ { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index d7ccbda..35ae997 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,4 +1,3 @@ -host: 127.0.0.1:3000 info: contact: email: drh.dimasrestu@gmail.com @@ -8,7 +7,7 @@ info: title: Go WhatsApp Multi-Device REST API version: 1.x paths: - /api/v1/whatsapp: + /: get: description: Get The Server Status produces: @@ -19,7 +18,7 @@ paths: summary: Show The Status of The Server tags: - Root - /api/v1/whatsapp/auth: + /auth: get: description: Get Authentication Token produces: @@ -32,7 +31,7 @@ paths: summary: Generate Authentication Token tags: - Root - /api/v1/whatsapp/group: + /group: get: description: Get Joined Groups Information from WhatsApp produces: @@ -45,7 +44,7 @@ paths: summary: Get Joined Groups Information tags: - WhatsApp Information - /api/v1/whatsapp/login: + /login: post: consumes: - multipart/form-data @@ -70,7 +69,7 @@ paths: summary: Generate QR Code for WhatsApp Multi-Device Login tags: - WhatsApp Authentication - /api/v1/whatsapp/login/pair: + /login/pair: post: consumes: - multipart/form-data @@ -85,7 +84,7 @@ paths: summary: Pair Phone for WhatsApp Multi-Device Login tags: - WhatsApp Authentication - /api/v1/whatsapp/logout: + /logout: post: description: Make Device Logout from WhatsApp Multi-Device produces: @@ -98,7 +97,7 @@ paths: summary: Logout Device from WhatsApp Multi-Device tags: - WhatsApp Authentication - /api/v1/whatsapp/registered: + /registered: get: description: Check WhatsApp Personal ID is Registered parameters: @@ -117,7 +116,7 @@ paths: summary: Check If WhatsApp Personal ID is Registered tags: - WhatsApp Information - /api/v1/whatsapp/send/audio: + /send/audio: post: consumes: - multipart/form-data @@ -143,7 +142,7 @@ paths: summary: Send Audio Message tags: - WhatsApp Message - /api/v1/whatsapp/send/contact: + /send/contact: post: consumes: - multipart/form-data @@ -175,7 +174,7 @@ paths: summary: Send Contact Message tags: - WhatsApp Message - /api/v1/whatsapp/send/document: + /send/document: post: consumes: - multipart/form-data @@ -202,7 +201,7 @@ paths: summary: Send Document Message tags: - WhatsApp Message - /api/v1/whatsapp/send/image: + /send/image: post: consumes: - multipart/form-data @@ -238,7 +237,7 @@ paths: summary: Send Image Message tags: - WhatsApp Message - /api/v1/whatsapp/send/link: + /send/link: post: consumes: - multipart/form-data @@ -268,7 +267,7 @@ paths: summary: Send Link Message tags: - WhatsApp Message - /api/v1/whatsapp/send/location: + /send/location: post: consumes: - multipart/form-data @@ -300,7 +299,7 @@ paths: summary: Send Location Message tags: - WhatsApp Message - /api/v1/whatsapp/send/sticker: + /send/sticker: post: consumes: - multipart/form-data @@ -327,7 +326,7 @@ paths: summary: Send Sticker Message tags: - WhatsApp Message - /api/v1/whatsapp/send/text: + /send/text: post: consumes: - multipart/form-data @@ -353,7 +352,7 @@ paths: summary: Send Text Message tags: - WhatsApp Message - /api/v1/whatsapp/send/video: + /send/video: post: consumes: - multipart/form-data @@ -389,8 +388,6 @@ paths: summary: Send Video Message tags: - WhatsApp Message -schemes: -- http securityDefinitions: BasicAuth: type: basic diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 4bf8924..fe161e8 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -20,7 +20,7 @@ import ( // @Produce json // @Success 200 // @Security BasicAuth -// @Router /api/v1/whatsapp/auth [get] +// @Router /auth [get] func Auth(c echo.Context) error { var reqAuthBasicInfo typAuth.RequestAuthBasicInfo var resAuthJWTData typAuth.ResponseAuthJWTData diff --git a/internal/index/index.go b/internal/index/index.go index 596851d..2d2c978 100644 --- a/internal/index/index.go +++ b/internal/index/index.go @@ -12,7 +12,7 @@ import ( // @Tags Root // @Produce json // @Success 200 -// @Router /api/v1/whatsapp [get] +// @Router / [get] func Index(c echo.Context) error { return router.ResponseSuccess(c, "Go WhatsApp Multi-Device REST is running") } diff --git a/internal/route.go b/internal/route.go index 4ac9aaf..af21140 100644 --- a/internal/route.go +++ b/internal/route.go @@ -6,6 +6,7 @@ import ( 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/router" @@ -19,9 +20,16 @@ import ( ) func Routes(e *echo.Echo) { + // Configure OpenAPI / Swagger + docs.SwaggerInfo.BasePath = router.BaseURL + // Route for Index // --------------------------------------------- e.GET(router.BaseURL, ctlIndex.Index) + e.GET(router.BaseURL+"/", ctlIndex.Index) + + // Route for OpenAPI / Swagger + // --------------------------------------------- e.GET(router.BaseURL+"/docs/*", eSwagger.WrapHandler) // Route for Auth diff --git a/internal/whatsapp/whatsapp.go b/internal/whatsapp/whatsapp.go index f272b4e..90a5a8b 100644 --- a/internal/whatsapp/whatsapp.go +++ b/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) // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/login [post] +// @Router /login [post] func Login(c echo.Context) error { var err error jid := jwtPayload(c).JID @@ -109,7 +109,7 @@ func Login(c echo.Context) error { // @Produce json // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/login/pair [post] +// @Router /login/pair [post] func LoginPair(c echo.Context) error { var err error jid := jwtPayload(c).JID @@ -143,7 +143,7 @@ func LoginPair(c echo.Context) error { // @Produce json // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/logout [post] +// @Router /logout [post] func Logout(c echo.Context) error { var err error jid := jwtPayload(c).JID @@ -164,7 +164,7 @@ func Logout(c echo.Context) error { // @Param msisdn query string true "WhatsApp Personal ID to Check" // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/registered [get] +// @Router /registered [get] func Registered(c echo.Context) error { jid := jwtPayload(c).JID remoteJID := strings.TrimSpace(c.QueryParam("msisdn")) @@ -188,7 +188,7 @@ func Registered(c echo.Context) error { // @Produce json // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/group [get] +// @Router /group [get] func GetGroup(c echo.Context) error { var err error jid := jwtPayload(c).JID @@ -211,7 +211,7 @@ func GetGroup(c echo.Context) error { // @Param message formData string true "Text Message" // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/send/text [post] +// @Router /send/text [post] func SendText(c echo.Context) error { var err error jid := jwtPayload(c).JID @@ -248,7 +248,7 @@ func SendText(c echo.Context) error { // @Param longitude formData number true "Location Longitude" // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/send/location [post] +// @Router /send/location [post] func SendLocation(c echo.Context) error { var err error jid := jwtPayload(c).JID @@ -290,7 +290,7 @@ func SendLocation(c echo.Context) error { // @Param phone formData string true "Contact Phone" // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/send/contact [post] +// @Router /send/contact [post] func SendContact(c echo.Context) error { var err error jid := jwtPayload(c).JID @@ -332,7 +332,7 @@ func SendContact(c echo.Context) error { // @Param url formData string true "Link URL" // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/send/link [post] +// @Router /send/link [post] func SendLink(c echo.Context) error { var err error jid := jwtPayload(c).JID @@ -369,7 +369,7 @@ func SendLink(c echo.Context) error { // @Param document formData file true "Document File" // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/send/document [post] +// @Router /send/document [post] func SendDocument(c echo.Context) error { return sendMedia(c, "document") } @@ -386,7 +386,7 @@ func SendDocument(c echo.Context) error { // @Param viewonce formData bool false "Is View Once" default(false) // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/send/image [post] +// @Router /send/image [post] func SendImage(c echo.Context) error { return sendMedia(c, "image") } @@ -401,7 +401,7 @@ func SendImage(c echo.Context) error { // @Param audio formData file true "Audio File" // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/send/audio [post] +// @Router /send/audio [post] func SendAudio(c echo.Context) error { return sendMedia(c, "audio") } @@ -418,7 +418,7 @@ func SendAudio(c echo.Context) error { // @Param viewonce formData bool false "Is View Once" default(false) // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/send/video [post] +// @Router /send/video [post] func SendVideo(c echo.Context) error { return sendMedia(c, "video") } @@ -433,7 +433,7 @@ func SendVideo(c echo.Context) error { // @Param sticker formData file true "Sticker File" // @Success 200 // @Security BearerAuth -// @Router /api/v1/whatsapp/send/sticker [post] +// @Router /send/sticker [post] func SendSticker(c echo.Context) error { return sendMedia(c, "sticker") }