forked from swaggo/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
69 lines (53 loc) · 1.5 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
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
}
// 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 {
return fullTypeName(t.File.Name.Name, t.TypeSpec.Name.Name)
}
// 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
}