Documentation ¶
Overview ¶
Package swag converts Go annotations to Swagger Documentation 2.0. See https://github.com/swaggo/swag for more information about swag.
Index ¶
- Constants
- Variables
- func CheckSchemaType(typeName string)
- func GetSchemes(commentLine string) []string
- func IsGolangPrimitiveType(typeName string) bool
- func IsPrimitiveType(typeName string) bool
- func ReadDoc() (string, error)
- func Register(name string, swagger Swagger)
- func Skip(f os.FileInfo) error
- func TransToValidSchemeType(typeName string) string
- type Operation
- func (operation *Operation) ParseAcceptComment(commentLine string) error
- func (operation *Operation) ParseComment(comment string, astFile *ast.File) error
- func (operation *Operation) ParseEmptyResponseComment(commentLine string) error
- func (operation *Operation) ParseEmptyResponseOnly(commentLine string) error
- func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.File) error
- func (operation *Operation) ParseProduceComment(commentLine string) error
- func (operation *Operation) ParseResponseComment(commentLine string, astFile *ast.File) error
- func (operation *Operation) ParseRouterComment(commentLine string) error
- func (operation *Operation) ParseSecurityComment(commentLine string) error
- func (operation *Operation) ParseTagsComment(commentLine string)
- type Parser
- func (parser *Parser) GetSwagger() *spec.Swagger
- func (parser *Parser) ParseAPI(searchDir string, mainAPIFile string)
- func (parser *Parser) ParseDefinition(pkgName string, typeSpec *ast.TypeSpec, typeName string)
- func (parser *Parser) ParseDefinitions()
- func (parser *Parser) ParseGeneralAPIInfo(mainAPIFile string)
- func (parser *Parser) ParseRouterAPIInfo(astFile *ast.File)
- func (parser *Parser) ParseType(astFile *ast.File)
- type Swagger
Constants ¶
const ( // CamelCase indicates using CamelCase strategy for struct field. CamelCase = "camelcase" // PascalCase indicates using PascalCase strategy for struct field. PascalCase = "pascalcase" // SnakeCase indicates using SnakeCase strategy for struct field. SnakeCase = "snakecase" )
const Name = "swagger"
Name is a unique name be used to register swag instance.
const Version = "v1.3.2"
Version of swag
Variables ¶
var ErrFailedConvertPrimitiveType = errors.New("swag property: failed convert primitive type")
ErrFailedConvertPrimitiveType Failed to convert for swag to interpretable type
Functions ¶
func CheckSchemaType ¶ added in v1.1.1
func CheckSchemaType(typeName string)
CheckSchemaType TODO: NEEDS COMMENT INFO
func GetSchemes ¶
GetSchemes parses swagger schemes for given commentLine
func IsGolangPrimitiveType ¶ added in v1.4.0
IsGolangPrimitiveType determine whether the type name is a golang primitive type
func IsPrimitiveType ¶ added in v1.4.0
IsPrimitiveType determine whether the type name is a primitive type
func TransToValidSchemeType ¶ added in v1.1.1
TransToValidSchemeType indicates type will transfer golang basic type to swagger supported type.
Types ¶
type Operation ¶
type Operation struct { HTTPMethod string Path string spec.Operation // contains filtered or unexported fields }
Operation describes a single API operation on a path. For more information: https://github.com/swaggo/swag#api-operation
func NewOperation ¶
func NewOperation() *Operation
NewOperation creates a new Operation with default properties. map[int]Response
func (*Operation) ParseAcceptComment ¶
ParseAcceptComment parses comment for given `accept` comment string.
func (*Operation) ParseComment ¶
ParseComment parses comment for given comment string and returns error if error occurs.
func (*Operation) ParseEmptyResponseComment ¶
ParseEmptyResponseComment parse only comment out status code and description,eg: @Success 200 "it's ok"
func (*Operation) ParseEmptyResponseOnly ¶ added in v1.4.0
ParseEmptyResponseOnly parse only comment out status code ,eg: @Success 200
func (*Operation) ParseParamComment ¶
ParseParamComment parses params return []string of param properties @Param queryText form string true "The email for login"
[param name] [paramType] [data type] [is mandatory?] [Comment]
@Param some_id path int true "Some ID"
func (*Operation) ParseProduceComment ¶
ParseProduceComment parses comment for gived `produce` comment string.
func (*Operation) ParseResponseComment ¶
ParseResponseComment parses comment for gived `response` comment string.
func (*Operation) ParseRouterComment ¶
ParseRouterComment parses comment for gived `router` comment string.
func (*Operation) ParseSecurityComment ¶ added in v1.3.2
ParseSecurityComment parses comment for gived `security` comment string.
func (*Operation) ParseTagsComment ¶ added in v1.1.0
ParseTagsComment parses comment for given `tag` comment string.
type Parser ¶
type Parser struct { // TypeDefinitions is a map that stores [package name][type name][*ast.TypeSpec] TypeDefinitions map[string]map[string]*ast.TypeSpec // CustomPrimitiveTypes is a map that stores custom primitive types to actual golang types [type name][string] CustomPrimitiveTypes map[string]string PropNamingStrategy string // contains filtered or unexported fields }
Parser implements a parser for Go source files.
func (*Parser) GetSwagger ¶
GetSwagger returns *spec.Swagger which is the root document object for the API specification.
func (*Parser) ParseAPI ¶ added in v1.3.2
ParseAPI parses general api info for gived searchDir and mainAPIFile
func (*Parser) ParseDefinition ¶ added in v1.1.1
ParseDefinition TODO: NEEDS COMMENT INFO
func (*Parser) ParseDefinitions ¶
func (parser *Parser) ParseDefinitions()
ParseDefinitions parses Swagger Api definitions.
func (*Parser) ParseGeneralAPIInfo ¶ added in v1.3.2
ParseGeneralAPIInfo parses general api info for gived mainAPIFile path
func (*Parser) ParseRouterAPIInfo ¶ added in v1.3.2
ParseRouterAPIInfo parses router api info for given astFile