Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger fails for gopkg.in/guregu/null.v2 (import name not same as package name) #90

Open
zasran opened this issue Sep 11, 2015 · 4 comments

Comments

@zasran
Copy link
Contributor

zasran commented Sep 11, 2015

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").

@yvasiyarov
Copy link
Owner

@zasran can you, possible, make a pull request ?

@RobertJGabriel
Copy link
Contributor

@yvasiyarov Could you possblie think of making a swagger 2.0 branch please :)

@yvasiyarov
Copy link
Owner

@RobertJGabriel sorry for delay. Branch created

@zasran
Copy link
Contributor Author

zasran commented Sep 11, 2015

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants