package module
Version: v1.2.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2022 License: MIT Imports: 9 Imported by: 88



echo middleware to automatically generate RESTful API documentation with Swagger 2.0.

Build Status Codecov branch Go Report Card Release


Start using it
  1. Add comments to your API source code, See Declarative Comments Format.
  2. Download Swag for Go by using:
$ go get -d

# 1.16 or newer
$ go install
  1. Run the Swag in your Go project root folder which contains main.go file, Swag will parse comments and generate required files(docs folder and docs/doc.go).
$ swag init
  1. Download echo-swagger by using:
$ go get -u

And import following in your code:

import "" // echo-swagger middleware
Canonical example:
package main

import (

	_ "" // docs is generated by Swag CLI, you have to import it.

// @title Swagger Example API
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService

// API Support
// @contact.url

// Apache 2.0
// @license.url

// @host
// @BasePath /v2
func main() {
	e := echo.New()

	e.GET("/swagger/*", echoSwagger.WrapHandler)


  1. Run it, and browser to http://localhost:1323/swagger/index.html, you can see Swagger 2.0 Api documents.


Note: If you are using Gzip middleware you should add the swagger endpoint to skipper

		Skipper: func(c echo.Context) bool {
			if strings.Contains(c.Request().URL.Path, "swagger") {
				return true
			return false




This section is empty.


View Source
var WrapHandler = EchoWrapHandler()

WrapHandler wraps swaggerFiles.Handler and returns echo.HandlerFunc


func DeepLinking added in v1.1.2

func DeepLinking(deepLinking bool) func(c *Config)

DeepLinking true, false.

func DocExpansion added in v1.1.2

func DocExpansion(docExpansion string) func(c *Config)

DocExpansion list, full, none.

func DomID added in v1.1.2

func DomID(domID string) func(c *Config)

DomID #swagger-ui.

func EchoWrapHandler

func EchoWrapHandler(configFns ...func(c *Config)) echo.HandlerFunc

EchoWrapHandler wraps `http.Handler` into `echo.HandlerFunc`.

func InstanceName added in v1.1.5

func InstanceName(instanceName string) func(c *Config)

InstanceName specified swag instance name

func URL

func URL(url string) func(c *Config)

URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).


type Config

type Config struct {
	// The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `mockedSwag.json`.
	URL          string
	DeepLinking  bool
	DocExpansion string
	DomID        string
	InstanceName string

Config stores echoSwagger configuration variables.

Source Files


Path Synopsis
Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT This file was generated by swaggo/swag
Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT This file was generated by swaggo/swag

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL