Documentation ¶
Index ¶
- Constants
- Variables
- func FindImports(file *ast.File) map[string]string
- func FindReturnInBlockStmt(stmt ast.Stmt) []*ast.ReturnStmt
- func FindRspIndex(rspName string, lhs []ast.Expr) int
- func FindSelectorPath(s *ast.SelectorExpr) []string
- func FormatComment(comments *ast.CommentGroup) string
- func GenFromPath(name, des, version, path, out string)
- func GetTagInfo(fieldTag string) (tag, name, validate string)
- type Api
- func (a *Api) AnalysisAnnotate()
- func (a *Api) FillRequestParams(method *Method)
- func (a *Api) FillResponse(method *Method)
- func (a *Api) FillSecurity(method *Method)
- func (a *Api) FindApiParameter(body *ast.BlockStmt)
- func (a *Api) FindRspMethodMap(rhs []ast.Expr) []string
- func (a *Api) GetApiPath() string
- func (a *Api) GetOperationId() string
- func (a *Api) GetParameterStruct(expr ast.Expr) *Struct
- func (a *Api) GetRequestPath() string
- func (a *Api) GetRequestPathNoGroup() string
- func (a *Api) GetResponseData() *Struct
- func (a *Api) GetResponseStruct(expr ast.Expr)
- func (a *Api) NewStruct() *Struct
- func (a *Api) SetResponseDataStruct(array bool, s *Struct)
- func (a *Api) SetResponseDataType(array bool, typ string)
- type ApiPathsMap
- type BaseType
- type Components
- func (c Components) GetHeadersName() string
- func (c Components) GetParametersName() string
- func (c Components) GetRequestBodiesName() string
- func (c Components) GetResponsesName() string
- func (c Components) GetSchemasName() string
- func (c Components) GetSecuritySchemesName() string
- func (c *Components) SetSecurityScheme(name string, scheme SecurityScheme)
- type Config
- type Contact
- type Content
- type CreatePackageOpt
- type ExternalDocs
- type Field
- type Fields
- type Flow
- type Header
- type Info
- type License
- type MapField
- type MapInfo
- type Method
- type MethodMap
- type OpenAPI
- type Package
- type Packages
- func (pkgs *Packages) DeepFindParams(idx int, paths []string, field Field) *Struct
- func (pkgs *Packages) FillPkgRelationStruct()
- func (pkgs *Packages) FindInMethodMapParams(sct *Struct)
- func (pkgs *Packages) FindStruct(path, pkg, name string) Struct
- func (pkgs *Packages) FindStructPtr(path, pkg, name string) *Struct
- func (pkgs *Packages) GenPackage(pkgPath, path string) []*Package
- func (pkgs *Packages) GetApi() OpenAPI
- func (pkgs *Packages) Init(base string)
- func (pkgs *Packages) InitPackages(base string)
- type Parameter
- type Property
- type RequestBody
- type Response
- type SecurityScheme
- type Server
- type Struct
- func (sct Struct) Copy() Struct
- func (sct *Struct) FieldFromAstField(fd *ast.Field) Field
- func (sct *Struct) FieldFromInterfaceAstField(fd *ast.Field) Field
- func (sct *Struct) GetField() *Field
- func (sct *Struct) GetInterfaceMethodField(it *ast.Field) StructMethod
- func (sct *Struct) GetStructFromAstInterfaceType(s *ast.InterfaceType)
- func (sct *Struct) GetStructFromAstStructType(s *ast.StructType)
- func (sct *Struct) GetStructMethodFuncType(ft *ast.FuncType) StructMethod
- func (sct Struct) ToProperty() Property
- type StructMethod
- type Tag
Constants ¶
View Source
const ( AnnotateSplitChar = "|" AuthStart = "auth:" ResponseTypeJSON = "json" ResponseTypeXML = "xml" ResponseTypeBytes = "bytes" AuthTypeJWT = "JWT" AuthTypeOAuth2 = "OAuth2" AuthTypeSession = "Session" AuthTypeCookie = "Cookie" ApiParamsBindMethod = "Bind" ApiParamsSuccessMethod = "Success" )
View Source
const ( ExprStruct = "struct" ExprFunc = "func" )
View Source
const ( PropertyTypeObject = "object" PropertyTypeArray = "array" )
View Source
const ( TagParamPath = "uri" TagParamFrom = "form" TagParamJson = "json" TagParamXml = "xml" TagParamYaml = "yaml" OpenApiInPath = "path" OpenApiInQuery = "query" OpenApiInHeader = "header" OpenApiInCookie = "cookie" TagValidate = "validate" OpenApiTypeArray = "array" OpenApiTypeBoolean = "boolean" OpenApiTypeInteger = "integer" OpenApiTypeNull = "null" OpenApiTypeNumber = "number" OpenApiTypeObject = "object" OpenApiTypeString = "string" OpenApiSchemasPrefix = "#/components/schemas/" )
View Source
const ConfigFileName = "config_origin.yaml"
Variables ¶
View Source
var APIMethods = []string{ http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace}
View Source
var AuthType = []string{AuthTypeJWT, AuthTypeOAuth2, AuthTypeSession, AuthTypeCookie}
View Source
var DefaultInfo = OpenAPI{ Openapi: "3.0.0", Components: Components{ Schemas: make(map[string]Property), Responses: make(map[string]Response), Headers: make(map[string]Header), RequestBodies: make(map[string]RequestBody), SecuritySchemes: make(map[string]*SecurityScheme), }, Paths: make(map[string]map[string]Method), }
View Source
var ResponseType = []string{ResponseTypeJSON, ResponseTypeXML, ResponseTypeBytes}
Functions ¶
func FindReturnInBlockStmt ¶
func FindReturnInBlockStmt(stmt ast.Stmt) []*ast.ReturnStmt
func FindSelectorPath ¶
func FindSelectorPath(s *ast.SelectorExpr) []string
func FormatComment ¶
func FormatComment(comments *ast.CommentGroup) string
func GetTagInfo ¶
Types ¶
type Api ¶
type Api struct { Name string `json:"name"` //接口地址 Summary string `json:"summary"` //名称 Description string `json:"description"` //描述 RequestPath string `json:"request_path"` //自定义路径 Point string `json:"point"` //接口结构体对象名称 Group string `json:"group"` //接口结构体名称 HttpMethod string `json:"method"` //接口http方法 Annotate string `json:"annotate"` //注释 Path string `json:"path"` //文件地址 Auth string `json:"auth"` //授权方式 AuthTo string `json:"authTo"` //授权方式 ResponseType string `json:"responseType"` //返回类型 Params *Struct `json:"params"` //参数 string为路径 Parameter为对象 Response *Struct `json:"response"` //返回结构体 // contains filtered or unexported fields }
func (*Api) AnalysisAnnotate ¶
func (a *Api) AnalysisAnnotate()
func (*Api) FillRequestParams ¶
FillRequestParams 填充请求参数
func (*Api) FindApiParameter ¶
FindApiParameter 构建API基础参数
func (*Api) GetApiPath ¶
func (*Api) GetOperationId ¶
func (*Api) GetRequestPath ¶
func (*Api) GetRequestPathNoGroup ¶
func (*Api) GetResponseData ¶
func (*Api) GetResponseStruct ¶
func (*Api) SetResponseDataStruct ¶
SetResponseDataStruct 返回为结构体时
func (*Api) SetResponseDataType ¶
SetResponseDataType 设置返回为基础类型时
type ApiPathsMap ¶
ApiPathsMap api解决乱序问题
func (ApiPathsMap) MarshalJSON ¶
func (m ApiPathsMap) MarshalJSON() ([]byte, error)
type Components ¶
type Components struct { Schemas map[string]Property `json:"schemas,omitempty"` Responses map[string]Response `json:"responses,omitempty"` Parameters []Parameter `json:"parameters,omitempty"` RequestBodies map[string]RequestBody `json:"requestBodies,omitempty"` Headers map[string]Header `json:"headers,omitempty"` SecuritySchemes map[string]*SecurityScheme `json:"securitySchemes,omitempty"` }
func (Components) GetHeadersName ¶
func (c Components) GetHeadersName() string
func (Components) GetParametersName ¶
func (c Components) GetParametersName() string
func (Components) GetRequestBodiesName ¶
func (c Components) GetRequestBodiesName() string
func (Components) GetResponsesName ¶
func (c Components) GetResponsesName() string
func (Components) GetSchemasName ¶
func (c Components) GetSchemasName() string
func (Components) GetSecuritySchemesName ¶
func (c Components) GetSecuritySchemesName() string
func (*Components) SetSecurityScheme ¶
func (c *Components) SetSecurityScheme(name string, scheme SecurityScheme)
type Config ¶
type Config struct { Web struct { Prefix string `yaml:"prefix"` } `yaml:"web"` }
Config 配置参数
type CreatePackageOpt ¶
type ExternalDocs ¶
type Field ¶
type Field struct { Name string `json:"name"` //名称 Type string `json:"type"` //类型 Tag string `json:"tag"` //tag In string `json:"in"` //存在类型 path 路径 json json对象内 ParamName string `json:"paramName"` //参数名 Validate string `json:"validate"` //验证 Pkg string `json:"Pkg"` //包名 类型为结构体时 PkgPath string `json:"pkgPath"` //包路径 类型为结构体时 Comment string `json:"comment"` //注释 Array bool `json:"array"` //是否数组 Ptr bool `json:"ptr"` //是否指针 MapInfo MapInfo `json:"mapInfo"` //map类型键值信息 Struct *Struct `json:"struct"` //是结构体时 }
func GetExprInfo ¶
func GetFieldInfo ¶
func (*Field) GetOpenApiIn ¶
func (*Field) GetOpenApiType ¶
func (Field) IsRequired ¶
func (Field) ToParameter ¶
func (Field) ToProperty ¶
ToProperty 找到属性 deep 递归层数 max递归深度
type Method ¶
type Method struct { Tags []string `json:"tags,omitempty"` Summary string `json:"summary,omitempty"` Description string `json:"description,omitempty"` OperationId string `json:"operationId,omitempty"` Parameters []Parameter `json:"parameters,omitempty"` RequestBody RequestBody `json:"requestBody,omitempty"` Responses map[string]Response `json:"responses,omitempty"` Security []map[string][]string `json:"security,omitempty"` // contains filtered or unexported fields }
type OpenAPI ¶
type OpenAPI struct { Openapi string `json:"openapi,omitempty"` Info Info `json:"info,omitempty"` Servers []Server `json:"servers,omitempty"` Tags []Tag `json:"tags,omitempty"` Paths ApiPathsMap `json:"paths,omitempty"` Components Components `json:"components,omitempty"` }
type Package ¶
type Package struct { Name string //包名 Path string //包路径 ModPath string //模块路径 Structs map[string]*Struct //所有结构体信息 // contains filtered or unexported fields }
func (*Package) FindConfig ¶
func (pkg *Package) FindConfig()
func (*Package) FindPkgApi ¶
func (pkg *Package) FindPkgApi()
type Packages ¶
type Packages []Package
func (*Packages) DeepFindParams ¶
DeepFindParams 深度查找参数
func (*Packages) FillPkgRelationStruct ¶
func (pkgs *Packages) FillPkgRelationStruct()
FillPkgRelationStruct 设置包内的关联结构体
func (*Packages) FindInMethodMapParams ¶
FindInMethodMapParams 从调用链获取返回参数
func (*Packages) FindStruct ¶
func (*Packages) FindStructPtr ¶
func (*Packages) GenPackage ¶
func (*Packages) InitPackages ¶
type Parameter ¶
type Parameter struct { Name string `json:"name,omitempty"` In string `json:"in,omitempty"` Description string `json:"description,omitempty"` Required bool `json:"required,omitempty"` AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` Deprecated bool `json:"deprecated,omitempty"` Schema Property `json:"schema,omitempty"` Style string `json:"style,omitempty"` }
type Property ¶
type Property struct { Name string `json:"-"` Type string `json:"type,omitempty"` Description string `json:"description,omitempty"` Format string `json:"format,omitempty"` Ref string `json:"$ref,omitempty"` Required []string `json:"required,omitempty"` Items *Property `json:"items,omitempty"` //数组 File *Property `json:"file,omitempty"` Properties map[string]Property `json:"properties,omitempty"` Enum []string `json:"enum,omitempty"` // contains filtered or unexported fields }
type RequestBody ¶
type SecurityScheme ¶
type Struct ¶
type Struct struct { Name string `json:"name"` //名称 Des string `json:"des"` //描述 Type string `json:"type"` //结构体类型 Field string `json:"field"` //所需字段 有时可能需要的是结构体中的字段 如:rsp.List Fields Fields `json:"fields"` //字段 MethodMap *MethodMap `json:"methodMap"` //map[参数位置][]链路 方法的返回值类型查找 Imports map[string]string //包下所有导入的包信息 Methods []StructMethod `json:"methods"` //方法列表 包括接口的方法 Api []Api //所有API接口信息 Pkg *Package }
func (*Struct) FieldFromAstField ¶
FieldFromAstField 寻找基础的结构体字段定义
func (*Struct) FieldFromInterfaceAstField ¶
func (*Struct) GetInterfaceMethodField ¶
func (sct *Struct) GetInterfaceMethodField(it *ast.Field) StructMethod
GetInterfaceMethodField 寻找接口字段定义
func (*Struct) GetStructFromAstInterfaceType ¶
func (sct *Struct) GetStructFromAstInterfaceType(s *ast.InterfaceType)
func (*Struct) GetStructFromAstStructType ¶
func (sct *Struct) GetStructFromAstStructType(s *ast.StructType)
func (*Struct) GetStructMethodFuncType ¶
func (sct *Struct) GetStructMethodFuncType(ft *ast.FuncType) StructMethod
GetStructMethodFuncType 寻找方法参数定义
func (Struct) ToProperty ¶
ToProperty 找到属性 deep 递归层数 max递归深度
type StructMethod ¶
type Tag ¶
type Tag struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` }
Click to show internal directories.
Click to hide internal directories.