forked from swaggo/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
76 lines (60 loc) · 1.75 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package swag
import (
"go/ast"
"github.com/go-openapi/spec"
)
// Schema parsed 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
}
// TypeSpecDef the whole information of a typeSpec.
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
ParentSpec ast.Decl
}
// Name the name of the typeSpec.
func (t *TypeSpecDef) Name() string {
if t.TypeSpec != nil {
return t.TypeSpec.Name.Name
}
return ""
}
// FullName full name of the typeSpec.
func (t *TypeSpecDef) FullName() string {
var fullName string
if parentFun, ok := (t.ParentSpec).(*ast.FuncDecl); ok && parentFun != nil {
fullName = fullTypeNameFunctionScoped(t.File.Name.Name, parentFun.Name.Name, t.TypeSpec.Name.Name)
} else {
fullName = fullTypeName(t.File.Name.Name, t.TypeSpec.Name.Name)
}
return fullName
}
// FullPath of the typeSpec.
func (t *TypeSpecDef) FullPath() string {
return t.PkgPath + "." + t.Name()
}
// AstFileInfo information of an ast.File.
type AstFileInfo struct {
// 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
}
// PackageDefinitions files and definition in a package.
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
}