Documentation
¶
Index ¶
- Constants
- func CheckSchemaType(typeName string) error
- func IsGolangPrimitiveType(typeName string) bool
- func IsNumericType(typeName string) bool
- func IsPrimitiveType(typeName string) bool
- func IsSimplePrimitiveType(typeName string) bool
- func SetExcludedDirsAndFiles(excludes string) func(*Parser)
- func TransToValidSchemeType(typeName string) string
- type ApiDocSpec
- type ApiGroupSpec
- type ApiParameterSpec
- type ApiRequestSpec
- type ApiResponseSpec
- type ApiSpec
- type AstFileInfo
- type Operation
- func (operation *Operation) ParseComment(comment string, astFile *ast.File) error
- func (operation *Operation) ParseDescriptionComment(lineRemainder string)
- func (operation *Operation) ParseParametersComment(parameterType, commentLine string, astFile *ast.File) error
- func (operation *Operation) ParseRequestComment(commentLine string, astFile *ast.File) error
- func (operation *Operation) ParseResponseComment(commentLine string, astFile *ast.File) error
- func (operation *Operation) ParseRouterComment(commentLine string) error
- type PackageDefinitions
- type PackagesDefinitions
- type Parser
- type TypeSchema
- func (v *TypeSchema) ExampleValue() string
- func (v *TypeSchema) GetTag(name string) (value string, has bool)
- func (v *TypeSchema) IsRequired() (required bool)
- func (s *TypeSchema) JSON(withComment bool) string
- func (v *TypeSchema) JSONKey() (key string, isOmitempty bool)
- func (v *TypeSchema) ParameterTags() map[string]string
- func (v *TypeSchema) ValidateTag() (validate string)
- func (s *TypeSchema) Write(format string, withComment bool) (body string)
- func (s *TypeSchema) XML(withComment bool) string
- func (v *TypeSchema) XMLAttrs() map[string]string
- func (v *TypeSchema) XMLName() string
- func (v *TypeSchema) XMLTag() (xmlTag string, hasTag, isAttr, isOmitempty, isInner bool)
- type TypeSpecDef
Constants ¶
const ( // ARRAY represent a array value. ARRAY = "array" // OBJECT represent a object value. OBJECT = "object" // BOOLEAN represent a boolean value. BOOLEAN = "boolean" // INTEGER represent a integer value. INTEGER = "integer" // NUMBER represent a number value. NUMBER = "number" // STRING represent a string value. STRING = "string" // FUNC represent a function value. FUNC = "func" // INTERFACE represent a interface value. INTERFACE = "interface{}" // ANY represent a any value. ANY = "any" // NIL represent a empty value. NIL = "nil" NULL = "null" )
Variables ¶
This section is empty.
Functions ¶
func CheckSchemaType ¶
CheckSchemaType checks if typeName is not a name of primitive type.
func IsGolangPrimitiveType ¶
IsGolangPrimitiveType determine whether the type name is a golang primitive type.
func IsNumericType ¶
IsNumericType determines whether the type name is a numeric type.
func IsPrimitiveType ¶
IsPrimitiveType determine whether the type name is a primitive type.
func IsSimplePrimitiveType ¶
IsSimplePrimitiveType determine whether the type name is a simple primitive type.
func SetExcludedDirsAndFiles ¶
func TransToValidSchemeType ¶
TransToValidSchemeType indicates type will transfer golang basic type to supported type.
Types ¶
type ApiDocSpec ¶
type ApiGroupSpec ¶
type ApiParameterSpec ¶
type ApiParameterSpec struct {
Name string
DataType string
Required bool
Description string
Validate string
Example string
// contains filtered or unexported fields
}
func (ApiParameterSpec) ParameterTypes ¶
func (p ApiParameterSpec) ParameterTypes() string
type ApiRequestSpec ¶
type ApiRequestSpec struct {
Parameters map[string]*ApiParameterSpec
Accept string //accept format
Schema *TypeSchema
// contains filtered or unexported fields
}
func (*ApiRequestSpec) Body ¶
func (s *ApiRequestSpec) Body() string
type ApiResponseSpec ¶
type ApiResponseSpec struct {
StatusCode int
Format string //json xml
Schema *TypeSchema
Description string
IsMock bool
// contains filtered or unexported fields
}
func (*ApiResponseSpec) Body ¶
func (s *ApiResponseSpec) Body() string
func (*ApiResponseSpec) PureBody ¶
func (s *ApiResponseSpec) PureBody() string
type ApiSpec ¶
type ApiSpec struct {
Title string
HTTPMethod string
Api string
Version string
Accept string //json,xml,form
Format string //json,xml
Description string
Author string
Deprecated bool
Group string
Responses []*ApiResponseSpec
Requests ApiRequestSpec
Order int //sort
// contains filtered or unexported fields
}
type AstFileInfo ¶
type Operation ¶
type Operation struct {
ApiSpec
// contains filtered or unexported fields
}
Operation describes a single API operation on a path.
func NewOperation ¶
NewOperation creates a new Operation with default properties. map[int]Response.
func (*Operation) ParseComment ¶
func (*Operation) ParseDescriptionComment ¶
ParseDescriptionComment godoc.
func (*Operation) ParseParametersComment ¶
func (operation *Operation) ParseParametersComment(parameterType, commentLine string, astFile *ast.File) error
ParseParametersComment parses parameters (@header, @param, @query, @form) @param [name] [type] [required] [comment] @query demo int true "测试参数"
func (*Operation) ParseRequestComment ¶
func (*Operation) ParseResponseComment ¶
ParseResponseComment parses comment for given `response` comment string.
func (*Operation) ParseRouterComment ¶
ParseRouterComment parses comment for given `router` comment string.
type PackageDefinitions ¶
type PackageDefinitions struct {
// files in this package, map key is file's relative path starting package path
Files map[string]*ast.File
// definitions in this package, map key is typeName
TypeDefinitions map[string]*TypeSpecDef
// package name
Name string
}
PackageDefinitions files and definition in a package.
type PackagesDefinitions ¶
type PackagesDefinitions struct {
// contains filtered or unexported fields
}
func NewPackagesDefinitions ¶
func NewPackagesDefinitions() *PackagesDefinitions
NewPackagesDefinitions create object PackagesDefinitions.
func (*PackagesDefinitions) CollectAstFile ¶
func (pkgDefs *PackagesDefinitions) CollectAstFile(packageDir, path string, astFile *ast.File) error
CollectAstFile collect ast.file.
func (*PackagesDefinitions) FindTypeSpec ¶
func (pkgDefs *PackagesDefinitions) FindTypeSpec(typeName string, file *ast.File, parseDependency bool) *TypeSpecDef
FindTypeSpec finds out TypeSpecDef of a type by typeName @typeName the name of the target type, if it starts with a package name, find its own package path from imports on top of @file @file the ast.file in which @typeName is used @pkgPath the package path of @file.
func (*PackagesDefinitions) ParseTypes ¶
func (pkgDefs *PackagesDefinitions) ParseTypes() error
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) GetApiDoc ¶
func (p *Parser) GetApiDoc() *ApiDocSpec
func (*Parser) ParseDefinition ¶
func (p *Parser) ParseDefinition(typeSpecDef *TypeSpecDef, parentSchema *TypeSchema) (*TypeSchema, error)
ParseDefinition parses given type spec that corresponds to the type under given name and package
type TypeSchema ¶
type TypeSchema struct {
Name string //xxRequest, xxResponse, for example: RegisterRequest
Type string //int, string, bool, object, array, any
FullName string
PkgPath string //for example: github.com/alovn/apidocgen/examples/svc-user/handler
FullPath string //for example: github.com/alovn/apidocgen/examples/svc-user/handler.RegisterRequest
Comment string
ArraySchema *TypeSchema
Properties map[string]*TypeSchema //object
Parent *TypeSchema
TagValue string
// contains filtered or unexported fields
}
func (*TypeSchema) ExampleValue ¶
func (v *TypeSchema) ExampleValue() string
func (*TypeSchema) IsRequired ¶
func (v *TypeSchema) IsRequired() (required bool)
func (*TypeSchema) JSON ¶
func (s *TypeSchema) JSON(withComment bool) string
func (*TypeSchema) JSONKey ¶
func (v *TypeSchema) JSONKey() (key string, isOmitempty bool)
func (*TypeSchema) ParameterTags ¶
func (v *TypeSchema) ParameterTags() map[string]string
func (*TypeSchema) ValidateTag ¶
func (v *TypeSchema) ValidateTag() (validate string)
func (*TypeSchema) Write ¶
func (s *TypeSchema) Write(format string, withComment bool) (body string)
func (*TypeSchema) XML ¶
func (s *TypeSchema) XML(withComment bool) string
func (*TypeSchema) XMLAttrs ¶
func (v *TypeSchema) XMLAttrs() map[string]string
func (*TypeSchema) XMLName ¶
func (v *TypeSchema) XMLName() string
func (*TypeSchema) XMLTag ¶
func (v *TypeSchema) XMLTag() (xmlTag string, hasTag, isAttr, isOmitempty, isInner bool)
type TypeSpecDef ¶
type TypeSpecDef struct {
// ast file where TypeSpec is
File *ast.File
// the TypeSpec of this type definition
TypeSpec *ast.TypeSpec
// path of package starting from under ${GOPATH}/src or from module path in go.mod
PkgPath string
}
TypeSpecDef the whole information of a typeSpec.
func (*TypeSpecDef) FullName ¶
func (t *TypeSpecDef) FullName() string
FullName full name of the typeSpec.