swagger
swagger copied to clipboard
Swagger fails for gopkg.in/guregu/null.v2 (import name not same as package name)
When using e.g. gopkg.in the import names do not match the package names. Go build works fine but swagger fails with error below.
Imported path: gopkg.in/guregu/null.v2 Package name : null
2015/09/10 20:56:27 Package null is not imported to bitbucket.org/aintuapps/api-go-poc/models, Imported: map[string][]string{"fmt":[]string{"fmt"}, "orm":[]string{"bitbucket.org/aintuapps/api-go-poc/orm"}, "errors":[]string{"errors"}, "driver":[]string{"github.com/SAP/go-hdb/driver"}, "sqlx":[]string{"github.com/jmoiron/sqlx"}, "null.v2":[]string{"gopkg.in/guregu/null.v2"}, "reflect":[]string{"reflect"}}
Swagger works when we replace the gopkg.in by the original github name github.com/guregu/null. That's not a good workaround because we lose ability to specify version of null.
The problem is in the parser.go function ParseImportStatements where the package name is generated from the import name like this:
importPath := strings.Split(importedPackageName, "/")
importedPackageAlias = importPath[len(importPath)-1]
The package name is actually astPackage.Name (we verified that it's set to string "null").
@zasran can you, possible, make a pull request ?
@yvasiyarov Could you possblie think of making a swagger 2.0 branch please :)
@RobertJGabriel sorry for delay. Branch created
@yvasiyarov sorry I don't know what exactly the proper solution is, I don't understand what exactly is ParseImportStatements trying to do. Why is it looping over all files then all imports and tries to get the package name from there when the package name is available right in package (the outermost loop).
I thought that the fix would be fairly simpe for somebody who understand the code but if not I'll look into some more and see if I can figure out a fix.