openapi

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 15 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 (
	ValidationErrorName     string = "ValidationError"
	HttpValidationErrorName string = "HTTPValidationError"
)
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"
	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 (
	PathParamPrefix         = ":" // 路径参数起始字符
	PathSeparator           = "/" // 路径分隔符
	OptionalPathParamSuffix = "?" // 可选路径参数结束字符
)
View Source
const (
	MIMETextXML                    string = "text/xml"
	MIMETextHTML                   string = "text/html"
	MIMETextPlain                  string = "text/plain"
	MIMETextCSS                    string = "text/css"
	MIMETextJavaScript             string = "text/javascript"
	MIMEApplicationXML             string = "application/xml"
	MIMEApplicationJSON            string = "application/json"
	MIMEApplicationForm            string = "application/x-www-form-urlencoded"
	MIMEOctetStream                string = "application/octet-stream"
	MIMEMultipartForm              string = "multipart/form-data"
	MIMETextXMLCharsetUTF8         string = "text/xml; charset=utf-8"
	MIMETextHTMLCharsetUTF8        string = "text/html; charset=utf-8"
	MIMETextPlainCharsetUTF8       string = "text/plain; charset=utf-8"
	MIMETextCSSCharsetUTF8         string = "text/css; charset=utf-8"
	MIMETextJavaScriptCharsetUTF8  string = "text/javascript; charset=utf-8"
	MIMEApplicationXMLCharsetUTF8  string = "application/xml; charset=utf-8"
	MIMEApplicationJSONCharsetUTF8 string = "application/json; charset=utf-8"
)
View Source
const (
	RefName              = "$ref"
	RefPrefix            = "#/components/schemas/"
	ArrayTypePrefix      = "ArrayOf" // 对于数组类型,关联到一个新模型
	InnerModelNamePrefix = "fastapi."
)
View Source
const AnonymousModelNameConnector = "_"

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

View Source
const ApiVersion = "3.1.0"
View Source
const HeaderContentType = "Content-Type"

Variables

View Source
var (
	Int8 = makeMetadata(
		"int8",
		"8位有符号的数字类型",
		`json:"int8" gte:"-128" lte:"127"`,
		IntegerType,
	)

	Int16 = makeMetadata(
		"int16",
		"16位有符号的数字类型",
		`json:"int16" gte:"-32768" lte:"32767"`,
		IntegerType,
	)

	Int32 = makeMetadata(
		"int32",
		"32位有符号的数字类型",
		`json:"int32" gte:"-2147483648" lte:"2147483647"`,
		IntegerType,
	)

	Int64 = makeMetadata(
		"int64",
		"64位有符号的数字类型",
		`json:"int64" gte:"-9223372036854775808" lte:"9223372036854775807"`,
		IntegerType,
	)

	Int = makeMetadata(
		"int",
		"有符号的数字类型",
		`json:"int" gte:"-9223372036854775808" lte:"9223372036854775807"`,
		IntegerType,
	)

	Uint8 = makeMetadata(
		"uint8",
		"8位无符号的数字类型",
		`json:"uint8" gte:"0" lte:"255"`,
		IntegerType,
	)

	Uint16 = makeMetadata(
		"uint16",
		"16位无符号的数字类型",
		`json:"uint16" gte:"0" lte:"65535"`,
		IntegerType,
	)

	Uint32 = makeMetadata(
		"uint32",
		"32位无符号的数字类型",
		`json:"uint32" gte:"0" lte:"4294967295"`,
		IntegerType,
	)

	Uint64 = makeMetadata(
		"uint64",
		"64位无符号的数字类型",
		`json:"uint64" gte:"0" lte:"18446744073709551615"`,
		IntegerType,
	)

	Float32 = makeMetadata(
		"float32",
		"32位的浮点类型",
		`json:"float32"`,
		NumberType,
	)

	Float64 = makeMetadata(
		"float64",
		"64位的浮点类型",
		`json:"float64"`,
		NumberType,
	)

	Float = makeMetadata(
		"float",
		"64位的浮点类型",
		`json:"float"`,
		NumberType,
	)

	String = makeMetadata(
		"string",
		"字符串类型",
		`json:"string" min:"0" max:"255"`,
		StringType,
	)

	Bool = makeMetadata(
		"bool",
		"布尔类型",
		`json:"boolean" oneof:"true false"`,
		BoolType,
	)
)
View Source
var Resp422 = &Response{
	StatusCode:  http.StatusUnprocessableEntity,
	Description: http.StatusText(http.StatusUnprocessableEntity),
	Content: &PathModelContent{
		MIMEType: MIMEApplicationJSON,
		Schema:   &ValidationError{},
	},
}
View Source
var ValidationErrorDefinition = &ValidationError{}

ValidationErrorDefinition 422 表单验证错误模型

View Source
var ValidationErrorResponseDefinition = &HTTPValidationError{}

ValidationErrorResponseDefinition 请求体相应体错误消息

Functions

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 FastApiRoutePath

func FastApiRoutePath(path string) string

FastApiRoutePath 将 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"

func GetDefaultV added in v0.1.5

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

GetDefaultV 从Tag中提取字段默认值

func IsArray added in v0.1.5

func IsArray(object any) bool

IsArray 判断一个对象是否是数组类型

func IsFieldRequired added in v0.1.5

func IsFieldRequired(tag reflect.StructTag) bool

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

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 QueryFieldTag added in v0.1.5

func QueryFieldTag(tag reflect.StructTag, label string, undefined string) string

QueryFieldTag 查找struct字段的Tag

@param	tag			reflect.StructTag	字段的Tag
@param	label		string				要查找的标签
@param	undefined	string				当查找的标签不存在时返回的默认值
@return	string 查找到的标签值, 不存在则返回提供的默认值

func QueryJsonName added in v0.1.5

func QueryJsonName(tag reflect.StructTag, undefined string) string

QueryJsonName 查询字段定义的json名称

func ReflectObjectType added in v0.1.5

func ReflectObjectType(obj any) reflect.Type

ReflectObjectType 获取任意对象的类型,若为指针,则反射具体的类型

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 StringsToFloats added in v0.1.5

func StringsToFloats(strs []string) []float64

StringsToFloats 将字符串数组转换成float64数组, 简单实现

@param	strs		[]string	输入字符串数组
@return	[]float64 	输出float64数组

func StringsToInts added in v0.1.5

func StringsToInts(strs []string) []int

StringsToInts 将字符串数组转换成int数组, 简单实现

@param	strs	[]string	输入字符串数组
@return	[]int 	输出int数组

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 BaseModel added in v0.1.5

type BaseModel struct{}

BaseModel 基本数据模型, 对于上层的 app.Route 其请求和相应体都应为继承此结构体的结构体 在 OpenApi 文档模型中,此模型的类型始终为 "object"; 对于 BaseModel 其字段仍然可能会 BaseModel

func (*BaseModel) ID added in v0.1.5

func (b *BaseModel) ID() string

func (*BaseModel) IsRequired added in v0.1.5

func (b *BaseModel) IsRequired() bool

func (*BaseModel) Metadata added in v0.1.5

func (b *BaseModel) Metadata() (*Metadata, error)

Metadata 获取反射后的字段元信息, 此字段应慎重使用

func (*BaseModel) Schema added in v0.1.5

func (b *BaseModel) Schema() (m map[string]any)

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

{
	"title": "examle.MyTimeslot",
	"type": "object"
	"description": "examle.mytimeslot",
	"required": [],
	"properties": {
		"control_timeslot": {
			"title": "control_timeslot",
			"type": "array"
			"description": "控制时隙编号数组",
			"required": false,
			"items": {
				"type": "integer"
			},
		},
		"superframe_count": {
			"title": "superframe_count",
			"type": "integer"
			"description": "超帧计数",
			"required": false,
		},
	},
},

func (*BaseModel) SchemaDesc added in v0.1.5

func (b *BaseModel) SchemaDesc() string

SchemaDesc 结构体文档注释

func (*BaseModel) SchemaName added in v0.1.5

func (b *BaseModel) SchemaName(exclude ...bool) string

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

@param	exclude	[]bool	是否排除包名LL

func (*BaseModel) SchemaType added in v0.1.5

func (b *BaseModel) SchemaType() DataType

SchemaType 模型类型

type ComponentScheme

type ComponentScheme struct {
	Model *Metadata `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 *Metadata)

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 ReflectKindToOType added in v0.1.5

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

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

@param	ReflectKind	reflect.Kind	反射类型

type Field added in v0.1.5

type Field struct {
	Title       string            `json:"title,omitempty" description:"字段名称"`
	Type        DataType          `json:"type,omitempty" description:"openapi 数据类型"`
	Tag         reflect.StructTag `json:"tag" description:"字段标签"`
	Description string            `json:"description,omitempty" description:"说明"`
	ItemRef     string            `description:"子元素类型, 仅Type=array/object时有效"`
	// contains filtered or unexported fields
}

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

func (*Field) InnerSchema added in v0.1.5

func (f *Field) InnerSchema() (m map[string]map[string]any)

InnerSchema 内部字段模型文档, 全名:文档

func (*Field) IsArray added in v0.1.5

func (f *Field) IsArray() bool

IsArray 字段是否是数组类型

func (*Field) IsRequired added in v0.1.5

func (f *Field) IsRequired() bool

IsRequired 字段是否必须

func (*Field) Metadata added in v0.1.5

func (f *Field) Metadata() (*Metadata, error)

func (*Field) Schema added in v0.1.5

func (f *Field) 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 (*Field) SchemaDesc added in v0.1.5

func (f *Field) SchemaDesc() string

SchemaDesc 字段注释说明

func (*Field) SchemaName added in v0.1.5

func (f *Field) SchemaName(exclude ...bool) string

SchemaName swagger文档字段名

func (*Field) SchemaType added in v0.1.5

func (f *Field) SchemaType() DataType

SchemaType 模型类型

func (*Field) SetId added in v0.1.5

func (f *Field) SetId(id string)

type HTTPValidationError added in v0.1.5

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

func (*HTTPValidationError) Error added in v0.1.5

func (v *HTTPValidationError) Error() 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) SchemaName added in v0.1.5

func (v *HTTPValidationError) SchemaName(exclude ...bool) 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 MetaCache added in v0.1.5

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

MetaCache Metadata 缓存

func (*MetaCache) Get added in v0.1.5

func (m *MetaCache) Get(pkg string) *Metadata

func (*MetaCache) Set added in v0.1.5

func (m *MetaCache) Set(meta *Metadata)

Set 保存一个元信息,存在则更新

type MetaField added in v0.1.5

type MetaField struct {
	Field

	Exported  bool `description:"是否是导出字段"`
	Anonymous bool `description:"是否是嵌入字段"`
	// contains filtered or unexported fields
}

MetaField 模型的字段元数据,可以与 Metadata 互相转换

func (*MetaField) ToMetadata added in v0.1.5

func (m *MetaField) ToMetadata() (bool, *Metadata)

ToMetadata 是否仍然是个基本模型

type Metadata added in v0.1.5

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

Metadata 数据模型 BaseModel 的元信息

func BaseModelToMetadata added in v0.1.5

func BaseModelToMetadata(model SchemaIface) *Metadata

BaseModelToMetadata 提取基本数据模型的元信息

@param	model	SchemaIface	基本数据模型
@return	*Metadata 基本数据模型的元信息

func GetMetadata added in v0.1.5

func GetMetadata(pkg string) *Metadata

GetMetadata 获取结构体的元信息

func List added in v0.1.5

func List(model SchemaIface) *Metadata

func (*Metadata) AddField added in v0.1.5

func (m *Metadata) AddField(field *MetaField, depth int)

AddField 添加字段记录

@param	depth	int	节点层级数

func (*Metadata) Fields added in v0.1.5

func (m *Metadata) Fields() []*MetaField

Fields 结构体字段

func (*Metadata) FromModel added in v0.1.5

func (m *Metadata) FromModel(model SchemaIface)

FromModel 从模型构造元数据,仅支持结构体

func (*Metadata) FromReflectType added in v0.1.5

func (m *Metadata) FromReflectType(rt reflect.Type)

FromReflectType 从反射类型种构造元数据

func (*Metadata) Id added in v0.1.5

func (m *Metadata) Id() string

Id 获取结构体的唯一标识

func (*Metadata) InnerFields added in v0.1.5

func (m *Metadata) InnerFields() []*MetaField

InnerFields 内部字段

func (*Metadata) IsRequired added in v0.1.5

func (m *Metadata) IsRequired() bool

func (*Metadata) Metadata added in v0.1.5

func (m *Metadata) Metadata() (*Metadata, error)

func (*Metadata) Name added in v0.1.5

func (m *Metadata) Name() string

Name 获取结构体名称

func (*Metadata) ReflectType added in v0.1.5

func (m *Metadata) ReflectType() reflect.Type

func (*Metadata) Schema added in v0.1.5

func (m *Metadata) Schema() map[string]any

Schema 输出为OpenAPI文档模型,字典格式 数组类型: 需要单独处理, 取其 fields 的第一个元素作为子资源素的实际类型 基本数据类型:取其 fields 的第一个元素, description同样取fields 的第一个元素 结构体类型: 需处理全部的 fields 和 innerFields

func (*Metadata) SchemaDesc added in v0.1.5

func (m *Metadata) SchemaDesc() string

SchemaDesc 结构体文档注释

func (*Metadata) SchemaName added in v0.1.5

func (m *Metadata) SchemaName(exclude ...bool) string

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

func (*Metadata) SchemaType added in v0.1.5

func (m *Metadata) SchemaType() DataType

SchemaType 模型类型

func (*Metadata) String added in v0.1.5

func (m *Metadata) String() string

String 结构体唯一标识:包名+结构体名称

type ModelContentSchema

type ModelContentSchema interface {
	SchemaType() DataType
	Schema() map[string]any
	SchemaName(exclude ...bool) string
}

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) AddDefinition

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

AddDefinition 添加一个模型文档

func (*OpenApi) QueryPathItem

func (o *OpenApi) QueryPathItem(path string) *PathItem

QueryPathItem 查询路由对象, 不存在则新建

func (*OpenApi) RecreateDocs

func (o *OpenApi) RecreateDocs() *OpenApi

RecreateDocs 重建Swagger 文档

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, 通过函数 MakeOperationResponses 构建
	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 字段

type Parameter

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

Parameter 路径参数或者查询参数

func QModelToParameter

func QModelToParameter(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"`
}

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 {
	Title  string            `json:"title,omitempty" description:"字段标题"`
	Name   string            `json:"name,omitempty" description:"字段名称"`
	Tag    reflect.StructTag `json:"tag,omitempty" description:"TAG"`
	Type   DataType          `json:"otype,omitempty" description:"openapi 数据类型"`
	InPath bool              `json:"in_path,omitempty" description:"是否是路径参数"`
}

QModel 查询参数或路径参数模型, 此类型会进一步转换为 openapi.Parameter

func ParseToQueryModels added in v0.1.5

func ParseToQueryModels(q QueryParameter) []*QModel

ParseToQueryModels 将一个结构体转换为 QueryModel

func (*QModel) InnerSchema added in v0.1.5

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

InnerSchema 内部字段模型文档, 全名:文档

func (*QModel) IsRequired added in v0.1.5

func (q *QModel) IsRequired() bool

IsRequired 是否必须

func (*QModel) Metadata added in v0.1.5

func (q *QModel) Metadata() (*Metadata, error)

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) SchemaName added in v0.1.5

func (q *QModel) SchemaName(exclude ...bool) string

SchemaName 获取名称,以json字段为准

func (*QModel) SchemaType added in v0.1.5

func (q *QModel) SchemaType() DataType

SchemaType 模型类型

func (*QModel) SetId added in v0.1.5

func (q *QModel) SetId(id string)

type QueryModel added in v0.1.5

type QueryModel struct{}

QueryModel 查询参数基类

func (*QueryModel) Fields added in v0.1.5

func (q *QueryModel) Fields() []*QModel

type QueryParameter added in v0.1.5

type QueryParameter interface {
}

type Reference

type Reference struct {
	// 关联模型, 取值为 openapi.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 路由 请求体模型文档

func MakeOperationRequestBody

func MakeOperationRequestBody(model *Metadata) *RequestBody

MakeOperationRequestBody 将路由中的 *openapi.Metadata 转换成 openapi 的请求体 RequestBody

type Response

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

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

func MakeOperationResponses

func MakeOperationResponses(model *Metadata) []*Response

MakeOperationResponses 将路由中的 *openapi.Metadata 转换成 openapi 的返回体 []*Response

type SchemaIface added in v0.1.5

type SchemaIface interface {
	// Schema 输出为OpenAPI文档模型,字典格式
	Schema() (m map[string]any)
	// SchemaName 获取结构体的名称,默认包含包名
	SchemaName(exclude ...bool) string
	// SchemaDesc 结构体文档注释
	SchemaDesc() string
	// SchemaType 模型类型
	SchemaType() DataType
	// IsRequired 字段是否必须
	IsRequired() bool
	// Metadata 获取反射后的字段元信息, 允许上层处理
	Metadata() (*Metadata, error)
}

type ValidationError added in v0.1.5

type ValidationError struct {
	BaseModel
	Ctx  map[string]any `json:"service" description:"Service"`
	Msg  string         `json:"msg" description:"Message" binding:"required"`
	Type string         `json:"type" description:"Error Type" binding:"required"`
	Loc  []string       `json:"loc" description:"Location" binding:"required"`
}

ValidationError 参数校验错误

func (*ValidationError) Error added in v0.1.5

func (v *ValidationError) Error() 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) SchemaName added in v0.1.5

func (v *ValidationError) SchemaName(exclude ...bool) 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