Skip to content

Latest commit

 

History

History

swagger

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Simple Swagger Implementation for Fiber

This example use fiber-swagger and swaggo (Go converter to Swagger Documentation 2.0)

Usage

  1. Download swaggo by using:

    $ go get -u github.com/swaggo/swag/cmd/swag
    
    # 1.16 or newer
    $ go install github.com/swaggo/swag/cmd/swag@latest
  2. Add comments to your API source code (example: handlers/book.go) or more details: swaggo documentation.

  3. Download fiber-swagger by using:

    $ go get -u github.com/arsmn/fiber-swagger/v2
  4. Import to your routes file (example: routes/routes.go):

    import swagger "github.com/arsmn/fiber-swagger/v2"
  5. Add swagger handler to routes as a middleware (example: routes/routes.go):

    app.Get("/docs/*", swagger.Handler) // default
    
    app.Get("/docs/*", swagger.New(swagger.Config{ // custom
    	URL: "http://example.com/doc.json",
        DeepLinking: false,
    }))
  6. Run the swaggo command in your Go project root directory which contain main.go file. This command will generate required files (docs and docs/doc.go)

    $ swag init
  7. Import docs directory that generated by Swag CLI to your main.go file:

    import _ "swagger/docs"
  8. Horray! You're ready to Go 🚀