openapi

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Code generated by go-bindata. DO NOT EDIT. sources: internal/static/favicon.png internal/static/redoc.standalone.js internal/static/swagger-ui-bundle.js internal/static/swagger-ui.css

Index

Constants

View Source
const (
	IntMaximum   int64 = Int64Maximum
	IntMinimum   int64 = Int64Minimum
	Int8Maximum  int64 = 127
	Int8Minimum  int64 = -128
	Int16Maximum int64 = 32767
	Int16Minimum int64 = -32768
	Int32Maximum int64 = 2147483647
	Int32Minimum int64 = -2147483648
	Int64Maximum int64 = 9223372036854775807
	Int64Minimum int64 = -9223372036854775808

	UintMaximum   uint64 = Uint64Maximum
	UintMinimum   uint64 = Uint64Minimum
	Uint8Maximum  uint64 = 255
	Uint8Minimum  uint64 = 0
	Uint16Maximum uint64 = 65535
	Uint16Minimum uint64 = 0
	Uint32Maximum uint64 = 4294967295
	Uint32Minimum uint64 = 0
	Uint64Maximum uint64 = 9223372036854775809
	Uint64Minimum uint64 = 0
)
View Source
const (
	SwaggerCssName    = "swagger-ui.css"
	FaviconName       = "favicon.png"
	FaviconIcoName    = "favicon.ico"
	SwaggerJsName     = "swagger-ui-bundle.js"
	RedocJsName       = "redoc.standalone.js"
	JsonUrl           = "openapi.json"
	DocumentUrl       = "/docs"
	ReDocumentUrl     = "/redoc"
	SwaggerFaviconUrl = "https://fastapi.tiangolo.com/img/" + FaviconName
	SwaggerCssUrl     = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/" + SwaggerCssName
	SwaggerJsUrl      = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/" + SwaggerJsName
	RedocJsUrl        = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/" + RedocJsName
)

用于swagger的一些静态文件,来自FastApi

View Source
const (
	RefName              = "$ref"
	RefPrefix            = "#/components/schemas/"
	ArrayTypeSuffix      = "_List" // 对于数组类型,关联到一个新模型
	GenericTypeConnector = "_About_"
	InnerModelNamePrefix = "fastapi."
)
View Source
const (
	TimeParamSchemaFormat     = "time"
	DateParamSchemaFormat     = "date"
	DateTimeParamSchemaFormat = "date-time"
	FileParamSchemaFormat     = "binary"
)
View Source
const (
	MIMETextJavaScript             string = "text/javascript"
	MIMEApplicationForm            string = "application/x-www-form-urlencoded"
	MIMEOctetStream                string = "application/octet-stream"
	MIMEMultipartForm              string = "multipart/form-data"
	MIMETextXML                    string = "text/xml"
	MIMETextXMLCharsetUTF8         string = "text/xml; charset=utf-8"
	MIMETextHTML                   string = "text/html"
	MIMETextHTMLCharsetUTF8        string = "text/html; charset=utf-8"
	MIMETextPlain                  string = "text/plain"
	MIMETextPlainCharsetUTF8       string = "text/plain; charset=utf-8"
	MIMETextCSS                    string = "text/css"
	MIMETextCSSCharsetUTF8         string = "text/css; charset=utf-8"
	MIMETextJavaScriptCharsetUTF8  string = "text/javascript; charset=utf-8"
	MIMEApplicationXML             string = "application/xml"
	MIMEApplicationXMLCharsetUTF8  string = "application/xml; charset=utf-8"
	MIMEApplicationTOML            string = "application/toml"
	MIMEApplicationTOMLCharsetUTF8 string = "application/toml; charset=utf-8"
	MIMEApplicationYAML            string = "application/x-yaml"
	MIMEApplicationYAMLCharsetUTF8 string = "application/x-yaml; charset=utf-8"
	MIMEApplicationJSON            string = "application/json"
	MIMEApplicationJSONCharsetUTF8 string = "application/json; charset=utf-8"

	MIMEJpg  = "image/jpeg"
	MIMEJpeg = "image/jpeg"
	MIMEPng  = "image/png"
	MIMEGif  = "image/gif"
	MIMETiff = "image/tiff"
	MIMEBmp  = "image/bmp"
	MIMEWebp = "image/webp"
	MIMESvg  = "image/svg+xml"
	MIMEPdf  = "application/pdf"
	MIMEZip  = "application/zip"
	MIMEPpt  = "application/vnd.ms-powerpoint"
	MIMEWord = "application/msword"
	MIMEXls  = "application/vnd.ms-excel"
)
View Source
const (
	CookiesParamType = "cookies" // 声明一个cookies参数
	HeadersParamType = "header"  // 声明一个header参数
	PathParamType    = "path"    // 声明一个路径参数,不同与路由path{}定义混用
)
View Source
const (
	SchemaDescMethodName string = "SchemaDesc"
	SchemaTypeMethodName string = "SchemaType"
)
View Source
const (
	ValidationErrorName     string = "ValidationError"
	HttpValidationErrorName string = "HTTPValidationError"
)
View Source
const AnonymousModelNameConnector = "_"

AnonymousModelNameConnector 为匿名结构体生成一个名称, 连接符

View Source
const ApiVersion = "3.1.0"
View Source
const CustomQueryNameConnector = "_"

CustomQueryNameConnector 为无法获得函数参数名称的入参生成一个参数名程,连接符

View Source
const HeaderContentType = "Content-Type"
View Source
const ReminderWhenResponseModelIsNil = " `| 路由未明确定义返回值,文档处缺省为map类型,实际可以是任意类型`"
View Source
const RouteMethodSeparator = "=|_0#0_|="

RouteMethodSeparator 路由分隔符,用于分割路由方法和路径

View Source
const TimePkg = "time.Time"

Variables

View Source
var (
	ValidateTagName    = "validate"
	QueryTagName       = "query"
	JsonTagName        = "json"
	DescriptionTagName = "description"
	DefaultValueTagNam = "default"
	ParamRequiredLabel = requiredTag
)

IllegalRouteParamType 不支持的参数类型

View Source
var InnerModelsName = []string{
	"BaseModel",
	"BaseModelField",
	"BaseGroupRouter",
}

InnerModelsName 特殊的内部模型名称

View Source
var InnerModelsPkg = []string{
	"fastapi.BaseModel",
	"fastapi.BaseModelField",
	"fastapi.BaseGroupRouter",
	"time.Location",
	"time.zone",
	"time.zoneTrans",
}
View Source
var RouteErrorOption = &RouteErrorOpt{
	StatusCode:   http.StatusInternalServerError,
	ResponseMode: nil,
	Description:  http.StatusText(http.StatusInternalServerError),
}
View Source
var ValidationErrorDefinition = &ValidationError{}

ValidationErrorDefinition 422 表单验证错误模型

View Source
var ValidationErrorResponseDefinition = &HTTPValidationError{}

ValidationErrorResponseDefinition 请求体相应体错误消息

View Source
var ValidatorLabelToOpenapiLabel = map[string]string{
	"required":      "required",
	"omitempty":     "omitempty",
	"len":           "len",
	"eq":            "eq",
	"gt":            "minimum",
	"gte":           "exclusiveMinimum",
	"lt":            "maximum",
	"lte":           "exclusiveMaximum",
	"eqfield":       "eqfield",
	"nefield":       "nefield",
	"gtfield":       "gtfield",
	"gtefield":      "gtefield",
	"ltfield":       "ltfield",
	"ltefield":      "ltefield",
	"eqcsfield":     "eqcsfield",
	"necsfield":     "necsfield",
	"gtcsfield":     "gtcsfield",
	"gtecsfield":    "gtecsfield",
	"ltcsfield":     "ltcsfield",
	"ltecsfield":    "ltecsfield",
	"min":           "minLength",
	"max":           "maxLength",
	"structonly":    "structonly",
	"nostructlevel": "nostructlevel",

	"dive": "dive",

	"dive Keys & EndKeys": "dive Keys & EndKeys",
	"required_with":       "required_with",
	"required_with_all":   "required_with_all",
	"isdefault":           "default",
	"oneof":               "enum",
	"containsfield":       "containsfield",
	"excludesfield":       "excludesfield",
	"unique":              "unique",
	"alphanum":            "alphanum",
	"alphaunicode":        "alphaunicode",
	"numeric":             "numeric",
	"hexadecimal":         "hexadecimal",
	"hexcolor":            "hexcolor",
	"lowercase":           "lowercase",
	"uppercase":           "uppercase",
	"email":               "email",
	"json":                "json",
	"file":                "file",
	"url":                 "url",
	"uri":                 "uri",
	"base64":              "base64",
	"contains":            "contains",
	"containsany":         "containsany",
	"containsrune":        "containsrune",
	"excludes":            "excludes",
	"excludesall":         "excludesall",
	"excludesrune":        "excludesrune",
	"startswith":          "startswith",
	"endswith":            "endswith",
	"ip":                  "ip",

	"datetime":  "datetime:2006-01-02 15:04:05",
	"timestamp": "timestamp",
	"ipv4":      "ipv4",
	"ipv6":      "ipv6",
	"cidr":      "cidr",
	"cidrv4":    "cidrv4",
	"cidrv6":    "cidrv6",
	"rgb":       "rgb",
	"rgba":      "rgba",
}

ValidatorLabelToOpenapiLabel validator 标签和 Openapi 标签的对应关系

Functions

func AddUtf8Charset added in v0.2.9

func AddUtf8Charset(m string) string

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func AssignGenericModelPkg added in v0.2.0

func AssignGenericModelPkg(modelString string) string

AssignGenericModelPkg 为范型结构体重新指定一个包名

func CreateRouteIdentify added in v0.2.0

func CreateRouteIdentify(method, url string) string

CreateRouteIdentify 获得一个路由对象的唯一标识

func GetDefaultV added in v0.1.5

func GetDefaultV(tag reflect.StructTag, otype DataType) (v any)

GetDefaultV 从Tag中提取字段默认值

func IsFieldRequired added in v0.1.5

func IsFieldRequired(tag reflect.StructTag) bool

IsFieldRequired 从tag中判断此字段是否是必须的

func IsGenericModel added in v0.2.0

func IsGenericModel(name string) bool

IsGenericModel 从 reflect.Type.String() 中判断是不是泛型结构体

func IsGenericModelByType added in v0.2.0

func IsGenericModelByType(rt reflect.Type) bool

IsGenericModelByType 从反射信息中判断是不是泛型结构体

func MakeOauth2RedirectHtml

func MakeOauth2RedirectHtml() string

func MakeRedocUiHtml

func MakeRedocUiHtml(title, openapiUrl, jsUrl, faviconUrl string) string

func MakeSwaggerUiHtml

func MakeSwaggerUiHtml(title, openapiUrl, jsUrl, cssUrl, faviconUrl string) string

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func ParseGenericModelName added in v0.2.0

func ParseGenericModelName(name string) []string

ParseGenericModelName 解析范型类型的名称 如果模型是范型,则返回数组的长度 >=2

# Example:

*test.PageResp[*test.MemoryNote] 	=> ["*test.PageResp", "*test.MemoryNote"]
test.PageResp[int] 					=> ["test.PageResp", "int"]
test.PageResp[Sheet[int]]			=> ["test.PageResp", "Sheet", "int"]

func ReflectCallSchemaDesc added in v0.2.0

func ReflectCallSchemaDesc(re reflect.Type) string

ReflectCallSchemaDesc 反射调用结构体的 SchemaDesc 方法

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func ToFastApiRoutePath added in v0.2.0

func ToFastApiRoutePath(path string) string

ToFastApiRoutePath 将 fiber.App 格式的路径转换成 FastApi 格式的路径

Example:
必选路径参数:
	Input: "/api/rcst/:no"
	Output: "/api/rcst/{no}"
可选路径参数:
	Input: "/api/rcst/:no?"
	Output: "/api/rcst/{no}"
常规路径:
	Input: "/api/rcst/no"
	Output: "/api/rcst/no"

Types

type ArgsType added in v0.1.5

type ArgsType struct {
	// contains filtered or unexported fields
}

func (ArgsType) FieldType added in v0.1.5

func (m ArgsType) FieldType() reflect.Type

func (ArgsType) IsAnonymousStruct added in v0.1.5

func (m ArgsType) IsAnonymousStruct() bool

func (ArgsType) String added in v0.1.5

func (m ArgsType) String() string

type BaseModelField added in v0.2.0

type BaseModelField struct {
	Pkg         string            `description:"包名.结构体名.字段名"`
	Name        string            `json:"name" description:"字段名称"`
	DataType    DataType          `json:"data_type" description:"openapi 数据类型"`
	Tag         reflect.StructTag `json:"tag" description:"字段标签"`
	Description string            `json:"description,omitempty" description:"说明"`
	ItemRef     string            `description:"子元素类型, 仅Type=array/object时有效"`
	Exported    bool              `description:"是否是导出字段"`
	Anonymous   bool              `description:"是否是嵌入字段"`
	// contains filtered or unexported fields
}

BaseModelField 模型的字段元数据 基本数据模型, 此模型不可再分, 同时也是 ModelSchema 的字段类型 但此类型不再递归记录,仅记录一个关联模型为基本

func (*BaseModelField) Init added in v0.2.0

func (f *BaseModelField) Init() (err error)

func (*BaseModelField) InnerSchema added in v0.2.0

func (f *BaseModelField) InnerSchema() []SchemaIface

InnerSchema 内部字段模型文档

func (*BaseModelField) IsArray added in v0.2.0

func (f *BaseModelField) IsArray() bool

IsArray 字段是否是数组类型

func (*BaseModelField) IsRequired added in v0.2.0

func (f *BaseModelField) IsRequired() bool

IsRequired 字段是否必须

func (*BaseModelField) JsonName added in v0.2.0

func (f *BaseModelField) JsonName() string

func (*BaseModelField) Schema added in v0.2.0

func (f *BaseModelField) Schema() (m map[string]any)

Schema 生成字段的详细描述信息

// 字段为结构体类型

"position_sat": {
	"title": "position_sat",
	"type": "object"
	"description": "position_sat",
	"required": false,
	"$ref": "#/comonents/schemas/example.PositionGeo",
}

// 字段为数组类型, 数组元素为基本类型

"traffic_timeslot": {
	"title": "traffic_timeslot",
	"type": "array"
	"description": "业务时隙编号数组",
	"required": false,
	"items": {
		"type": "integer"
	},
}

// 字段为数组类型, 数组元素为自定义结构体类型

"Detail": {
	"title": "Detail",
	"type": "array"
	"description": "Detail",
	"required": true,
	"items": {
		"$ref": "#/comonents/schemas/ValidationError"
	},
}

func (*BaseModelField) SchemaDesc added in v0.2.0

func (f *BaseModelField) SchemaDesc() string

SchemaDesc 字段注释说明

func (*BaseModelField) SchemaPkg added in v0.2.0

func (f *BaseModelField) SchemaPkg() string

func (*BaseModelField) SchemaTitle added in v0.2.0

func (f *BaseModelField) SchemaTitle() string

SchemaTitle swagger文档字段名

func (*BaseModelField) SchemaType added in v0.2.0

func (f *BaseModelField) SchemaType() DataType

SchemaType 模型类型

type BaseModelMeta added in v0.2.0

type BaseModelMeta struct {
	Param *RouteParam

	Description string `description:"模型描述"`
	// contains filtered or unexported fields
}

BaseModelMeta 所有数据模型 ModelSchema 的元信息

func BaseModelMetaFrom added in v0.2.8

func BaseModelMetaFrom(obj any, index int, paramType RouteParamType) (*BaseModelMeta, error)

BaseModelMetaFrom 反射结构体获得 BaseModelMeta

func NewBaseModelMeta added in v0.2.0

func NewBaseModelMeta(param *RouteParam) *BaseModelMeta

func (*BaseModelMeta) HasValidateTag added in v0.2.0

func (m *BaseModelMeta) HasValidateTag() bool

HasValidateTag 是否定义了validate标签

func (*BaseModelMeta) Init added in v0.2.0

func (m *BaseModelMeta) Init() (err error)

func (*BaseModelMeta) InnerSchema added in v0.2.0

func (m *BaseModelMeta) InnerSchema() []SchemaIface

InnerSchema 内部字段模型文档

func (*BaseModelMeta) IsRequired added in v0.2.0

func (m *BaseModelMeta) IsRequired() bool

IsRequired 模型都是必须的

func (*BaseModelMeta) JsonName added in v0.2.0

func (m *BaseModelMeta) JsonName() string

func (*BaseModelMeta) Name added in v0.2.0

func (m *BaseModelMeta) Name() string

func (*BaseModelMeta) Scan added in v0.2.0

func (m *BaseModelMeta) Scan() (err error)

func (*BaseModelMeta) ScanInner added in v0.2.0

func (m *BaseModelMeta) ScanInner() (err error)

func (*BaseModelMeta) Schema added in v0.2.0

func (m *BaseModelMeta) Schema() (dict map[string]any)

Schema 输出为OpenAPI文档模型,字典格式 数组类型: 需要单独处理, 取其内部 itemModel 作为子元素的实际类型 结构体类型: 需处理全部的 fields 和 innerModels

func (*BaseModelMeta) SchemaDesc added in v0.2.0

func (m *BaseModelMeta) SchemaDesc() string

SchemaDesc 模型文档注释

func (*BaseModelMeta) SchemaPkg added in v0.2.0

func (m *BaseModelMeta) SchemaPkg() string

func (*BaseModelMeta) SchemaTitle added in v0.2.0

func (m *BaseModelMeta) SchemaTitle() string

SchemaTitle 获取结构体的名称,默认包含包名

func (*BaseModelMeta) SchemaType added in v0.2.0

func (m *BaseModelMeta) SchemaType() DataType

SchemaType 模型类型

type ComponentScheme

type ComponentScheme struct {
	Model SchemaIface `json:"model" description:"模型定义"`
	Name  string      `json:"name" description:"模型名称,包含包名"`
}

ComponentScheme openapi 的模型文档部分

type Components

type Components struct {
	Scheme []*ComponentScheme `json:"scheme" description:"模型文档"`
}

Components openapi 的模型部分 需要重写序列化方法

func (*Components) AddModel

func (c *Components) AddModel(m SchemaIface)

AddModel 添加一个模型文档

func (*Components) MarshalJSON

func (c *Components) MarshalJSON() ([]byte, error)

MarshalJSON 重载序列化方法

type Contact

type Contact struct {
	Name  string `json:"name" description:"姓名/名称"`
	Url   string `json:"url" description:"链接"`
	Email string `json:"email" description:"联系方式"`
}

Contact 联系方式, 显示在 info 字段内部 无需重写序列化方法

type DataType added in v0.1.5

type DataType string
const (
	IntegerType DataType = "integer"
	NumberType  DataType = "number"
	StringType  DataType = "string"
	BoolType    DataType = "boolean"
	ObjectType  DataType = "object"
	ArrayType   DataType = "array"
)

func ReflectKindToType added in v0.2.0

func ReflectKindToType(kind reflect.Kind) (name DataType)

ReflectKindToType 转换reflect.Kind为swagger类型说明

@param	ReflectKind	reflect.Kind	反射类型,不进一步对指针类型进行上浮

func (DataType) IsBaseType added in v0.2.0

func (m DataType) IsBaseType() bool

type HTTPValidationError added in v0.1.5

type HTTPValidationError struct {
	Detail []*ValidationError `json:"detail" description:"Detail" binding:"required"`
}

func (*HTTPValidationError) Error added in v0.1.5

func (v *HTTPValidationError) Error() string

func (*HTTPValidationError) InnerSchema added in v0.2.0

func (v *HTTPValidationError) InnerSchema() []SchemaIface

InnerSchema 内部字段模型文档

func (*HTTPValidationError) JsonName added in v0.2.0

func (v *HTTPValidationError) JsonName() string

func (*HTTPValidationError) Schema added in v0.1.5

func (v *HTTPValidationError) Schema() map[string]any

func (*HTTPValidationError) SchemaDesc added in v0.1.5

func (v *HTTPValidationError) SchemaDesc() string

func (*HTTPValidationError) SchemaPkg added in v0.2.0

func (v *HTTPValidationError) SchemaPkg() string

func (*HTTPValidationError) SchemaTitle added in v0.2.0

func (v *HTTPValidationError) SchemaTitle() string

func (*HTTPValidationError) SchemaType added in v0.1.5

func (v *HTTPValidationError) SchemaType() DataType

func (*HTTPValidationError) String added in v0.1.5

func (v *HTTPValidationError) String() string

type Info

type Info struct {
	Title          string  `json:"title" description:"显示在文档顶部的标题"`
	Version        string  `json:"version" description:"显示在标题右上角的程序版本号"`
	Description    string  `json:"description,omitempty" description:"显示在标题下方的说明"`
	Contact        Contact `json:"contact,omitempty" description:"联系方式"`
	License        License `json:"license,omitempty" description:"许可证"`
	TermsOfService string  `json:"termsOfService,omitempty" description:"服务条款(不常用)"`
}

Info 文档说明信息 无需重写序列化方法

type License

type License struct {
	Name string `json:"name" description:"名称"`
	Url  string `json:"url" description:"链接"`
}

License 权利证书, 显示在 info 字段内部 无需重写序列化方法

type ModelContentSchema

type ModelContentSchema interface {
	Schema() map[string]any
	SchemaType() DataType
	SchemaTitle() string
	SchemaPkg() string
}

type ModelSchema added in v0.2.0

type ModelSchema interface {
	SchemaDesc() string   // 模型文档注释
	SchemaType() DataType // 模型类型
	IsRequired() bool     // 模型是否必须
}

ModelSchema 数据模型定义 作为路由请求体或响应体的数据模型都必须实现此方法

type OpenApi

type OpenApi struct {
	Info       *Info       `json:"info,omitempty" description:"联系信息"`
	Components *Components `json:"components" description:"模型文档"`
	Paths      *Paths      `json:"paths" description:"路由列表,同一路由存在多个方法文档"`
	Version    string      `json:"openapi" description:"Open API版本号"`
	// contains filtered or unexported fields
}

OpenApi 模型类, 移除 FastApi 中不常用的属性

func NewOpenApi

func NewOpenApi(title, version, description string) *OpenApi

NewOpenApi 构造一个新的 OpenApi 文档

func (*OpenApi) AddContact added in v0.2.0

func (o *OpenApi) AddContact(info Contact) *OpenApi

func (*OpenApi) AddDefinition

func (o *OpenApi) AddDefinition(meta SchemaIface) *OpenApi

AddDefinition 手动添加一个模型文档

func (*OpenApi) AddLicense added in v0.2.0

func (o *OpenApi) AddLicense(info License) *OpenApi

func (*OpenApi) RecreateDocs

func (o *OpenApi) RecreateDocs() *OpenApi

RecreateDocs 重建Swagger 文档

func (*OpenApi) RegisterFrom added in v0.2.0

func (o *OpenApi) RegisterFrom(swagger *RouteSwagger) *OpenApi

RegisterFrom home point

func (*OpenApi) Schema

func (o *OpenApi) Schema() []byte

Schema Swagger 文档, 并非完全符合 OpenApi 文档规范

type Operation

type Operation struct {
	Tags        []string `json:"tags,omitempty" description:"路由标签"`
	Summary     string   `json:"summary,omitempty" description:"摘要描述"`
	Description string   `json:"description,omitempty" description:"说明"`
	OperationId string   `json:"operationId,omitempty" description:"唯一ID"` // no use, keep
	// 路径参数和查询参数, 对于路径相同,方法不同的路由来说,其查询参数可以不一样,但其路径参数都是一样的
	Parameters []*Parameter `json:"parameters,omitempty" description:"路径参数和查询参数"`
	// 请求体,通过 MakeOperationRequestBody 构建
	RequestBody *RequestBody `json:"requestBody,omitempty" description:"请求体"`
	// 响应文档,对于任一个路由,均包含2个固定的响应实例:200 + 422 和一个可选的 RouteErrorFormatter 响应实例, 通过函数 ResponseFrom 构建
	Responses  []*Response `json:"responses,omitempty" description:"响应体"`
	Deprecated bool        `json:"deprecated,omitempty" description:"是否禁用"`
}

Operation 路由HTTP方法: Get/Post/Patch/Delete 等操作方法

func (*Operation) MarshalJSON

func (o *Operation) MarshalJSON() ([]byte, error)

MarshalJSON 重写序列化方法,修改 Responses 和 RequestBody 字段

func (*Operation) RequestBodyFrom added in v0.2.0

func (o *Operation) RequestBodyFrom(model *BaseModelMeta) *Operation

RequestBodyFrom 从 *openapi.BaseModelMeta 转换成 openapi 的请求体 RequestBody

func (*Operation) ResponseFrom added in v0.2.0

func (o *Operation) ResponseFrom(model *BaseModelMeta) *Operation

ResponseFrom 从 *openapi.BaseModelMeta 转换成 openapi 的响应实例

type Parameter

type Parameter struct {
	Default any              `json:"default,omitempty" description:"默认值"`
	Schema  *ParameterSchema `json:"schema,omitempty" description:"字段模型"`
	ParameterBase
}

Parameter 路径参数或者查询参数

func (*Parameter) FromQModel added in v0.2.0

func (p *Parameter) FromQModel(model *QModel) *Parameter

type ParameterBase

type ParameterBase struct {
	Name        string          `json:"name" description:"名称"`
	Description string          `json:"description,omitempty" description:"说明"`
	In          ParameterInType `json:"in" description:"参数位置"`
	Required    bool            `json:"required" description:"是否必须"`
	Deprecated  bool            `json:"deprecated" description:"是否禁用"`
}

ParameterBase 各种参数的基类

type ParameterInType

type ParameterInType string
const (
	InQuery  ParameterInType = "query"
	InHeader ParameterInType = "header"
	InPath   ParameterInType = "path"
	InCookie ParameterInType = "cookie"
)

type ParameterSchema

type ParameterSchema struct {
	Type   DataType `json:"type" description:"数据类型"`
	Title  string   `json:"title"`
	Format string   `json:"format,omitempty" description:"针对特殊类型的格式化参数"`
}

type PathItem

type PathItem struct {
	Get    *Operation `json:"get,omitempty" description:"GET方法"`
	Put    *Operation `json:"put,omitempty" description:"PUT方法"`
	Post   *Operation `json:"post,omitempty" description:"POST方法"`
	Patch  *Operation `json:"patch,omitempty" description:"PATCH方法"`
	Delete *Operation `json:"delete,omitempty" description:"DELETE方法"`
	Head   *Operation `json:"head,omitempty" description:"header方法"`
	Trace  *Operation `json:"trace,omitempty" description:"trace方法"`
	Path   string     `json:"-" description:"请求绝对路径"`
}

PathItem 路由选项,由于同一个路由可以存在不同的操作方法,因此此选项可以存在多个 Operation

type PathModelContent

type PathModelContent struct {
	Schema   ModelContentSchema `json:"schema" description:"模型引用文档"`
	MIMEType string             `json:"-"`
}

PathModelContent 路由中请求体 RequestBody 和 响应体中返回值 Responses 模型

func (*PathModelContent) MarshalJSON

func (p *PathModelContent) MarshalJSON() ([]byte, error)

MarshalJSON 自定义序列化

type Paths

type Paths struct {
	Paths []*PathItem
}

Paths openapi 的路由部分 需要重写序列化方法

func (*Paths) AddItem

func (p *Paths) AddItem(item *PathItem)

func (*Paths) MarshalJSON

func (p *Paths) MarshalJSON() ([]byte, error)

MarshalJSON 重载序列化方法

type QModel added in v0.1.5

type QModel struct {
	Name     string            `json:"name,omitempty" description:"字段名称"`
	DataType DataType          `json:"data_type,omitempty" description:"openapi 数据类型"`
	Tag      reflect.StructTag `json:"tag,omitempty" description:"TAG"`
	JName    string            `json:"json_name,omitempty" description:"json标签名"`
	QName    string            `json:"query_name,omitempty" description:"query标签名"`
	Desc     string            `json:"description,omitempty" description:"参数描述"`
	Kind     reflect.Kind      `json:"Kind,omitempty" description:"反射类型"`
	Required bool              `json:"required,omitempty" description:"是否必须"`
	InPath   bool              `json:"in_path,omitempty" description:"是否是路径参数"`
	InStruct bool              `json:"in_struct,omitempty" description:"是否是结构体字段参数"`
	IsTime   bool              `json:"is_time,omitempty" description:"是否是时间类型"`
}

QModel 查询参数或路径参数元数据, 此类型对应于swagger中的: openapi.Parameter

func StructToQModels added in v0.2.0

func StructToQModels(rt reflect.Type) []*QModel

StructToQModels 将一个结构体的每一个导出字段都转换为一个查询参数 对于结构体字段,仅支持基本的数据类型和time.Time类型,不支持数组类型和自定义结构体类型

func (*QModel) Init added in v0.2.0

func (q *QModel) Init() (err error)

Init 解析并缓存字段名

func (*QModel) InnerSchema added in v0.1.5

func (q *QModel) InnerSchema() []SchemaIface

InnerSchema 内部字段模型文档

func (*QModel) IsRequired added in v0.1.5

func (q *QModel) IsRequired() bool

IsRequired 是否必须

func (*QModel) JsonName added in v0.2.0

func (q *QModel) JsonName() string

JsonName 对于查询参数结构体,其文档名称 tag 默认为 query query -> json -> fieldName

func (*QModel) Schema added in v0.1.5

func (q *QModel) Schema() (m map[string]any)

Schema 输出为OpenAPI文档模型,字典格式

{
	"required": true,
	"schema": {
		"title": "names",
		"type": "string",
		"default": "jack"
	},
	"name": "names",
	"in": "query"/"path"
}

func (*QModel) SchemaDesc added in v0.1.5

func (q *QModel) SchemaDesc() string

SchemaDesc 结构体文档注释

func (*QModel) SchemaPkg added in v0.2.0

func (q *QModel) SchemaPkg() string

func (*QModel) SchemaTitle added in v0.2.0

func (q *QModel) SchemaTitle() string

func (*QModel) SchemaType added in v0.1.5

func (q *QModel) SchemaType() DataType

SchemaType 模型类型

type Reference

type Reference struct {
	// 关联模型, 取值为 RefPrefix + modelName
	Name string `json:"-" description:"关联模型"`
}

Reference 引用模型,用于模型字段和路由之间互相引用

func (*Reference) MarshalJSON

func (r *Reference) MarshalJSON() ([]byte, error)

type RequestBody

type RequestBody struct {
	Content  *PathModelContent `json:"content,omitempty" description:"请求体模型"`
	Required bool              `json:"required" description:"是否必须"`
}

RequestBody 路由 请求体模型文档

type Response

type Response struct {
	Content     *PathModelContent `json:"content" description:"返回值模型"`
	Description string            `json:"description,omitempty" description:"说明"`
	StatusCode  int               `json:"-" description:"状态码"`
}

Response 路由返回体,包含了返回状态码,状态码说明和返回值模型

type RouteErrorOpt added in v0.2.8

type RouteErrorOpt struct {
	StatusCode   int            `json:"statusCode" validate:"required" description:"请求错误时的状态码"`
	ResponseMode *BaseModelMeta `json:"responseMode" validate:"required" description:"请求错误时的响应体,空则为字符串"`
	Description  string         `json:"description,omitempty" description:"错误文档"`
}

RouteErrorOpt 错误处理函数选项

type RouteParam added in v0.2.0

type RouteParam struct {
	Prototype      reflect.Type   `description:"直接反射后获取的类型,未提取指针指向的类型"`
	Name           string         `description:"名称"`
	Pkg            string         `description:"包含包名,如果是结构体则为: 包名.结构体名, 处理了指针"`
	QueryName      string         `` /* 129-byte string literal not displayed */
	DataType       DataType       `description:"如果是指针,则为指针指向的类型定义"`
	RouteParamType RouteParamType `description:"参数路由类型, 并非完全准确, 只在限制范围内访问"`
	PrototypeKind  reflect.Kind   `description:"原始类型的参数类型"`
	Index          int            `` /* 141-byte string literal not displayed */
	IsPtr          bool           `description:"标识 Prototype 是否是指针类型"`
	IsTime         bool           `description:"是否是时间类型"`
	IsGeneric      bool           `description:"是否是泛型结构体"`
	IsNil          bool           `description:"todo"`
}

RouteParam 路由参数的原始类型信息(由反射获得) 具体包含查询参数,路径参数,请求体参数和响应体参数

func NewRouteParam added in v0.2.0

func NewRouteParam(rt reflect.Type, index int, paramType RouteParamType) *RouteParam

func (*RouteParam) CopyPrototype added in v0.2.0

func (r *RouteParam) CopyPrototype() reflect.Type

CopyPrototype 将原始模型的 reflect.Type 拷贝一份

func (*RouteParam) ElemKind added in v0.2.0

func (r *RouteParam) ElemKind() reflect.Kind

ElemKind 获得子元素的真实类型 如果是指针类型,则上浮获得实际元素的类型; 如果是数组/切片类型, 则获得元素的类型 如果是 [][]any 类型的,则为[]any类型

func (*RouteParam) Init added in v0.2.0

func (r *RouteParam) Init() (err error)

Init 初始化类型反射信息,此方法在所有 Scanner.Init 之前调用

func (*RouteParam) InnerSchema added in v0.2.0

func (r *RouteParam) InnerSchema() []SchemaIface

InnerSchema 内部字段模型文档

func (*RouteParam) IsRequired added in v0.2.0

func (r *RouteParam) IsRequired() bool

func (*RouteParam) JsonName added in v0.2.0

func (r *RouteParam) JsonName() string

func (*RouteParam) NewNotStruct added in v0.2.0

func (r *RouteParam) NewNotStruct(value any) reflect.Value

NewNotStruct 通过反射创建一个(非struct类型)新的参数实例

func (*RouteParam) Rename added in v0.2.0

func (r *RouteParam) Rename(pkg, name string)

func (*RouteParam) Scan added in v0.2.0

func (r *RouteParam) Scan() (err error)

func (*RouteParam) ScanInner added in v0.2.0

func (r *RouteParam) ScanInner() (err error)

func (*RouteParam) Schema added in v0.2.0

func (r *RouteParam) Schema() (m map[string]any)

func (*RouteParam) SchemaDesc added in v0.2.0

func (r *RouteParam) SchemaDesc() string

func (*RouteParam) SchemaPkg added in v0.2.0

func (r *RouteParam) SchemaPkg() string

func (*RouteParam) SchemaTitle added in v0.2.0

func (r *RouteParam) SchemaTitle() string

func (*RouteParam) SchemaType added in v0.2.0

func (r *RouteParam) SchemaType() DataType

type RouteParamType added in v0.2.0

type RouteParamType string

RouteParamType 路由参数类型

const (
	RouteParamQuery    RouteParamType = "query"
	RouteParamPath     RouteParamType = "path"
	RouteParamRequest  RouteParamType = "requestBody"
	RouteParamResponse RouteParamType = "responseBody"
)

type RouteSwagger added in v0.2.0

type RouteSwagger struct {
	RequestModel        *BaseModelMeta `description:"请求体元数据"`
	ResponseModel       *BaseModelMeta `description:"响应体元数据"`
	Summary             string         `json:"summary" description:"摘要描述"`
	Url                 string         `json:"url" description:"完整请求路由"`
	Description         string         `json:"description" description:"详细描述"`
	Method              string         `json:"method" description:"请求方法"`
	RelativePath        string         `json:"relative_path" description:"相对路由"`
	RequestContentType  string         `` /* 126-byte string literal not displayed */
	ResponseContentType string         `` /* 127-byte string literal not displayed */
	Api                 string         `description:"用作唯一标识"`
	Tags                []string       `json:"tags" description:"路由标签"`
	PathFields          []*QModel      `json:"-" description:"路径参数"`
	QueryFields         []*QModel      `json:"-" description:"查询参数"`
	UploadFile          SchemaIface    `json:"-" description:"是否是上传文件,不能与RequestModel共存"`
	Deprecated          bool           `json:"deprecated" description:"是否禁用"`
}

RouteSwagger 路由文档定义,所有类型的路由均包含此部分

func (*RouteSwagger) Id added in v0.2.0

func (r *RouteSwagger) Id() string

func (*RouteSwagger) Init added in v0.2.0

func (r *RouteSwagger) Init() (err error)

func (*RouteSwagger) Scan added in v0.2.0

func (r *RouteSwagger) Scan() (err error)

func (*RouteSwagger) ScanInner added in v0.2.0

func (r *RouteSwagger) ScanInner() (err error)

ScanInner 解析内部模型数据

type SchemaIface added in v0.1.5

type SchemaIface interface {
	ModelSchema
	SchemaPkg() string          // 包名.模型名
	SchemaTitle() string        // 获取模型名不包含包名, 如果是结构体字段,则为字段原始名称
	JsonName() string           // 通常情况下与 SchemaTitle 相同,如果是结构体字段,则为字段json标签的值
	Schema() (m map[string]any) // 输出为OpenAPI文档模型,字典格式
	InnerSchema() []SchemaIface // 适用于数组类型,以及结构体字段仍为结构体的类型
}

SchemaIface 定义数据模型 对于泛型接口响应体模型必须实现此接口 对于接口体方法接口则通过反射判断是否实现了此接口

type UploadFileMeta added in v0.2.0

type UploadFileMeta struct {
	// contains filtered or unexported fields
}

UploadFileMeta 上传文件

func (*UploadFileMeta) ContentType added in v0.2.0

func (f *UploadFileMeta) ContentType() string

func (*UploadFileMeta) InnerSchema added in v0.2.0

func (f *UploadFileMeta) InnerSchema() []SchemaIface

func (*UploadFileMeta) IsRequired added in v0.2.0

func (f *UploadFileMeta) IsRequired() bool

func (*UploadFileMeta) JsonName added in v0.2.0

func (f *UploadFileMeta) JsonName() string

func (*UploadFileMeta) Schema added in v0.2.0

func (f *UploadFileMeta) Schema() (m map[string]any)

func (*UploadFileMeta) SchemaDesc added in v0.2.0

func (f *UploadFileMeta) SchemaDesc() string

func (*UploadFileMeta) SchemaPkg added in v0.2.0

func (f *UploadFileMeta) SchemaPkg() string

func (*UploadFileMeta) SchemaTitle added in v0.2.0

func (f *UploadFileMeta) SchemaTitle() string

func (*UploadFileMeta) SchemaType added in v0.2.0

func (f *UploadFileMeta) SchemaType() DataType

type ValidationError added in v0.1.5

type ValidationError struct {
	Ctx  map[string]any `json:"service,omitempty" description:"附加消息"`
	Type string         `json:"type" binding:"required" description:"参数类型"`
	Msg  string         `json:"msg" binding:"required" description:"错误消息"`
	Loc  []string       `json:"loc" binding:"required" description:"参数定位"`
}

ValidationError 参数校验错误

func (*ValidationError) Error added in v0.1.5

func (v *ValidationError) Error() string

func (*ValidationError) InnerSchema added in v0.2.0

func (v *ValidationError) InnerSchema() []SchemaIface

InnerSchema 内部字段模型文档

func (*ValidationError) JsonName added in v0.2.0

func (v *ValidationError) JsonName() string

func (*ValidationError) Schema added in v0.1.5

func (v *ValidationError) Schema() (m map[string]any)

func (*ValidationError) SchemaDesc added in v0.1.5

func (v *ValidationError) SchemaDesc() string

func (*ValidationError) SchemaPkg added in v0.2.0

func (v *ValidationError) SchemaPkg() string

func (*ValidationError) SchemaTitle added in v0.2.0

func (v *ValidationError) SchemaTitle() string

func (*ValidationError) SchemaType added in v0.1.5

func (v *ValidationError) SchemaType() DataType

Jump to

Keyboard shortcuts

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