-
Notifications
You must be signed in to change notification settings - Fork 6k
[Go] Rewrite of Go Client, Server generator #5037
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
Changes from 4 commits
a07e456
023f433
805ed00
f38c62f
dcb60f2
bfdd67e
2479173
77ef70c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,25 +38,49 @@ Class | Method | HTTP request | Description | |
{{/model}}{{/models}} | ||
|
||
## Documentation For Authorization | ||
|
||
{{^authMethods}} All endpoints do not require authorization. | ||
{{^authMethods}} Endpoints do not require authorization. | ||
{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}} | ||
{{#authMethods}}## {{{name}}} | ||
|
||
{{#authMethods}} | ||
## {{{name}}} | ||
{{#isApiKey}}- **Type**: API key | ||
- **API key parameter name**: {{{keyParamName}}} | ||
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} | ||
!!! NOT IMPLEMENTED !!! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
{{/isApiKey}} | ||
{{#isBasic}}- **Type**: HTTP basic authentication | ||
|
||
Example | ||
``` | ||
auth := context.WithValue(oauth2.NoContext, sw.ContextBasicAuth, sw.BasicAuth{ | ||
UserName: "username", | ||
Password: "password", | ||
}) | ||
r, err := client.Service.Operation(auth, args) | ||
``` | ||
{{/isBasic}} | ||
{{#isOAuth}}- **Type**: OAuth | ||
- **Flow**: {{{flow}}} | ||
- **Authorizatoin URL**: {{{authorizationUrl}}} | ||
- **Authorization URL**: {{{authorizationUrl}}} | ||
- **Scopes**: {{^scopes}}N/A{{/scopes}} | ||
{{#scopes}} - **{{{scope}}}**: {{{description}}} | ||
{{/scopes}} | ||
{{/isOAuth}} | ||
|
||
Example | ||
``` | ||
auth := context.WithValue(oauth2.NoContext, sw.ContextAccessToken, "ACCESSTOKENSTRING") | ||
r, err := client.Service.Operation(auth, args) | ||
``` | ||
|
||
Or via OAuth2 module to automaticly refresh tokens and perform user authentication. | ||
``` | ||
import "golang.org/x/oauth2" | ||
|
||
/ .. Perform OAuth2 round trip request and obtain a token .. // | ||
|
||
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) | ||
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource) | ||
r, err := client.Service.Operation(auth, args) | ||
``` | ||
{{/isOAuth}} | ||
{{/authMethods}} | ||
|
||
## Author | ||
|
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)