Skip to content

Commit

Permalink
fix http bear auth documentation for go clinets (#7312)
Browse files Browse the repository at this point in the history
  • Loading branch information
QP Hou authored Aug 31, 2020
1 parent d5a680e commit 3007483
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ Note, each API key must be added to a map of `map[string]APIKey` where the key i

{{/isApiKey}}
{{#isBasic}}
{{#isBasicBearer}}
- **Type**: HTTP Bearer token authentication

Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "BEARERTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

{{/isBasicBearer}}
{{#isBasicBasic}}
- **Type**: HTTP basic authentication

Expand Down
28 changes: 21 additions & 7 deletions modules/openapi-generator/src/main/resources/go/README.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,41 @@ Class | Method | HTTP request | Description
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), {{packageName}}.ContextAPIKey, {{packageName}}.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
r, err := client.Service.Operation(auth, args)
```

{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{#isHttpSignature}}
Not supported.

{{/isHttpSignature}}
{{#isBasicBasic}}- **Type**: HTTP basic authentication

Example

```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
auth := context.WithValue(context.Background(), {{packageName}}.ContextBasicAuth, {{packageName}}.BasicAuth{
UserName: "username",
Password: "password",
})
r, err := client.Service.Operation(auth, args)
```

{{/isBasic}}
{{/isBasicBasic}}
{{#isBasicBearer}}- **Type**: HTTP Bearer token authentication

Example

```golang
auth := context.WithValue(context.Background(), {{packageName}}.ContextAccessToken, "BEARERTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

{{/isBasicBearer}}
{{#isOAuth}}

- **Type**: OAuth
Expand All @@ -97,7 +111,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
auth := context.WithValue(context.Background(), {{packageName}}.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

Expand All @@ -109,7 +123,7 @@ 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)
auth := context.WithValue(oauth2.NoContext, {{packageName}}.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```

Expand All @@ -120,7 +134,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAWSv4, sw.AWSv4{
auth := context.WithValue(context.Background(), {{packageName}}.ContextAWSv4, {{packageName}}.AWSv4{
AccessKey: "ACCESSKEYSTRING",
SecretKey: "SECRETKEYSTRING",
})
Expand Down
10 changes: 5 additions & 5 deletions samples/client/petstore/go/go-petstore-withXml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Class | Method | HTTP request | Description
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
Expand All @@ -149,7 +149,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
Expand All @@ -164,7 +164,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
auth := context.WithValue(context.Background(), petstore.ContextBasicAuth, petstore.BasicAuth{
UserName: "username",
Password: "password",
})
Expand All @@ -185,7 +185,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
auth := context.WithValue(context.Background(), petstore.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

Expand All @@ -197,7 +197,7 @@ 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)
auth := context.WithValue(oauth2.NoContext, petstore.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```

Expand Down
10 changes: 5 additions & 5 deletions samples/client/petstore/go/go-petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Class | Method | HTTP request | Description
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
Expand All @@ -149,7 +149,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
Expand All @@ -164,7 +164,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
auth := context.WithValue(context.Background(), petstore.ContextBasicAuth, petstore.BasicAuth{
UserName: "username",
Password: "password",
})
Expand All @@ -185,7 +185,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
auth := context.WithValue(context.Background(), petstore.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

Expand All @@ -197,7 +197,7 @@ 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)
auth := context.WithValue(oauth2.NoContext, petstore.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ Note, each API key must be added to a map of `map[string]APIKey` where the key i

### bearer_test

- **Type**: HTTP Bearer token authentication

Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "BEARERTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```


### http_basic_test

Expand Down
29 changes: 8 additions & 21 deletions samples/openapi3/client/petstore/go/go-petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Class | Method | HTTP request | Description
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
Expand All @@ -152,7 +152,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
auth := context.WithValue(context.Background(), petstore.ContextAPIKey, petstore.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
Expand All @@ -162,15 +162,12 @@ r, err := client.Service.Operation(auth, args)

## bearer_test

- **Type**: HTTP basic authentication
- **Type**: HTTP Bearer token authentication

Example

```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
UserName: "username",
Password: "password",
})
auth := context.WithValue(context.Background(), petstore.ContextAccessToken, "BEARERTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

Expand All @@ -182,7 +179,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
auth := context.WithValue(context.Background(), petstore.ContextBasicAuth, petstore.BasicAuth{
UserName: "username",
Password: "password",
})
Expand All @@ -192,17 +189,7 @@ r, err := client.Service.Operation(auth, args)

## http_signature_test

- **Type**: HTTP basic authentication

Example

```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
UserName: "username",
Password: "password",
})
r, err := client.Service.Operation(auth, args)
```
Not supported.


## petstore_auth
Expand All @@ -218,7 +205,7 @@ r, err := client.Service.Operation(auth, args)
Example

```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
auth := context.WithValue(context.Background(), petstore.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

Expand All @@ -230,7 +217,7 @@ 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)
auth := context.WithValue(oauth2.NoContext, petstore.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```

Expand Down

0 comments on commit 3007483

Please sign in to comment.