swag

package module
v2.0.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: MIT Imports: 31 Imported by: 0

README

swag

CUSTOM VER

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

View Source
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"
)
View Source
const (
	// ParseNone parse nothing
	ParseNone ParseFlag = 0x00
	// ParseOperations parse operations
	ParseOperations = 0x01
	// ParseModels parse models
	ParseModels = 0x02
	// ParseAll parse operations and models
	ParseAll = ParseOperations | ParseModels
)
View Source
const (
	// ARRAY represent a array value.
	ARRAY = "array"
	// OBJECT represent a object value.
	OBJECT = "object"
	// PRIMITIVE represent a primitive value.
	PRIMITIVE = "primitive"
	// 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"
	// ERROR represent a error value.
	ERROR = "error"
	// INTERFACE represent a interface value.
	INTERFACE = "interface{}"
	// ANY represent a any value.
	ANY = "any"
	// NIL represent a empty value.
	NIL = "nil"

	// IgnoreNameOverridePrefix Prepend to model to avoid renaming based on comment.
	IgnoreNameOverridePrefix = '$'
)
View Source
const NULL_V3 = "null"

NULL_V3 represent a nullable value. Valid if version > 3.1

View Source
const Name = "swagger"

Name is a unique name be used to register swag instance.

View Source
const Version = "v2.0.0-nullable"

Version of swag.

Variables

View Source
var (
	// ErrRecursiveParseStruct recursively parsing struct.
	ErrRecursiveParseStruct = errors.New("recursively parsing struct")

	// ErrFuncTypeField field type is func.
	ErrFuncTypeField = errors.New("field type is func")

	// ErrFailedConvertPrimitiveType Failed to convert for swag to interpretable type.
	ErrFailedConvertPrimitiveType = errors.New("swag property: failed convert primitive type")

	// ErrSkippedField .swaggo specifies field should be skipped.
	ErrSkippedField = errors.New("field is skipped by global overrides")
)

Functions

func AppendUtf8Rune

func AppendUtf8Rune(p []byte, r rune) []byte

AppendUtf8Rune appends the UTF-8 encoding of r to the end of p and returns the extended buffer. If the rune is out of range, it appends the encoding of RuneError.

func BuildCustomSchema

func BuildCustomSchema(types []string) (*spec.Schema, error)

BuildCustomSchema build custom schema specified by tag swaggertype.

func BuildCustomSchemaV3

func BuildCustomSchemaV3(types []string) (*spec.RefOrSpec[spec.Schema], error)

BuildCustomSchemaV3 build custom schema specified by tag swaggertype.

func CheckSchemaType

func CheckSchemaType(typeName string) error

CheckSchemaType checks if typeName is not a name of primitive type.

func EvaluateBinary

func EvaluateBinary(x, y interface{}, operator token.Token, xtype, ytype ast.Expr) (interface{}, ast.Expr)

EvaluateBinary evaluate the type and value of a binary expression

func EvaluateDataConversion

func EvaluateDataConversion(x interface{}, typeName string) interface{}

EvaluateDataConversion evaluate the type a explicit type conversion

func EvaluateEscapedChar

func EvaluateEscapedChar(text string) rune

EvaluateEscapedChar parse escaped character

func EvaluateEscapedString

func EvaluateEscapedString(text string) string

EvaluateEscapedString parse escaped characters in string

func EvaluateUnary

func EvaluateUnary(x interface{}, operator token.Token, xtype ast.Expr) (interface{}, ast.Expr)

EvaluateUnary evaluate the type and value of a unary expression

func FieldsByAnySpace

func FieldsByAnySpace(s string, n int) []string

FieldsByAnySpace split a string s by any space character into max n parts

func FieldsFunc

func FieldsFunc(s string, f func(rune2 rune) bool, n int) []string

FieldsFunc split a string s by a func splitter into max n parts

func GenerateOpenAPI3Doc

func GenerateOpenAPI3Doc(enable bool) func(*Parser)

GenerateOpenAPI3Doc parses only those operations which match given extension

func IsComplexSchema

func IsComplexSchema(schema *spec.Schema) bool

IsComplexSchema whether a schema is complex and should be a ref schema

func IsComplexSchemaV3

func IsComplexSchemaV3(schema *SchemaV3) bool

IsComplexSchemaV3 whether a schema is complex and should be a ref schema

func IsGolangPrimitiveType

func IsGolangPrimitiveType(typeName string) bool

IsGolangPrimitiveType determine whether the type name is a golang primitive type.

func IsInterfaceLike

func IsInterfaceLike(typeName string) bool

IsInterfaceLike determines whether the swagger type name is an go named interface type like error type.

func IsNullableTypeV3

func IsNullableTypeV3(typeName string) bool

IsNullableTypeV3 determine whether the type name is a github.com/guregu/null type.

func IsNumericType

func IsNumericType(typeName string) bool

IsNumericType determines whether the swagger type name is a numeric type.

func IsPrimitiveType

func IsPrimitiveType(typeName string) bool

IsPrimitiveType determine whether the type name is a primitive type.

func IsRefSchema

func IsRefSchema(schema *spec.Schema) bool

IsRefSchema whether a schema is a reference schema.

func IsSimplePrimitiveType

func IsSimplePrimitiveType(typeName string) bool

IsSimplePrimitiveType determine whether the type name is a simple primitive type.

func MergeSchema

func MergeSchema(dst *spec.Schema, src *spec.Schema) *spec.Schema

MergeSchema merge schemas

func NullableSchemaV3

func NullableSchemaV3(types []string) (*spec.RefOrSpec[spec.Schema], error)

func ParseUsingGoList

func ParseUsingGoList(enabled bool) func(parser *Parser)

ParseUsingGoList sets whether swag use go list to parse dependency

func PrimitiveSchema

func PrimitiveSchema(refType string) *spec.Schema

PrimitiveSchema build a primitive schema.

func PrimitiveSchemaV3

func PrimitiveSchemaV3(refType string) *spec.RefOrSpec[spec.Schema]

PrimitiveSchemaV3 build a primitive schema.

func ReadDoc

func ReadDoc(optionalName ...string) (string, error)

ReadDoc reads swagger document. An optional name parameter can be passed to read a specific document. The default name is "swagger".

func RefSchema

func RefSchema(refType string) *spec.Schema

RefSchema build a reference schema.

func RefSchemaV3

func RefSchemaV3(refType string) *spec.RefOrSpec[spec.Schema]

RefSchemaV3 build a reference schema.

func Register

func Register(name string, swagger Swagger)

Register registers swagger for given name.

func SetCodeExampleFilesDirectory

func SetCodeExampleFilesDirectory(directoryPath string) func(*Operation)

SetCodeExampleFilesDirectory sets the directory to search for codeExamples.

func SetCodeExampleFilesDirectoryV3

func SetCodeExampleFilesDirectoryV3(directoryPath string) func(*OperationV3)

SetCodeExampleFilesDirectoryV3 sets the directory to search for codeExamples.

func SetCodeExamplesDirectory

func SetCodeExamplesDirectory(directoryPath string) func(*Parser)

SetCodeExamplesDirectory sets the directory to search for code example files.

func SetCollectionFormat

func SetCollectionFormat(collectionFormat string) func(*Parser)

SetCollectionFormat set default collection format

func SetDebugger

func SetDebugger(logger Debugger) func(parser *Parser)

SetDebugger allows the use of user-defined implementations.

func SetExcludedDirsAndFiles

func SetExcludedDirsAndFiles(excludes string) func(*Parser)

SetExcludedDirsAndFiles sets directories and files to be excluded when searching.

func SetFieldParserFactory

func SetFieldParserFactory(factory FieldParserFactory) func(parser *Parser)

SetFieldParserFactory allows the use of user-defined implementations.

func SetMarkdownFileDirectory

func SetMarkdownFileDirectory(directoryPath string) func(*Parser)

SetMarkdownFileDirectory sets the directory to search for markdown files.

func SetOverrides

func SetOverrides(overrides map[string]string) func(parser *Parser)

SetOverrides allows the use of user-defined global type overrides.

func SetParseDependency

func SetParseDependency(parseDependency bool) func(*Parser)

SetParseDependency sets whether to parse the dependent packages.

func SetParseExtension

func SetParseExtension(parseExtension string) func(*Parser)

SetParseExtension parses only those operations which match given extension

func SetStrict

func SetStrict(strict bool) func(*Parser)

SetStrict sets whether swag should error or warn when it detects cases which are most likely user errors.

func SetTags

func SetTags(include string) func(*Parser)

SetTags sets the tags to be included

func TransToValidCollectionFormat

func TransToValidCollectionFormat(format string) string

TransToValidCollectionFormat determine valid collection format.

func TransToValidCollectionFormatV3

func TransToValidCollectionFormatV3(format, in string) string

TransToValidCollectionFormatV3 determine valid collection format.

func TransToValidSchemeType

func TransToValidSchemeType(typeName string) string

TransToValidSchemeType indicates type will transfer golang basic type to swagger supported type.

Types

type AstFileInfo

type AstFileInfo struct {
	//FileSet the FileSet object which is used to parse this go source file
	FileSet *token.FileSet

	// File ast.File
	File *ast.File

	// Path the path of the ast.File
	Path string

	// PackagePath package import path of the ast.File
	PackagePath string

	// ParseFlag determine what to parse
	ParseFlag ParseFlag
}

AstFileInfo information of an ast.File.

type CanIntegerValue

type CanIntegerValue struct {
	reflect.Value
}

CanIntegerValue a wrapper of reflect.Value

func (CanIntegerValue) CanInt

func (v CanIntegerValue) CanInt() bool

CanInt reports whether Uint can be used without panicking.

func (CanIntegerValue) CanUint

func (v CanIntegerValue) CanUint() bool

CanUint reports whether Uint can be used without panicking.

type CodeSamples

type CodeSamples []map[string]string

CodeSamples is used to parse code samples.

type ConstVariable

type ConstVariable struct {
	Name    *ast.Ident
	Type    ast.Expr
	Value   interface{}
	Comment *ast.CommentGroup
	File    *ast.File
	Pkg     *PackageDefinitions
}

ConstVariable a model to record a const variable

type ConstVariableGlobalEvaluator

type ConstVariableGlobalEvaluator interface {
	EvaluateConstValue(pkg *PackageDefinitions, cv *ConstVariable, recursiveStack map[string]struct{}) (interface{}, ast.Expr)
	EvaluateConstValueByName(file *ast.File, pkgPath, constVariableName string, recursiveStack map[string]struct{}) (interface{}, ast.Expr)
	FindTypeSpec(typeName string, file *ast.File) *TypeSpecDef
}

ConstVariableGlobalEvaluator an interface used to evaluate enums across packages

type Debugger

type Debugger interface {
	Printf(format string, v ...interface{})
}

Debugger is the interface that wraps the basic Printf method.

type EnumValue

type EnumValue struct {
	Value   interface{}
	Comment string
	// contains filtered or unexported fields
}

EnumValue a model to record an enum consts variable

type FieldParser

type FieldParser interface {
	ShouldSkip() bool
	FieldName() (string, error)
	FormName() string
	CustomSchema() (*spec.Schema, error)
	ComplementSchema(schema *spec.Schema) error
	IsRequired() (bool, error)
}

FieldParser parse struct field.

type FieldParserFactory

type FieldParserFactory func(ps *Parser, field *ast.Field) FieldParser

FieldParserFactory create FieldParser.

type FieldParserFactoryV3

type FieldParserFactoryV3 func(ps *Parser, field *ast.Field) FieldParserV3

FieldParserFactoryV3 func(ps *Parser, field *ast.Field) FieldParserV3 create FieldParser.

type FieldParserV3

type FieldParserV3 interface {
	ShouldSkip() bool
	FieldName() (string, error)
	FormName() string
	CustomSchema() (*spec.RefOrSpec[spec.Schema], error)
	ComplementSchema(schema *spec.RefOrSpec[spec.Schema]) error
	IsRequired() (bool, error)
}

FieldParserV3 parse struct field.

type Formatter

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

Formatter implements a formatter for Go source files.

func NewFormatter

func NewFormatter() *Formatter

NewFormatter create a new formatter instance.

func (*Formatter) Format

func (f *Formatter) Format(fileName string, contents []byte) ([]byte, error)

Format formats swag comments in contents. It uses fileName to report errors that happen during parsing of contents.

type Operation

type Operation struct {
	spec.Operation
	RouterProperties []RouteProperties
	// 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(parser *Parser, options ...func(*Operation)) *Operation

NewOperation creates a new Operation with default properties. map[int]Response.

func (*Operation) AddResponse

func (operation *Operation) AddResponse(code int, response *spec.Response)

AddResponse add a response for a code.

func (*Operation) DefaultResponse

func (operation *Operation) DefaultResponse() *spec.Response

DefaultResponse return the default response member pointer.

func (*Operation) ParseAcceptComment

func (operation *Operation) ParseAcceptComment(commentLine string) error

ParseAcceptComment parses comment for given `accept` comment string.

func (*Operation) ParseCodeSample

func (operation *Operation) ParseCodeSample(attribute, _, lineRemainder string) error

ParseCodeSample godoc.

func (*Operation) ParseComment

func (operation *Operation) ParseComment(comment string, astFile *ast.File) error

ParseComment parses comment for given comment string and returns error if error occurs.

func (*Operation) ParseDescriptionComment

func (operation *Operation) ParseDescriptionComment(lineRemainder string)

ParseDescriptionComment godoc.

func (*Operation) ParseEmptyResponseComment

func (operation *Operation) ParseEmptyResponseComment(commentLine string) error

ParseEmptyResponseComment parse only comment out status code and description,eg: @Success 200 "it's ok".

func (*Operation) ParseEmptyResponseOnly

func (operation *Operation) ParseEmptyResponseOnly(commentLine string) error

ParseEmptyResponseOnly parse only comment out status code ,eg: @Success 200.

func (*Operation) ParseMetadata

func (operation *Operation) ParseMetadata(attribute, lowerAttribute, lineRemainder string) error

ParseMetadata godoc.

func (*Operation) ParseParamComment

func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.File) error

ParseParamComment parses params return []string of param properties E.g. @Param queryText formData string true "The email for login"

[param name]    [paramType] [data type]  [is mandatory?]   [Comment]

E.g. @Param some_id path int true "Some ID".

func (*Operation) ParseProduceComment

func (operation *Operation) ParseProduceComment(commentLine string) error

ParseProduceComment parses comment for given `produce` comment string.

func (*Operation) ParseResponseComment

func (operation *Operation) ParseResponseComment(commentLine string, astFile *ast.File) error

ParseResponseComment parses comment for given `response` comment string.

func (*Operation) ParseResponseHeaderComment

func (operation *Operation) ParseResponseHeaderComment(commentLine string, _ *ast.File) error

ParseResponseHeaderComment parses comment for given `response header` comment string.

func (*Operation) ParseRouterComment

func (operation *Operation) ParseRouterComment(commentLine string) error

ParseRouterComment parses comment for given `router` comment string.

func (*Operation) ParseSecurityComment

func (operation *Operation) ParseSecurityComment(commentLine string) error

ParseSecurityComment parses comment for given `security` comment string.

func (*Operation) ParseTagsComment

func (operation *Operation) ParseTagsComment(commentLine string)

ParseTagsComment parses comment for given `tag` comment string.

type OperationV3

type OperationV3 struct {
	spec.Operation
	RouterProperties []RouteProperties
	// contains filtered or unexported fields
}

OperationV3 describes a single API operation on a path. For more information: https://github.com/swaggo/swag#api-operation

func NewOperationV3

func NewOperationV3(parser *Parser, options ...func(*OperationV3)) *OperationV3

NewOperationV3 returns a new instance of OperationV3.

func (*OperationV3) AddResponse

func (o *OperationV3) AddResponse(code string, response *spec.RefOrSpec[spec.Extendable[spec.Response]])

AddResponse add a response for a code.

func (*OperationV3) DefaultResponse

func (o *OperationV3) DefaultResponse() *spec.Response

DefaultResponse return the default response member pointer.

func (*OperationV3) ParseAcceptComment

func (o *OperationV3) ParseAcceptComment(commentLine string) error

ParseAcceptComment parses comment for given `accept` comment string.

func (*OperationV3) ParseCodeSample

func (o *OperationV3) ParseCodeSample(attribute, _, lineRemainder string) error

ParseCodeSample godoc.

func (*OperationV3) ParseComment

func (o *OperationV3) ParseComment(comment string, astFile *ast.File) error

ParseComment parses comment for given comment string and returns error if error occurs.

func (*OperationV3) ParseDescriptionComment

func (o *OperationV3) ParseDescriptionComment(lineRemainder string)

ParseDescriptionComment parses the description comment and sets it to the operation.

func (*OperationV3) ParseEmptyResponseComment

func (o *OperationV3) ParseEmptyResponseComment(commentLine string) error

ParseEmptyResponseComment parse only comment out status code and description,eg: @Success 200 "it's ok".

func (*OperationV3) ParseEmptyResponseOnly

func (o *OperationV3) ParseEmptyResponseOnly(commentLine string) error

ParseEmptyResponseOnly parse only comment out status code ,eg: @Success 200.

func (*OperationV3) ParseMetadata

func (o *OperationV3) ParseMetadata(attribute, lowerAttribute, lineRemainder string) error

ParseMetadata godoc.

func (*OperationV3) ParseParamComment

func (o *OperationV3) ParseParamComment(commentLine string, astFile *ast.File) error

ParseParamComment parses params return []string of param properties E.g. @Param queryText formData string true "The email for login"

[param name]    [paramType] [data type]  [is mandatory?]   [Comment]

E.g. @Param some_id path int true "Some ID".

func (*OperationV3) ParseProduceComment

func (o *OperationV3) ParseProduceComment(commentLine string) error

ParseProduceComment parses comment for given `produce` comment string.

func (*OperationV3) ParseResponseComment

func (o *OperationV3) ParseResponseComment(commentLine string, astFile *ast.File) error

ParseResponseComment parses comment for given `response` comment string.

func (*OperationV3) ParseResponseHeaderComment

func (o *OperationV3) ParseResponseHeaderComment(commentLine string, _ *ast.File) error

ParseResponseHeaderComment parses comment for given `response header` comment string.

func (*OperationV3) ParseRouterComment

func (o *OperationV3) ParseRouterComment(commentLine string) error

ParseRouterComment parses comment for given `router` comment string.

func (*OperationV3) ParseSecurityComment

func (o *OperationV3) ParseSecurityComment(commentLine string) error

ParseSecurityComment parses comment for given `security` comment string.

func (*OperationV3) ParseTagsComment

func (o *OperationV3) ParseTagsComment(commentLine string)

ParseTagsComment parses comment for given `tag` comment string.

func (*OperationV3) ProcessProduceComment

func (o *OperationV3) ProcessProduceComment() error

ProcessProduceComment processes the previously parsed produce comment.

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

	// const variables in this package, map key is the name
	ConstTable map[string]*ConstVariable

	// const variables in order in this package
	OrderedConst []*ConstVariable

	// package name
	Name string

	// package path
	Path string
}

PackageDefinitions files and definition in a package.

func NewPackageDefinitions

func NewPackageDefinitions(name, pkgPath string) *PackageDefinitions

NewPackageDefinitions new a PackageDefinitions object

func (*PackageDefinitions) AddConst

func (pkg *PackageDefinitions) AddConst(astFile *ast.File, valueSpec *ast.ValueSpec) *PackageDefinitions

AddConst add a const variable.

func (*PackageDefinitions) AddFile

func (pkg *PackageDefinitions) AddFile(pkgPath string, file *ast.File) *PackageDefinitions

AddFile add a file

func (*PackageDefinitions) AddTypeSpec

func (pkg *PackageDefinitions) AddTypeSpec(name string, typeSpec *TypeSpecDef) *PackageDefinitions

AddTypeSpec add a type spec.

type PackagesDefinitions

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

PackagesDefinitions map[package import path]*PackageDefinitions.

func NewPackagesDefinitions

func NewPackagesDefinitions() *PackagesDefinitions

NewPackagesDefinitions create object PackagesDefinitions.

func (*PackagesDefinitions) EvaluateConstValue

func (pkgDefs *PackagesDefinitions) EvaluateConstValue(pkg *PackageDefinitions, cv *ConstVariable, recursiveStack map[string]struct{}) (interface{}, ast.Expr)

EvaluateConstValue evaluate a const variable.

func (*PackagesDefinitions) EvaluateConstValueByName

func (pkgDefs *PackagesDefinitions) EvaluateConstValueByName(file *ast.File, pkgName, constVariableName string, recursiveStack map[string]struct{}) (interface{}, ast.Expr)

EvaluateConstValueByName evaluate a const variable by name.

func (*PackagesDefinitions) FindTypeSpec

func (pkgDefs *PackagesDefinitions) FindTypeSpec(typeName string, file *ast.File) *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) ParseFile

func (pkgDefs *PackagesDefinitions) ParseFile(packageDir, path string, src interface{}, flag ParseFlag) error

ParseFile parse a source file.

func (*PackagesDefinitions) ParseTypes

func (pkgDefs *PackagesDefinitions) ParseTypes() (map[*TypeSpecDef]*Schema, error)

ParseTypes parse types @Return parsed definitions.

func (*PackagesDefinitions) RangeFiles

func (pkgDefs *PackagesDefinitions) RangeFiles(handle func(info *AstFileInfo) error) error

RangeFiles for range the collection of ast.File in alphabetic order.

type ParseFlag

type ParseFlag int

ParseFlag determine what to parse

type Parser

type Parser struct {

	// PropNamingStrategy naming strategy
	PropNamingStrategy string

	// ParseVendor parse vendor folder
	ParseVendor bool

	// ParseDependencies whether swag should be parse outside dependency folder
	ParseDependency bool

	// ParseInternal whether swag should parse internal packages
	ParseInternal bool

	// Strict whether swag should error or warn when it detects cases which are most likely user errors
	Strict bool

	// RequiredByDefault set validation required for all fields by default
	RequiredByDefault bool

	// Overrides allows global replacements of types. A blank replacement will be skipped.
	Overrides map[string]string
	// contains filtered or unexported fields
}

Parser implements a parser for Go source files.

func New

func New(options ...func(*Parser)) *Parser

New creates a new Parser with default properties.

func (*Parser) GetOpenAPI

func (p *Parser) GetOpenAPI() *spec.OpenAPI

GetOpenAPI returns *spec.OpenAPI which is the root document object for the API specification.

func (*Parser) GetSchemaTypePath

func (parser *Parser) GetSchemaTypePath(schema *spec.Schema, depth int) []string

GetSchemaTypePath get path of schema type.

func (*Parser) GetSchemaTypePathV3

func (p *Parser) GetSchemaTypePathV3(schema *spec.RefOrSpec[spec.Schema], depth int) []string

GetSchemaTypePathV3 get path of schema type.

func (*Parser) GetSwagger

func (parser *Parser) GetSwagger() *spec.Swagger

GetSwagger returns *spec.Swagger which is the root document object for the API specification.

func (*Parser) ParseAPI

func (parser *Parser) ParseAPI(searchDir string, mainAPIFile string, parseDepth int) error

ParseAPI parses general api info for given searchDir and mainAPIFile.

func (*Parser) ParseAPIMultiSearchDir

func (parser *Parser) ParseAPIMultiSearchDir(searchDirs []string, mainAPIFile string, parseDepth int) error

ParseAPIMultiSearchDir is like ParseAPI but for multiple search dirs.

func (*Parser) ParseAcceptComment

func (parser *Parser) ParseAcceptComment(commentLine string) error

ParseAcceptComment parses comment for given `accept` comment string.

func (*Parser) ParseDefinition

func (parser *Parser) ParseDefinition(typeSpecDef *TypeSpecDef) (*Schema, error)

ParseDefinition parses given type spec that corresponds to the type under given name and package, and populates swagger schema definitions registry with a schema for the given type

func (*Parser) ParseDefinitionV3

func (p *Parser) ParseDefinitionV3(typeSpecDef *TypeSpecDef) (*SchemaV3, error)

ParseDefinitionV3 parses given type spec that corresponds to the type under given name and package, and populates swagger schema definitions registry with a schema for the given type

func (*Parser) ParseGeneralAPIInfo

func (parser *Parser) ParseGeneralAPIInfo(mainAPIFile string) error

ParseGeneralAPIInfo parses general api info for given mainAPIFile path.

func (*Parser) ParseProduceComment

func (parser *Parser) ParseProduceComment(commentLine string) error

ParseProduceComment parses comment for given `produce` comment string.

func (*Parser) ParseRouterAPIInfo

func (parser *Parser) ParseRouterAPIInfo(fileInfo *AstFileInfo) error

ParseRouterAPIInfo parses router api info for given astFile.

func (*Parser) ParseRouterAPIInfoV3

func (p *Parser) ParseRouterAPIInfoV3(fileInfo *AstFileInfo) error

ParseRouterAPIInfoV3 parses router api info for given astFile.

func (*Parser) Skip

func (parser *Parser) Skip(path string, f os.FileInfo) error

Skip returns filepath.SkipDir error if match vendor and hidden folder.

type RouteProperties

type RouteProperties struct {
	HTTPMethod string
	Path       string
}

RouteProperties describes HTTP properties of a single router comment.

type Schema

type Schema struct {
	*spec.Schema        //
	PkgPath      string // package import path used to rename Name of a definition int case of conflict
	Name         string // Name in definitions
}

Schema parsed schema.

type SchemaV3

type SchemaV3 struct {
	*spec.Schema        //
	PkgPath      string // package import path used to rename Name of a definition int case of conflict
	Name         string // Name in definitions
}

SchemaV3 parsed schema.

type Spec

type Spec struct {
	Version          string
	Host             string
	BasePath         string
	Schemes          []string
	Title            string
	Description      string
	InfoInstanceName string
	SwaggerTemplate  string
	LeftDelim        string
	RightDelim       string
}

Spec holds exported Swagger Info so clients can modify it.

func (*Spec) InstanceName

func (i *Spec) InstanceName() string

InstanceName returns Spec instance name.

func (*Spec) ReadDoc

func (i *Spec) ReadDoc() string

ReadDoc parses SwaggerTemplate into swagger document.

type Swagger

type Swagger interface {
	ReadDoc() string
}

Swagger is an interface to read swagger document.

func GetSwagger

func GetSwagger(name string) Swagger

GetSwagger returns the swagger instance for given name. If not found, returns nil.

type TypeSpecDef

type TypeSpecDef struct {
	// ast file where TypeSpec is
	File *ast.File

	// the TypeSpec of this type definition
	TypeSpec *ast.TypeSpec

	Enums []EnumValue

	// path of package starting from under ${GOPATH}/src or from module path in go.mod
	PkgPath    string
	ParentSpec ast.Decl

	NotUnique bool
}

TypeSpecDef the whole information of a typeSpec.

func (*TypeSpecDef) FullPath

func (t *TypeSpecDef) FullPath() string

FullPath return the full path of the typeSpec.

func (*TypeSpecDef) Name

func (t *TypeSpecDef) Name() string

Name the name of the typeSpec.

func (*TypeSpecDef) TypeName

func (t *TypeSpecDef) TypeName() string

TypeName the type name of the typeSpec.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL