From 194c6ae81dcdd0e4d8b49601cee6963cc42f87dd Mon Sep 17 00:00:00 2001 From: nikhilnarayanan623 Date: Fri, 11 Aug 2023 19:06:04 +0530 Subject: [PATCH] swagger documentation updated --- cmd/api/docs/docs.go | 20 ++++++++++++++++---- cmd/api/docs/swagger.json | 17 ++++++++++++++++- cmd/api/docs/swagger.yaml | 14 +++++++++++++- pkg/api/server.go | 16 ++++++++++++++-- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/cmd/api/docs/docs.go b/cmd/api/docs/docs.go index d734e2d..55a3447 100644 --- a/cmd/api/docs/docs.go +++ b/cmd/api/docs/docs.go @@ -10,7 +10,14 @@ const docTemplate = `{ "info": { "description": "{{escape .Description}}", "title": "{{.Title}}", - "contact": {}, + "contact": { + "name": "For API Support", + "email": "nikhilnarayanan623@gmail.com" + }, + "license": { + "name": "MIT", + "url": "https://opensource.org/licenses/MIT" + }, "version": "{{.Version}}" }, "host": "{{.Host}}", @@ -4128,6 +4135,11 @@ const docTemplate = `{ } } } + }, + "securityDefinitions": { + "BasicAuth": { + "type": "basic" + } } }` @@ -4135,10 +4147,10 @@ const docTemplate = `{ var SwaggerInfo = &swag.Spec{ Version: "", Host: "", - BasePath: "", + BasePath: "/api", Schemes: []string{}, - Title: "", - Description: "", + Title: "E-commerce Application Backend API", + Description: "Backend API built with Golang using Clean Code architecture. \\nGithub: [https://github.com/nikhilnarayanan623/ecommerce-gin-clean-arch].", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", diff --git a/cmd/api/docs/swagger.json b/cmd/api/docs/swagger.json index 7cc7a68..9aef098 100644 --- a/cmd/api/docs/swagger.json +++ b/cmd/api/docs/swagger.json @@ -1,8 +1,18 @@ { "swagger": "2.0", "info": { - "contact": {} + "description": "Backend API built with Golang using Clean Code architecture. \\nGithub: [https://github.com/nikhilnarayanan623/ecommerce-gin-clean-arch].", + "title": "E-commerce Application Backend API", + "contact": { + "name": "For API Support", + "email": "nikhilnarayanan623@gmail.com" + }, + "license": { + "name": "MIT", + "url": "https://opensource.org/licenses/MIT" + } }, + "basePath": "/api", "paths": { "/account": { "get": { @@ -4116,5 +4126,10 @@ } } } + }, + "securityDefinitions": { + "BasicAuth": { + "type": "basic" + } } } \ No newline at end of file diff --git a/cmd/api/docs/swagger.yaml b/cmd/api/docs/swagger.yaml index 71bd540..e97ed9f 100644 --- a/cmd/api/docs/swagger.yaml +++ b/cmd/api/docs/swagger.yaml @@ -1,3 +1,4 @@ +basePath: /api definitions: request.Address: properties: @@ -460,7 +461,15 @@ definitions: type: string type: object info: - contact: {} + contact: + email: nikhilnarayanan623@gmail.com + name: For API Support + description: 'Backend API built with Golang using Clean Code architecture. \nGithub: + [https://github.com/nikhilnarayanan623/ecommerce-gin-clean-arch].' + license: + name: MIT + url: https://opensource.org/licenses/MIT + title: E-commerce Application Backend API paths: /account: get: @@ -2692,4 +2701,7 @@ paths: summary: Get all product items (User) tags: - User Products +securityDefinitions: + BasicAuth: + type: basic swagger: "2.0" diff --git a/pkg/api/server.go b/pkg/api/server.go index f2f7020..b927855 100644 --- a/pkg/api/server.go +++ b/pkg/api/server.go @@ -16,6 +16,18 @@ type ServerHTTP struct { Engine *gin.Engine } +// @title E-commerce Application Backend API +// @description Backend API built with Golang using Clean Code architecture. \nGithub: [https://github.com/nikhilnarayanan623/ecommerce-gin-clean-arch]. +// +// @contact.name For API Support +// @contact.email nikhilnarayanan623@gmail.com +// +// @license.name MIT +// @license.url https://opensource.org/licenses/MIT +// +// @BasePath /api +// +// @securityDefinitions.basic BasicAuth func NewServerHTTP(authHandler handlerInterface.AuthHandler, middleware middleware.Middleware, adminHandler handlerInterface.AdminHandler, userHandler handlerInterface.UserHandler, cartHandler handlerInterface.CartHandler, paymentHandler handlerInterface.PaymentHandler, @@ -33,9 +45,9 @@ func NewServerHTTP(authHandler handlerInterface.AuthHandler, middleware middlewa engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) // set up routes - routes.UserRoutes(engine.Group("/"), authHandler, middleware, userHandler, cartHandler, + routes.UserRoutes(engine.Group("/api"), authHandler, middleware, userHandler, cartHandler, productHandler, paymentHandler, orderHandler, couponHandler) - routes.AdminRoutes(engine.Group("/admin"), authHandler, middleware, adminHandler, + routes.AdminRoutes(engine.Group("/api/admin"), authHandler, middleware, adminHandler, productHandler, paymentHandler, orderHandler, couponHandler, offerHandler, stockHandler) // no handler