swagger

package module
v2.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: MIT Imports: 9 Imported by: 199

README

fiber-swagger

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

Usage

Start using it
  1. Add comments to your API source code, See Declarative Comments Format.
  2. Download Swag for Go by using:
$ go get -u github.com/swaggo/swag/cmd/swag
  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 fiber-swagger by using:
$ go get -u github.com/arsmn/fiber-swagger/v2

And import following in your code:

import "github.com/arsmn/fiber-swagger/v2" // fiber-swagger middleware

Canonical example:
package main

import (
	swagger "github.com/arsmn/fiber-swagger/v2"
	"github.com/gofiber/fiber/v2"

	// docs are generated by Swag CLI, you have to import them.
	_ "github.com/arsmn/fiber-swagger/v2/example/docs"
)

// @title Fiber Example API
// @version 1.0
// @description This is a sample swagger for Fiber
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.email fiber@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:8080
// @BasePath /
func main() {
	app := fiber.New()

	app.Get("/swagger/*", swagger.Handler) // default

	app.Get("/swagger/*", swagger.New(swagger.Config{ // custom
		URL: "http://example.com/doc.json",
		DeepLinking: false,
	}))

	app.Listen(":8080")
}
  1. Run it, and browser to http://localhost:8080/swagger, you can see Swagger 2.0 Api documents.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Handler = New()

Handler default

Functions

func New

func New(config ...Config) fiber.Handler

New returns custom handler

Types

type Config

type Config struct {
	DeepLinking bool
	URL         string
}

Config ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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