swgin

package module
v0.0.0-...-2d6bdae Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MIT Imports: 8 Imported by: 0

README

Swgin

Help gin users generate swagger when defining routes

Install

go get github.com/fzdwx/swgin

Usage

type Req struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
	List []Item `json:"list"`
}

type Item struct {
	Java   string `json:"java"`
	Golang string `json:"golang"`
}

func main() {

	e := gin.New()
	s := swgin.New(e)

	s.Router(swgin.Router{
		Method:  "Get",
		Path:    "hello",
		Summary: "测试 hello",
		Body:    Req{},
		Handlers: []gin.HandlerFunc{
			func(context *gin.Context) {

			},
		},
	})

	o := s.Parse()

	bytes, err := json.Marshal(o)
	if err != nil {
		return
	}

	err = os.WriteFile("swagger.json", bytes, 0644)
	if err != nil {
		return
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PropertiesNameJson  = "json"
	PropertiesNameQuery = "query"

	RequiredName = "required"
)

Functions

This section is empty.

Types

type Router

type Router struct {
	Path        string
	Method      string
	Summary     string
	Description string

	Tags         []string
	Query        any
	Body         any
	ResponseType any

	Handlers []gin.HandlerFunc

	// extended properties
	Properties map[string]string
}

type RouterGroup

type RouterGroup struct {
	Path    string
	Routers []Router
}

type Swgin

type Swgin struct {
	Title       string
	Version     string
	Description string
	Host        string
	BasePath    string
	// contains filtered or unexported fields
}

func New

func New(e *gin.Engine) *Swgin

func (*Swgin) Group

func (s *Swgin) Group(rg RouterGroup) *Swgin

func (*Swgin) Parse

func (s *Swgin) Parse() swaggerObject

func (*Swgin) Router

func (s *Swgin) Router(r Router) *Swgin

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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