Merged in feature/s3integration (pull request #47)

Set Up S3 integration

* cfginterfaceandfirsts3funcs

* addlocalstack

* generallypassesfullsuite

* addedmultipleattemptedpings

* cleanup

* stabiliseplusskip
This commit is contained in:
Michael McGuinness
2025-02-05 12:52:41 +00:00
parent 9254b91d45
commit 92334ad1dd
838 changed files with 139249 additions and 6671 deletions
+70 -30
View File
@@ -19,7 +19,7 @@ type PackagesDefinitions struct {
files map[*ast.File]*AstFileInfo
packages map[string]*PackageDefinitions
uniqueDefinitions map[string]*TypeSpecDef
parseDependency bool
parseDependency ParseFlag
debug Debugger
}
@@ -93,7 +93,7 @@ func (pkgDefs *PackagesDefinitions) RangeFiles(handle func(info *AstFileInfo) er
for _, info := range pkgDefs.files {
// ignore package path prefix with 'vendor' or $GOROOT,
// because the router info of api will not be included these files.
if strings.HasPrefix(info.PackagePath, "vendor") || strings.HasPrefix(info.Path, runtime.GOROOT()) {
if strings.HasPrefix(info.PackagePath, "vendor") || (runtime.GOROOT() != "" && strings.HasPrefix(info.Path, runtime.GOROOT()+string(filepath.Separator))) {
continue
}
sortedFiles = append(sortedFiles, info)
@@ -166,6 +166,8 @@ func (pkgDefs *PackagesDefinitions) parseTypesFromFile(astFile *ast.File, packag
pkgDefs.uniqueDefinitions[fullName] = nil
anotherTypeDef.NotUnique = true
pkgDefs.uniqueDefinitions[anotherTypeDef.TypeName()] = anotherTypeDef
anotherTypeDef.SetSchemaName()
typeSpecDef.NotUnique = true
fullName = typeSpecDef.TypeName()
pkgDefs.uniqueDefinitions[fullName] = typeSpecDef
@@ -174,6 +176,8 @@ func (pkgDefs *PackagesDefinitions) parseTypesFromFile(astFile *ast.File, packag
pkgDefs.uniqueDefinitions[fullName] = typeSpecDef
}
typeSpecDef.SetSchemaName()
if pkgDefs.packages[typeSpecDef.PkgPath] == nil {
pkgDefs.packages[typeSpecDef.PkgPath] = NewPackageDefinitions(astFile.Name.Name, typeSpecDef.PkgPath).AddTypeSpec(typeSpecDef.Name(), typeSpecDef)
} else if _, ok = pkgDefs.packages[typeSpecDef.PkgPath].TypeDefinitions[typeSpecDef.Name()]; !ok {
@@ -192,6 +196,7 @@ func (pkgDefs *PackagesDefinitions) parseFunctionScopedTypesFromFile(astFile *as
for _, astDeclaration := range astFile.Decls {
funcDeclaration, ok := astDeclaration.(*ast.FuncDecl)
if ok && funcDeclaration.Body != nil {
functionScopedTypes := make(map[string]*TypeSpecDef)
for _, stmt := range funcDeclaration.Body.List {
if declStmt, ok := (stmt).(*ast.DeclStmt); ok {
if genDecl, ok := (declStmt.Decl).(*ast.GenDecl); ok && genDecl.Tok == token.TYPE {
@@ -212,12 +217,31 @@ func (pkgDefs *PackagesDefinitions) parseFunctionScopedTypesFromFile(astFile *as
}
}
fullName := typeSpecDef.TypeName()
if structType, ok := typeSpecDef.TypeSpec.Type.(*ast.StructType); ok {
for _, field := range structType.Fields.List {
var idt *ast.Ident
var ok bool
switch field.Type.(type) {
case *ast.Ident:
idt, ok = field.Type.(*ast.Ident)
case *ast.StarExpr:
idt, ok = field.Type.(*ast.StarExpr).X.(*ast.Ident)
case *ast.ArrayType:
idt, ok = field.Type.(*ast.ArrayType).Elt.(*ast.Ident)
}
if ok && !IsGolangPrimitiveType(idt.Name) {
if functype, ok := functionScopedTypes[idt.Name]; ok {
idt.Name = functype.TypeName()
}
}
}
}
if pkgDefs.uniqueDefinitions == nil {
pkgDefs.uniqueDefinitions = make(map[string]*TypeSpecDef)
}
fullName := typeSpecDef.TypeName()
anotherTypeDef, ok := pkgDefs.uniqueDefinitions[fullName]
if ok {
if anotherTypeDef == nil {
@@ -228,14 +252,19 @@ func (pkgDefs *PackagesDefinitions) parseFunctionScopedTypesFromFile(astFile *as
pkgDefs.uniqueDefinitions[fullName] = nil
anotherTypeDef.NotUnique = true
pkgDefs.uniqueDefinitions[anotherTypeDef.TypeName()] = anotherTypeDef
anotherTypeDef.SetSchemaName()
typeSpecDef.NotUnique = true
fullName = typeSpecDef.TypeName()
pkgDefs.uniqueDefinitions[fullName] = typeSpecDef
}
} else {
pkgDefs.uniqueDefinitions[fullName] = typeSpecDef
functionScopedTypes[typeSpec.Name.Name] = typeSpecDef
}
typeSpecDef.SetSchemaName()
if pkgDefs.packages[typeSpecDef.PkgPath] == nil {
pkgDefs.packages[typeSpecDef.PkgPath] = NewPackageDefinitions(astFile.Name.Name, typeSpecDef.PkgPath).AddTypeSpec(fullName, typeSpecDef)
} else if _, ok = pkgDefs.packages[typeSpecDef.PkgPath].TypeDefinitions[fullName]; !ok {
@@ -324,7 +353,7 @@ func (pkgDefs *PackagesDefinitions) EvaluateConstValueByName(file *ast.File, pkg
}
}
}
if pkgDefs.parseDependency {
if pkgDefs.parseDependency > 0 {
for _, pkgPath := range externalPkgPaths {
if err := pkgDefs.loadExternalPackage(pkgPath); err == nil {
if pkg, ok := pkgDefs.packages[pkgPath]; ok {
@@ -353,8 +382,8 @@ func (pkgDefs *PackagesDefinitions) collectConstEnums(parsedSchemas map[*TypeSpe
continue
}
//delete it from parsed schemas, and will parse it again
if _, ok := parsedSchemas[typeDef]; ok {
// delete it from parsed schemas, and will parse it again
if _, ok = parsedSchemas[typeDef]; ok {
delete(parsedSchemas, typeDef)
}
@@ -363,7 +392,7 @@ func (pkgDefs *PackagesDefinitions) collectConstEnums(parsedSchemas map[*TypeSpe
}
name := constVar.Name.Name
if _, ok := constVar.Value.(ast.Expr); ok {
if _, ok = constVar.Value.(ast.Expr); ok {
continue
}
@@ -469,7 +498,7 @@ func (pkgDefs *PackagesDefinitions) findPackagePathFromImports(pkg string, file
}
break
} else if imp.Name.Name == "_" && len(pkg) > 0 {
//for unused types
// for unused types
pd, ok := pkgDefs.packages[path]
if ok {
if pd.Name == pkg {
@@ -506,14 +535,7 @@ func (pkgDefs *PackagesDefinitions) findPackagePathFromImports(pkg string, file
}
func (pkgDefs *PackagesDefinitions) findTypeSpecFromPackagePaths(matchedPkgPaths, externalPkgPaths []string, name string) (typeDef *TypeSpecDef) {
for _, pkgPath := range matchedPkgPaths {
typeDef = pkgDefs.findTypeSpec(pkgPath, name)
if typeDef != nil {
return typeDef
}
}
if pkgDefs.parseDependency {
if pkgDefs.parseDependency > 0 {
for _, pkgPath := range externalPkgPaths {
if err := pkgDefs.loadExternalPackage(pkgPath); err == nil {
typeDef = pkgDefs.findTypeSpec(pkgPath, name)
@@ -524,6 +546,13 @@ func (pkgDefs *PackagesDefinitions) findTypeSpecFromPackagePaths(matchedPkgPaths
}
}
for _, pkgPath := range matchedPkgPaths {
typeDef = pkgDefs.findTypeSpec(pkgPath, name)
if typeDef != nil {
return typeDef
}
}
return typeDef
}
@@ -542,13 +571,14 @@ func (pkgDefs *PackagesDefinitions) FindTypeSpec(typeName string, file *ast.File
parts := strings.Split(strings.Split(typeName, "[")[0], ".")
if len(parts) > 1 {
typeDef, ok := pkgDefs.uniqueDefinitions[typeName]
if ok {
return typeDef
}
pkgPaths, externalPkgPaths := pkgDefs.findPackagePathFromImports(parts[0], file)
typeDef = pkgDefs.findTypeSpecFromPackagePaths(pkgPaths, externalPkgPaths, parts[1])
if len(externalPkgPaths) == 0 || pkgDefs.parseDependency == ParseNone {
typeDef, ok := pkgDefs.uniqueDefinitions[typeName]
if ok {
return typeDef
}
}
typeDef := pkgDefs.findTypeSpecFromPackagePaths(pkgPaths, externalPkgPaths, parts[1])
return pkgDefs.parametrizeGenericType(file, typeDef, typeName)
}
@@ -557,17 +587,27 @@ func (pkgDefs *PackagesDefinitions) FindTypeSpec(typeName string, file *ast.File
return typeDef
}
//in case that comment //@name renamed the type with a name without a dot
typeDef, ok = pkgDefs.uniqueDefinitions[typeName]
if ok {
return typeDef
}
name := parts[0]
typeDef, ok = pkgDefs.uniqueDefinitions[fullTypeName(file.Name.Name, name)]
if !ok {
pkgPaths, externalPkgPaths := pkgDefs.findPackagePathFromImports("", file)
typeDef = pkgDefs.findTypeSpecFromPackagePaths(pkgPaths, externalPkgPaths, name)
}
return pkgDefs.parametrizeGenericType(file, typeDef, typeName)
if typeDef != nil {
return pkgDefs.parametrizeGenericType(file, typeDef, typeName)
}
// in case that comment //@name renamed the type with a name without a dot
for k, v := range pkgDefs.uniqueDefinitions {
if v == nil {
pkgDefs.debug.Printf("%s TypeSpecDef is nil", k)
continue
}
if v.SchemaName == typeName {
return v
}
}
return nil
}