Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.
/ swagger Public archive

wool handler to automatically generate RESTful API documentation with Swagger 2.0

License

Notifications You must be signed in to change notification settings

gowool/swagger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swagger

Wool handler 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 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 github.com/gowool/swagger

And import following in your code:

import "github.com/gowool/swagger" // wool swagger handler

Canonical example:

package main

import (
    "context"
    "github.com/gowool/swagger"
    _ "github.com/gowool/swagger/example/docs"
    "github.com/gowool/wool"
	"golang.org/x/exp/slog"
    "os"
)

// @title Swagger Example API
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/

// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host petstore.swagger.io
// @BasePath /api/v1
func main() {
	logger := slog.New(slog.HandlerOptions{Level: slog.LevelDebug}.NewJSONHandler(os.Stdout))
    w := wool.New(logger.WithGroup("wool"))
    swg := swagger.New(&swagger.Config{})
    w.GET("/swagger/...", swg.Handler)
    
    srv := wool.NewServer(&wool.ServerConfig{
        Address: ":1323",
    }, logger.WithGroup("server"))
    if err := srv.StartC(context.Background(), w); err != nil {
		srv.Log.Error("server error", err)
        os.Exit(1)
    }
}
  1. Run it, and browser to http://localhost:1323/swagger/index.html, you can see Swagger 2.0 Api documents.

License

Distributed under MIT License, please see license file within the code for more details.

About

wool handler to automatically generate RESTful API documentation with Swagger 2.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages