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

[Go] Rewrite of Go Client, Server generator #5037

Merged
merged 8 commits into from
Apr 21, 2017
Merged

[Go] Rewrite of Go Client, Server generator #5037

merged 8 commits into from
Apr 21, 2017

Conversation

antihax
Copy link
Contributor

@antihax antihax commented Mar 13, 2017

PR checklist

  • Read the contribution guidelines.
  • Ran the shell/batch script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)
  • Filed the PR against the correct branch: master for non-breaking changes and 2.3.0 branch for breaking (non-backward compatible) changes.

Description of the PR

Rewrite of Go client. This will need community review. This is modeled after some other API clients (go-github, godo, etc).

  • Removed most of go-resty.
  • Moved http.Client to APIClient structure (for keep-alive, http2 multiplexing).
  • Authentication through contexts. OAuth2, AccessToken, or BasicAuth per request.
  • Resolves compile error when using []int as parameter or response.
  • Resolves date format parsing issues on date type.
  • Able to pass custom http.Clients (caching across clusters, custom timeouts, rate limiting, tracing, etc).
  • Catches http errors.
  • Mirrored many changes to the go-server so more complex templates can be used.
  • Optional parameters via map[string]interface.
  • Documentation updated.
  • Examples in README.md.

This replaces #4440

@antihax
Copy link
Contributor Author

antihax commented Mar 13, 2017

@guohuang @neilotoole @wy-z @vpolouchkine @ePaul @xavier-fernandez
Could you review and provide feedback on this PR?

This replaces PR #4440, it takes care of a few other issues I ran into as the API I am using evolves.

I was hoping to find a better solution for authentication but have been unable to come up with one.

I re-implemented the Configuration also so it is more familiar with the other languages.

Not sure why Shippable is failing, cannot see the error directly?

@wing328
Copy link
Contributor

wing328 commented Mar 13, 2017

Not sure why Shippable is failing, cannot see the error directly?

The shippable error has been worked around by #5031 by commenting the tests with OpenJDK8. The issue has nothing to do with our changes and I'll report the issue to Shippable later if it's still not resolved.

For the time being, please ignore the Shippable error.

@ePaul
Copy link
Contributor

ePaul commented Mar 13, 2017

The {{paramName}}/{{baseName}} stuff looks fine. I don't know Go, so I can't comment on the general functionality, or code quality.

// create path and map variables
localVarPath := a.Configuration.BasePath + "{{path}}"{{#pathParams}}
localVarPath := a.client.cfg.BasePath + "{{path}}"{{#pathParams}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For {{path}}, please use unescaped value, i.e. {{{path}}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -97,7 +97,7 @@ public GoClientCodegen() {
typeMapping.put("boolean", "bool");
typeMapping.put("string", "string");
typeMapping.put("UUID", "string");
typeMapping.put("date", "time.Time");
typeMapping.put("date", "SwaggerDateType");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antihax Shall we keep time.time so that the auto-generated code at least compile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it fail to compile with the template? time.Time used in this manner will cause a runtime error.

There may be a better way to handle it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about mapping it as "string" instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a possibility.

I have an app in production using the date type so it should help determine any issues that arise from using string.

I will test that tonight and convert if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String worked with minimal changes for the user. It can be converted by using
dateObject, err := time.Parse("2006-01-02", dateString)

{{#isApiKey}}- **Type**: API key
- **API key parameter name**: {{{keyParamName}}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
!!! NOT IMPLEMENTED !!!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antihax so API key (via header or query parameter) is no longer supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. I could not see in the original where it was supported as a reference of how to implement it.

I could take another look at some other implementations and try to determine. Is there a way to write tests for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall how I became confused here...

API Key in Query String: https://github.com/antihax/swagger-codegen/blob/New-GoClient-GoServer/samples/client/petstore/go/go-petstore/pet_api.go#L99

I will add the header equivalent tonight and alter the documentation.

@wing328
Copy link
Contributor

wing328 commented Apr 21, 2017

@antihax when you've time, I wonder if you can help resolve the merge conflicts and then I'll merge the enhancements into 2.3.0. Thanks!

@wing328 wing328 modified the milestones: v2.3.0, v2.2.3 Apr 21, 2017
@wing328
Copy link
Contributor

wing328 commented Apr 21, 2017

Seems like issues with CIs (shippable, Appveyor) at the moment. Will restart the jobs tomorrow to see if the issue goes away.

@antihax
Copy link
Contributor Author

antihax commented Apr 21, 2017 via email

@wing328
Copy link
Contributor

wing328 commented Apr 21, 2017

Ah interesting... I'll also take a look over the weekend.

Correct missing line from resolving conflicts.
@wing328
Copy link
Contributor

wing328 commented Apr 21, 2017

Saw your fix so shippable did its job in catching issues related to mustache (e.g. missing tags)

@wing328 wing328 merged commit 3ed1aa8 into swagger-api:2.3.0 Apr 21, 2017
@wing328 wing328 mentioned this pull request Apr 21, 2017
3 tasks
@wing328 wing328 changed the title Rewrite of Go Client #2 [Go] Rewrite of Go Client, Server generator Apr 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants