Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertStrToBasicType(str string, t *types.Basic) interface{}
- func InspectPackage(pkg *packages.Package, visit func(pkg *packages.Package) bool)
- func NormalizeComment(text, trimStart string) string
- func ReadGoMod(pkgPath string) (mod *modfile.File, err error)
- type A
- type API
- type APISpec
- type APIs
- type Analyzer
- type CallInfo
- type CallRule
- type Comment
- func (c *Comment) ApplyToSchema(schema *spec.SchemaRef)
- func (c *Comment) Consumes() []string
- func (c *Comment) Deprecated() bool
- func (c *Comment) ID() string
- func (c *Comment) Ignore() bool
- func (c *Comment) Produces() []string
- func (c *Comment) Required() bool
- func (c *Comment) Security() *spec.SecurityRequirements
- func (c *Comment) Summary() string
- func (c *Comment) Tags() []string
- func (c *Comment) Text() string
- func (c *Comment) TextPointer() *string
- func (c *Comment) TrimPrefix(prefix string) string
- type CommentStack
- type Config
- type Context
- func (c *Context) APIs() *APIs
- func (c *Context) AddAPI(items ...*API)
- func (c *Context) Block() *Context
- func (c *Context) CommentStack() *CommentStack
- func (c *Context) Doc() *spec.T
- func (c *Context) File() *ast.File
- func (c *Context) GetCallInfo(n ast.Node) (string, string, error)
- func (c *Context) GetDefinition(pkg, name string) Definition
- func (c *Context) GetFuncFromAstNode(n ast.Node) *types.Func
- func (c *Context) GetHeadingCommentOf(pos token.Pos) *ast.CommentGroup
- func (c *Context) GetSchemaByExpr(expr ast.Expr, contentType string) *spec.SchemaRef
- func (c *Context) GetTrailingCommentOf(pos token.Pos) *ast.CommentGroup
- func (c *Context) LineColumn(pos token.Pos) string
- func (c *Context) MatchCall(n ast.Node, rule *CallRule, ...)
- func (c *Context) NewEnv() *Context
- func (c *Context) Package() *packages.Package
- func (c *Context) ParseComment(commentGroup *ast.CommentGroup) *Comment
- func (c *Context) ParseStatusCode(status ast.Expr) int
- func (c *Context) ParseType(t types.Type) Definition
- func (c *Context) WithFile(file *ast.File) *Context
- func (c *Context) WithPackage(pkg *packages.Package) *Context
- type Definition
- type Definitions
- type Entrypoint
- type Environment
- type FieldNameParser
- type FuncDefinition
- type GeneratorConfig
- type ModFile
- type OpenAPIConfig
- type ParamNameParser
- type ParamParser
- type Plugin
- type RouteAnalyzer
- type RouteGroup
- type SchemaBuilder
- type SecuritySchemes
- type Stack
- type TypeDefinition
Constants ¶
View Source
const ( MimeTypeJson = "application/json" MimeApplicationXml = "application/xml" MimeTypeXml = "text/xml" MimeTypeFormData = "multipart/form-data" MimeTypeFormUrlencoded = "application/x-www-form-urlencoded" )
Variables ¶
View Source
var DEBUG = os.Getenv("DEBUG") == "on"
Functions ¶
func ConvertStrToBasicType ¶
func InspectPackage ¶
func NormalizeComment ¶
Types ¶
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
func NewAnalyzer ¶
type CallRule ¶
func NewCallRule ¶
func NewCallRule() *CallRule
type Comment ¶
type Comment struct { Annotations []annotation.Annotation // contains filtered or unexported fields }
func ParseComment ¶
func ParseComment(commentGroup *ast.CommentGroup, fSet *token.FileSet) *Comment
func (*Comment) ApplyToSchema ¶
func (*Comment) Deprecated ¶
func (*Comment) Security ¶
func (c *Comment) Security() *spec.SecurityRequirements
func (*Comment) TextPointer ¶
func (*Comment) TrimPrefix ¶
TrimPrefix trim comment prefix and return trimmed string
type CommentStack ¶
type CommentStack struct {
// contains filtered or unexported fields
}
func NewCommentStack ¶
func NewCommentStack(parent *CommentStack, comment *Comment) *CommentStack
func (*CommentStack) LookupAnnotations ¶
func (e *CommentStack) LookupAnnotations(annotType annotation.Type) []annotation.Annotation
func (*CommentStack) LookupTags ¶
func (e *CommentStack) LookupTags() []string
func (*CommentStack) ResolveByAnnotation ¶
func (e *CommentStack) ResolveByAnnotation(annotType annotation.Type) *CommentStack
type Config ¶
type Config struct { Plugin string Dir string Output string Depends []string OpenAPI OpenAPIConfig Generators []*GeneratorConfig }
type Context ¶
type Context struct { Env *Environment // contains filtered or unexported fields }
func (*Context) CommentStack ¶
func (c *Context) CommentStack() *CommentStack
func (*Context) GetCallInfo ¶
GetCallInfo returns the package or type and name associated with a call expression
e.g. GetCallInfo(`c.GET("/ping", ...)`) returns ("*github/gin-gonic/gin.RouterGroup", "GET", nil)
func (*Context) GetDefinition ¶
func (c *Context) GetDefinition(pkg, name string) Definition
func (*Context) GetHeadingCommentOf ¶
func (c *Context) GetHeadingCommentOf(pos token.Pos) *ast.CommentGroup
func (*Context) GetSchemaByExpr ¶
func (*Context) GetTrailingCommentOf ¶
func (c *Context) GetTrailingCommentOf(pos token.Pos) *ast.CommentGroup
func (*Context) ParseComment ¶
func (c *Context) ParseComment(commentGroup *ast.CommentGroup) *Comment
type Definition ¶
type Definitions ¶
type Definitions map[string]Definition
func (*Definitions) Get ¶
func (d *Definitions) Get(key string) Definition
func (*Definitions) Set ¶
func (d *Definitions) Set(def Definition)
type Entrypoint ¶
type Entrypoint struct {
// contains filtered or unexported fields
}
func NewEntrypoint ¶
func NewEntrypoint(plugins ...Plugin) *Entrypoint
func (*Entrypoint) Run ¶
func (e *Entrypoint) Run(args []string)
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
func NewEnvironment ¶
func NewEnvironment(parent *Environment) *Environment
func (*Environment) Assign ¶
func (e *Environment) Assign(k, v interface{}) *Environment
func (*Environment) Define ¶
func (e *Environment) Define(k, v interface{}) *Environment
func (*Environment) Lookup ¶
func (e *Environment) Lookup(k interface{}) interface{}
func (*Environment) Resolve ¶
func (e *Environment) Resolve(k interface{}) *Environment
type FuncDefinition ¶
func NewFuncDefinition ¶
func (*FuncDefinition) File ¶
func (f *FuncDefinition) File() *ast.File
func (*FuncDefinition) Key ¶
func (f *FuncDefinition) Key() string
func (*FuncDefinition) Pkg ¶
func (f *FuncDefinition) Pkg() *packages.Package
type GeneratorConfig ¶
type ModFile ¶
func LoadModFileFrom ¶
type OpenAPIConfig ¶
type OpenAPIConfig struct { OpenAPI string `yaml:"openapi"` // OpenAPI version 3.0.0|3.0.3|3.1.0 Info *spec.Info `yaml:"info"` // Required SecuritySchemes *SecuritySchemes `yaml:"securitySchemes"` }
func (OpenAPIConfig) ApplyToDoc ¶
func (c OpenAPIConfig) ApplyToDoc(doc *spec.T)
type ParamNameParser ¶
type ParamParser ¶
type ParamParser struct {
// contains filtered or unexported fields
}
func NewParamParser ¶
func NewParamParser(ctx *Context, nameParser ParamNameParser) *ParamParser
type Plugin ¶
type Plugin interface { Name() string Mount(k *koanf.Koanf) error Analyze(ctx *Context, node ast.Node) }
Plugin 用于对解析逻辑进行扩展以支持不同的框架/模式
type RouteGroup ¶
type RouteGroup struct {
Prefix string
}
type SchemaBuilder ¶
type SchemaBuilder struct {
// contains filtered or unexported fields
}
func NewSchemaBuilder ¶
func NewSchemaBuilder(ctx *Context, contentType string) *SchemaBuilder
func (*SchemaBuilder) ParseExpr ¶
func (s *SchemaBuilder) ParseExpr(expr ast.Expr) (schema *spec.SchemaRef)
func (*SchemaBuilder) WithFieldNameParser ¶
func (s *SchemaBuilder) WithFieldNameParser(parser FieldNameParser) *SchemaBuilder
type SecuritySchemes ¶
type SecuritySchemes map[string]*spec.SecurityScheme
type TypeDefinition ¶
type TypeDefinition struct { Spec *ast.TypeSpec // Enum items Enums []*spec.ExtendedEnumItem // contains filtered or unexported fields }
func NewTypeDefinition ¶
func (*TypeDefinition) File ¶
func (t *TypeDefinition) File() *ast.File
func (*TypeDefinition) Key ¶
func (t *TypeDefinition) Key() string
func (*TypeDefinition) ModelKey ¶
func (t *TypeDefinition) ModelKey(typeArgs ...*spec.SchemaRef) string
func (*TypeDefinition) Pkg ¶
func (t *TypeDefinition) Pkg() *packages.Package
Source Files
¶
Click to show internal directories.
Click to hide internal directories.