extractor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PropertyName            = "name"
	PropertySecurityScopes  = "scopes"
	PropertyValidatorString = "validate"
)
View Source
const (
	AttributeTag              = "Tag"
	AttributeQuery            = "Query"
	AttributeDeprecated       = "Deprecated"
	AttributeHidden           = "Hidden"
	AttributeSecurity         = "Security"
	AttributeAdvancedSecurity = "AdvancedSecurity"
	AttributeRoute            = "Route"
	AttributeResponse         = "Response"
	AttributeDescription      = "Description"
	AttributeMethod           = "Method"
	AttributeErrorResponse    = "ErrorResponse"
)

Variables

This section is empty.

Functions

func DoesStructEmbedStruct

func DoesStructEmbedStruct(
	sourceFile *ast.File,
	structFullPackageName string,
	structNode *ast.StructType,
	embeddedStructName string,
) bool

func DoesStructEmbedStructByName

func DoesStructEmbedStructByName(structNode *ast.StructType, embeddedStructName string) bool

DoesStructEmbedStructByName Checks whether `structNode` embeds a struct who's name equals embeddedStructName. Note this function does NOT take into account

func DoesStructEmbedType

func DoesStructEmbedType(pkg *packages.Package, structName string, embeddedStructFullPackage string, embeddedStructName string) (bool, error)

func DoesTypeOrInterfaceExistInPackage

func DoesTypeOrInterfaceExistInPackage(
	packages []*packages.Package,
	packageFullName string,
	ident *ast.Ident,
) (bool, bool)

func FilterPackageByFullName

func FilterPackageByFullName(packages []*packages.Package, fullName string) *packages.Package

func FindAndExtract

func FindAndExtract(input []string, search string) string

func FindAndExtractOccurrences

func FindAndExtractOccurrences(input []string, search string, maxMatchCount uint) []string

func FindGenDeclByName

func FindGenDeclByName(pkg *packages.Package, typeSpecName string) *ast.GenDecl

func FindStructAst

func FindStructAst(pkg *packages.Package, structName string) *ast.StructType

func FindTypesStructInPackage

func FindTypesStructInPackage(pkg *packages.Package, structName string) (*types.Struct, error)

func GetAllPackageFiles

func GetAllPackageFiles(codeFiles []*ast.File, fileSet *token.FileSet, fullPackageNameToFind string) ([]*ast.File, error)

func GetCastProperty

func GetCastProperty[TPropertyType any](attrib *Attribute, property string) (*TPropertyType, error)

func GetCommentsFromIdent

func GetCommentsFromIdent(ident *ast.Ident) []string

func GetDefaultAlias

func GetDefaultAlias(fullyQualifiedPackage string) string

func GetDefaultPackageAlias

func GetDefaultPackageAlias(file *ast.File) (string, error)

func GetDotImportedPackageNames

func GetDotImportedPackageNames(file *ast.File) []string

func GetFieldMetadata

func GetFieldMetadata(
	file *ast.File,
	fileSet *token.FileSet,
	packages []*packages.Package,
	value *ast.Field,
) (definitions.TypeMetadata, error)

func GetFileByImportNode

func GetFileByImportNode(codeFiles []*ast.File, fileSet *token.FileSet, importNode *ast.ImportSpec) (*ast.File, error)

func GetFullPackageName

func GetFullPackageName(file *ast.File, fileSet *token.FileSet) (string, error)

func GetFuncParameterTypeList

func GetFuncParameterTypeList(
	file *ast.File,
	fileSet *token.FileSet,
	packages []*packages.Package,
	funcDecl *ast.FuncDecl,
) ([]definitions.ParamMeta, error)

func GetFuncReturnTypeList

func GetFuncReturnTypeList(
	file *ast.File,
	fileSet *token.FileSet,
	packages []*packages.Package,
	funcDecl *ast.FuncDecl,
) ([]definitions.TypeMetadata, error)

func GetImportAliases

func GetImportAliases(file *ast.File) map[string]string

func GetPackageAndDependencies

func GetPackageAndDependencies(
	codeFiles []*ast.File,
	fileSet *token.FileSet,
	fullPackageNameToFind string,
	relevantFilesOutput *MapSet.Set[*ast.File],
) error

func GetPackagesFromExpressions

func GetPackagesFromExpressions(packageExpressions []string) ([]*packages.Package, error)

func GetStructFromGenDecl

func GetStructFromGenDecl(decl *ast.GenDecl) *ast.StructType

func GetTypeMetaByIdent

func GetTypeMetaByIdent(
	file *ast.File,
	fileSet *token.FileSet,
	packages []*packages.Package,
	ident *ast.Ident,
) (definitions.TypeMetadata, error)

func GetTypeMetaBySelectorExpr

func GetTypeMetaBySelectorExpr(
	file *ast.File,
	fileSet *token.FileSet,
	packages []*packages.Package,
	selector *ast.SelectorExpr,
) (definitions.TypeMetadata, error)

func IsAliasDefault

func IsAliasDefault(fullPackageName string, alias string) bool

func IsAliasDefaultImport

func IsAliasDefaultImport(file *ast.File, alias string) bool

func IsFuncDeclReceiverForStruct

func IsFuncDeclReceiverForStruct(structName string, funcDecl *ast.FuncDecl) bool

func IsIdentFromDotImport

func IsIdentFromDotImport(file *ast.File, ident *ast.Ident, typeInfo *types.Info) (bool, error)

IsIdentFromDotImport resolves whether an `*ast.Ident` refers to a type from a dot-imported package.

func IsIdentInPackage

func IsIdentInPackage(pkg *packages.Package, ident *ast.Ident) bool

func IsPackageDotImported

func IsPackageDotImported(file *ast.File, packageName string) (bool, string)

func IsUniverseType

func IsUniverseType(typeName string) bool

func MapDocListToStrings

func MapDocListToStrings(docList []*ast.Comment) []string

MapDocListToStrings converts a list of comment nodes (ast.Comment) to a string array

Types

type Attribute

type Attribute struct {
	Name        string
	Value       string
	Properties  map[string]any
	Description string
}

func (Attribute) GetProperty

func (attr Attribute) GetProperty(name string) *any

func (Attribute) HasProperty

func (attr Attribute) HasProperty(name string) bool

type AttributesHolder

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

func NewAttributeHolder

func NewAttributeHolder(comments []string) (AttributesHolder, error)

func (AttributesHolder) FindByValueOrProperty

func (holder AttributesHolder) FindByValueOrProperty(key string, value string) *Attribute

func (AttributesHolder) FindFirstByProperty

func (holder AttributesHolder) FindFirstByProperty(key string, value string) *Attribute

func (AttributesHolder) FindFirstByValue

func (holder AttributesHolder) FindFirstByValue(value string) *Attribute

func (AttributesHolder) GetAll

func (holder AttributesHolder) GetAll(attribute string) []*Attribute

func (AttributesHolder) GetDescription

func (holder AttributesHolder) GetDescription() string

func (AttributesHolder) GetFirst

func (holder AttributesHolder) GetFirst(attribute string) *Attribute

func (AttributesHolder) GetFirstDescriptionOrEmpty

func (holder AttributesHolder) GetFirstDescriptionOrEmpty(attribute string) string

func (AttributesHolder) GetFirstPropertyValueOrEmpty

func (holder AttributesHolder) GetFirstPropertyValueOrEmpty(property string) string

func (AttributesHolder) GetFirstValueOrEmpty

func (holder AttributesHolder) GetFirstValueOrEmpty(attribute string) string

func (AttributesHolder) Has

func (holder AttributesHolder) Has(attribute string) bool

type ControllerVisitor

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

func NewControllerVisitor

func NewControllerVisitor(config *definitions.GleeceConfig) (*ControllerVisitor, error)

func (ControllerVisitor) DumpContext

func (v ControllerVisitor) DumpContext() (string, error)

func (ControllerVisitor) GetControllers

func (v ControllerVisitor) GetControllers() []definitions.ControllerMetadata

func (*ControllerVisitor) GetFiles

func (v *ControllerVisitor) GetFiles() []*ast.File

func (*ControllerVisitor) GetFormattedDiagnosticStack

func (v *ControllerVisitor) GetFormattedDiagnosticStack() string

func (*ControllerVisitor) GetLastError

func (v *ControllerVisitor) GetLastError() *error

func (*ControllerVisitor) GetModelsFlat

func (v *ControllerVisitor) GetModelsFlat() ([]definitions.ModelMetadata, bool, error)

func (*ControllerVisitor) Visit

func (v *ControllerVisitor) Visit(node ast.Node) ast.Visitor

type Field

type Field struct {
	Name string
	Type string
}

Field represents a field in a struct

type StructAttributeHolders

type StructAttributeHolders struct {
	StructHolder AttributesHolder
	FieldHolders map[string]*AttributesHolder
}

type StructInfo

type StructInfo struct {
	Name   string
	Fields []Field
}

StructInfo represents a struct with its fields

type TypeVisitor

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

func NewTypeVisitor

func NewTypeVisitor(packages []*packages.Package) *TypeVisitor

func (*TypeVisitor) GetStructs

func (v *TypeVisitor) GetStructs() []definitions.ModelMetadata

GetStructs returns the list of processed structs.

func (*TypeVisitor) VisitStruct

func (v *TypeVisitor) VisitStruct(fullPackageName string, structName string, structType *types.Struct) error

Jump to

Keyboard shortcuts

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