knife4jgo

package module
v0.0.0-...-3e6627e Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MulanPSL-2.0 Imports: 20 Imported by: 0

README

### 使用方式:

  1. example 包下为示例,直接执行即可

  2. extend为扩展包,都可以重新自定义

  • 2.1 - Cpdr ContextPathDuplicateRemoval // swagger查询api接口时,把根路径去掉,打开swagger页面时,url根路径会重复,如果没有重复可以不启用
  • 2.2 - Vem ValidatorErrorMessages // 自定义Validator验证错误描述信息
  • 2.3 - Cgwh CustomGinWrapHandler // 自定义gin.handler包装器,默认为panic统一拦截器
  • 2.4 - Acwh AssembleCustomWrapHandler // 把每个gin.Handler包装一层自定义CustomGinWrapHandler
  • 2.5 - Cver CustomValidatorErrorRes // 自定义参数验证错误响应体,默认为自定义的Result结构体
  • 2.6 - Cp ContextPath // 根路径:http://localhost:8080/example/doc.html# example为根路径
  1. 使用方法跟上面参考资料一致,本项目只做了一些增强功能

  2. 依赖导入命令 go get gitee.com/longyancang/knife4jgo

### 参考资料:

  1. https://gitee.com/youbeiwuhuan/knife4go?force_mobile=true
  2. https://github.com/wI2L/fizz
  3. https://github.com/loopfz/gadgeto/tree/master/tonic

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Integer  int32
	Long     int64
	Float    float32
	Double   float64
	String   string
	Byte     []byte
	Binary   []byte
	Boolean  bool
	DateTime time.Time
)

Primitive type helpers.

Functions

func Deprecated

func Deprecated(deprecated bool) func(*openapi.OperationInfo)

Deprecated marks the operation as deprecated.

func Description

func Description(desc string) func(*openapi.OperationInfo)

Description adds a description to an operation.

func Descriptionf

func Descriptionf(format string, a ...interface{}) func(*openapi.OperationInfo)

Descriptionf adds a description to an operation according to a format specifier.

func Header(name, desc string, model interface{}) func(*openapi.OperationInfo)

Header adds a header to the operation.

func ID

func ID(id string) func(*openapi.OperationInfo)

ID overrides the operation ID.

func InputModel

func InputModel(model interface{}) func(*openapi.OperationInfo)

InputModel overrides the binding model of the operation.

func OperationFromContext

func OperationFromContext(ctx context.Context) (*openapi.Operation, error)

OperationFromContext returns the OpenAPI operation from the given Gin context or an error if none is found.

func Response

func Response(statusCode, desc string, model interface{}, headers []*openapi.ResponseHeader, example interface{}) func(*openapi.OperationInfo)

Response adds an additional response to the operation.

func ResponseWithExamples

func ResponseWithExamples(statusCode, desc string, model interface{}, headers []*openapi.ResponseHeader, examples map[string]interface{}) func(*openapi.OperationInfo)

ResponseWithExamples is a variant of Response that accept many examples.

func Security

func Security(security *openapi.SecurityRequirement) func(*openapi.OperationInfo)

Overrides top-level security requirement for this operation. Note that this function can be used more than once to add several requirements.

func StatusDescription

func StatusDescription(desc string) func(*openapi.OperationInfo)

StatusDescription sets the default status description of the operation.

func Summary

func Summary(summary string) func(*openapi.OperationInfo)

Summary adds a summary to an operation.

func Summaryf

func Summaryf(format string, a ...interface{}) func(*openapi.OperationInfo)

Summaryf adds a summary to an operation according to a format specifier.

func WithOptionalSecurity

func WithOptionalSecurity() func(*openapi.OperationInfo)

Add an empty security requirement to this operation to make other security requirements optional.

func WithoutSecurity

func WithoutSecurity() func(*openapi.OperationInfo)

Remove any top-level security requirements for this operation.

func XCodeSample

func XCodeSample(cs *openapi.XCodeSample) func(*openapi.OperationInfo)

XCodeSample adds a code sample to the operation.

func XInternal

func XInternal() func(*openapi.OperationInfo)

XInternal marks the operation as internal.

Types

type Fizz

type Fizz struct {
	*RouterGroup
	// contains filtered or unexported fields
}

Fizz is an abstraction of a Gin engine that wraps the routes handlers with Tonic and generates an OpenAPI 3.0 specification from it.

func AddApiDocRouter

func AddApiDocRouter(router *gin.Engine, infos *openapi.Info) *Fizz

func InitSwaggerKnife

func InitSwaggerKnife(router *gin.Engine, infos *openapi.Info) *Fizz

func New

func New() *Fizz

New creates a new Fizz wrapper for a default Gin engine.

func NewFromEngine

func NewFromEngine(e *gin.Engine) *Fizz

NewFromEngine creates a new Fizz wrapper from an existing Gin engine.

func (*Fizz) Engine

func (f *Fizz) Engine() *gin.Engine

Engine returns the underlying Gin engine.

func (*Fizz) Errors

func (f *Fizz) Errors() []error

Errors returns the errors that may have occurred during the spec generation.

func (*Fizz) Generator

func (f *Fizz) Generator() *openapi.Generator

Generator returns the underlying OpenAPI generator.

func (*Fizz) GinRouterGroup

func (f *Fizz) GinRouterGroup() *gin.RouterGroup

GinRouterGroup returns the underlying Gin router group.

func (*Fizz) OpenAPI

func (f *Fizz) OpenAPI(info *openapi.Info, ct string) gin.HandlerFunc

OpenAPI returns a Gin HandlerFunc that serves the marshalled OpenAPI specification of the API.

func (*Fizz) ServeHTTP

func (f *Fizz) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.HandlerFunc for Fizz.

type OperationOption

type OperationOption func(*openapi.OperationInfo)

OperationOption represents an option-pattern function used to add informations to an operation.

type RouterGroup

type RouterGroup struct {
	Name        string
	Description string
	// contains filtered or unexported fields
}

RouterGroup is an abstraction of a Gin router group.

func (*RouterGroup) DELETE

func (g *RouterGroup) DELETE(path string, infos []OperationOption, handlers ...gin.HandlerFunc) *RouterGroup

DELETE is a shortcut to register a new handler with the DELETE method.

func (*RouterGroup) GET

func (g *RouterGroup) GET(path string, infos []OperationOption, handlers ...gin.HandlerFunc) *RouterGroup

GET is a shortcut to register a new handler with the GET method.

func (*RouterGroup) GinRouterGroup

func (g *RouterGroup) GinRouterGroup() *gin.RouterGroup

GinRouterGroup returns the underlying Gin router group.

func (*RouterGroup) Group

func (g *RouterGroup) Group(path, name, description string, handlers ...gin.HandlerFunc) *RouterGroup

Group creates a new group of routes.

func (*RouterGroup) HEAD

func (g *RouterGroup) HEAD(path string, infos []OperationOption, handlers ...gin.HandlerFunc) *RouterGroup

HEAD is a shortcut to register a new handler with the HEAD method.

func (*RouterGroup) Handle

func (g *RouterGroup) Handle(path, method string, infos []OperationOption, handlers ...gin.HandlerFunc) *RouterGroup

Handle registers a new request handler that is wrapped with Tonic and documented in the OpenAPI specification.

func (*RouterGroup) OPTIONS

func (g *RouterGroup) OPTIONS(path string, infos []OperationOption, handlers ...gin.HandlerFunc) *RouterGroup

OPTIONS is a shortcut to register a new handler with the OPTIONS method.

func (*RouterGroup) PATCH

func (g *RouterGroup) PATCH(path string, infos []OperationOption, handlers ...gin.HandlerFunc) *RouterGroup

PATCH is a shortcut to register a new handler with the PATCH method.

func (*RouterGroup) POST

func (g *RouterGroup) POST(path string, infos []OperationOption, handlers ...gin.HandlerFunc) *RouterGroup

POST is a shortcut to register a new handler with the POST method.

func (*RouterGroup) PUT

func (g *RouterGroup) PUT(path string, infos []OperationOption, handlers ...gin.HandlerFunc) *RouterGroup

PUT is a shortcut to register a new handler with the PUT method.

func (*RouterGroup) TRACE

func (g *RouterGroup) TRACE(path string, infos []OperationOption, handlers ...gin.HandlerFunc) *RouterGroup

TRACE is a shortcut to register a new handler with the TRACE method.

func (*RouterGroup) Use

func (g *RouterGroup) Use(handlers ...gin.HandlerFunc)

Use adds middleware to the group.

Jump to

Keyboard shortcuts

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