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

gnostic-go-generator: -output doesn't like non package names #111

Closed
bhenderson opened this issue Feb 8, 2019 · 2 comments
Closed

gnostic-go-generator: -output doesn't like non package names #111

bhenderson opened this issue Feb 8, 2019 · 2 comments

Comments

@bhenderson
Copy link
Contributor

bhenderson commented Feb 8, 2019

I know the docs say that -out is also the package name, but the error message is confusing. when I do something like -output=/tmp/bookstore I get

Plugin error: [constants.go:3:9: expected 'IDENT', found '/']

I think it would be nice to have a friendlier error.

I've traced this to goimports errors. related to #110
https://github.com/googleapis/gnostic/blob/d55a06a32dc7468c645ac01d93d37d4dd47ca062/plugins/gnostic-go-generator/renderer.go#L63

I made some changes like

diff --git a/plugins/gnostic-go-generator/renderer.go b/plugins/gnostic-go-generator/renderer.go
index 93fd47d..31efb8e 100644
--- a/plugins/gnostic-go-generator/renderer.go
+++ b/plugins/gnostic-go-generator/renderer.go
@@ -60,7 +60,9 @@ func (renderer *Renderer) Render(response *plugins.Response, files []string) (er
                }
                // run generated Go files through imports pkg
                if filepath.Ext(file.Name) == ".go" {
-                       file.Data, err = imports.Process(file.Name, file.Data, nil)
+                       if file.Data, err = imports.Process(file.Name, file.Data, nil); err != nil {
+                               response.Errors = append(response.Errors, fmt.Sprintf("ERROR %v", err))
+                       }
                }
                response.Files = append(response.Files, file)
        }

The last error gets reported twice though due to named returns, and I was thinking it would be really nice to still write out the files so that the user can inspect the problem in context.

thoughts?

@bhenderson bhenderson changed the title gnostic-go-generator: -out doesn't like non package names gnostic-go-generator: -output doesn't like non package names Feb 8, 2019
@bhenderson
Copy link
Contributor Author

The code I put above is really for better error messaging.

I'm working on a PR for cleaning the package name.

bhenderson added a commit to bhenderson/gnostic that referenced this issue Feb 9, 2019
I wanted to be able to run -output . or -output /path/to/dir

Using format.Source was the easiest way I could figure out how to
validate the package name.

Relates to google#111
@bhenderson
Copy link
Contributor Author

Closed by #112

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

1 participant