• Stars
    star
    384
  • Rank 111,726 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🧬 fiber middleware to automatically generate RESTful API documentation with Swagger

Swagger

Release Discord Test Security Linter

fiber middleware to automatically generate RESTful API documentation with Swagger

Usage

  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.16 or newer
go install github.com/swaggo/swag/cmd/swag@latest
  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 swagger by using:
go get -u github.com/gofiber/swagger

And import following in your code:

import "github.com/gofiber/swagger" // swagger handler

Canonical example:

package main

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

	// docs are generated by Swag CLI, you have to import them.
	// replace with your own docs folder, usually "github.com/username/reponame/docs"
	_ "github.com/gofiber/swagger/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 [email protected]
// @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.HandlerDefault) // default

	app.Get("/swagger/*", swagger.New(swagger.Config{ // custom
		URL: "http://example.com/doc.json",
		DeepLinking: false,
		// Expand ("list") or Collapse ("none") tag groups by default
		DocExpansion: "none",
		// Prefill OAuth ClientId on Authorize popup
		OAuth: &swagger.OAuthConfig{
			AppName:  "OAuth Provider",
			ClientId: "21bb4edc-05a7-4afc-86f1-2e151e4ba6e2",
		},
		// Ability to change OAuth2 redirect uri location
		OAuth2RedirectUrl: "http://localhost:8080/swagger/oauth2-redirect.html",
	}))

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

More Repositories

1

fiber

⚡️ Express inspired web framework written in Go
Go
32,846
star
2

recipes

📁 Examples for 🚀 Fiber
Go
3,042
star
3

awesome-fiber

✨ A curated list of awesome Fiber middlewares, boilerplates, recipes, articles and tools.
492
star
4

boilerplate

🚧 Boilerplate for 🚀 Fiber
Go
398
star
5

jwt

⚠️ Deprecated repository, available within Fiber Contrib.
Go
396
star
6

websocket

⚠️ Deprecated repository, available within Fiber Contrib.
Go
290
star
7

storage

📦 Premade storage drivers for 🚀 Fiber
Go
261
star
8

template

🧬 Template engine middleware for Fiber
Go
258
star
9

docs

📚 Documentation for 🚀 Fiber
JavaScript
211
star
10

contrib

🧬 Repository for third party middlewares with dependencies
Go
205
star
11

adaptor

🧬 Adaptor middleware to convert net/http handlers from/to Fiber request handlers
Go
182
star
12

cli

Fiber Command Line Interface
Go
85
star
13

helmet

🧬 Helmet middleware for Fiber
Go
80
star
14

keyauth

🧬 Key Authentication for Fiber
Go
77
star
15

utils

⚡ A collection of common functions but with better performance, less allocations and less dependencies created for Fiber.
Go
44
star
16

session

⚠ Deprecated, available within Fiber v2
Go
24
star
17

basicauth

⚠ Deprecated, available within Fiber v2
Go
17
star
18

redirect

🧬 Redirect middleware for Fiber
Go
15
star
19

website

🌈 The website of the 🚀 Fiber framework
TypeScript
14
star
20

cors

⚠ Deprecated, available within Fiber v2
Go
14
star
21

rewrite

🧬 Rewrite middleware for Fiber
Go
12
star
22

embed

⚠ Deprecated, available within Fiber v2
Go
11
star
23

limiter

⚠ Deprecated, available within Fiber v2
Go
10
star
24

proxy

⚠ Deprecated, available within Fiber v2
Go
8
star
25

logger

⚠ Deprecated, available within Fiber v2
Go
7
star
26

csrf

⚠ Deprecated, available within Fiber v2
Go
5
star
27

pprof

⚠ Deprecated, available within Fiber v2
Go
5
star
28

recover

⚠ Deprecated, available within Fiber v2
Go
2
star
29

compression

⚠ Deprecated, available within Fiber v2
Go
1
star