Swagger-codegen: [Go] Update to use oauth2

Created on 4 Oct 2017  路  2Comments  路  Source: swagger-api/swagger-codegen

Description

I would like to use oauth2 with the codegen SDK. This is supported in resty v1.

Issues with codegen SDK reported here:

It seems like 2 changes are needed:

  • Change Configuration.Transport type to http.RoundTripper from *http.Transport
  • Change api_client.go to use "gopkg.in/go-resty/resty.v1" from "gopkg.in/go-resty/resty.v0"
Swagger-codegen version

https://github.com/grokify/ringcentral-sdk-go-scg/blob/master/swagger_ringcentral_codegen_version.txt

$ unzip -p swagger-codegen-cli.jar META-INF/MANIFEST.MF
Manifest-Version: 1.0
implementation-version: 2.2.3
Built-By: tony
Build-Jdk: 1.7.0_79
package: io.swagger
Created-By: Apache Maven 3.3.9
Main-Class: io.swagger.codegen.SwaggerCodegen
url: https://github.com/swagger-api/swagger-codegen/modules/swagger-co
 degen-cli
mode: development
Swagger declaration file content or url

https://github.com/grokify/ringcentral-sdk-go-scg/blob/master/swagger_ringcentral_spec.json

Command line used for generation

https://github.com/grokify/ringcentral-sdk-go-scg/blob/master/swagger_ringcentral_command.sh

Steps to reproduce

Run this code with an unmodified client SDK:

https://github.com/grokify/ringcentral-sdk-go-scg/blob/master/examples/get_extension/get_extension.go

Related issues/PRs

not found

Suggest a fix/enhancement

| Item | old | new |
|------|-----|-------|
| Configuration.Transport type | *http.Transport | http.RoundTripper |
| resty dependency | gopkg.in/go-resty/resty.v0 | gopkg.in/go-resty/resty.v1 |

More testing is necessary to ensure resty.v1 is backward compatible with resty.v0 everywhere used.

Go Feature

Most helpful comment

Thanks @wing328!

I've verified v2.3.0 works for me using oauth2 with a http.Client created by oauth2.Config.Client() using an updated version of my go-aha client (https://github.com/grokify/go-aha). I'll update this and the other auto-generated SDKs I maintain.

I use something like the following now:

cfg := aha.NewConfiguration()
cfg.HTTPClient = client // generated by oauth2.Config.Client()
apiClient := aha.NewAPIClient(cfg)
featuresApi := apiClient.FeaturesApi

As a bonus, I noticed that a couple of things are much nicer in 2.3.0:

  • "type":"string", "format":"date" now results in a string instead of a time.Time.
  • query parameters are now a map[string]interface{} instead of a sequence of function parameters.

All 2 comments

@grokify can you check the latest master (2.3.0), which has Go client refactored and OAuth2 support?

Thanks @wing328!

I've verified v2.3.0 works for me using oauth2 with a http.Client created by oauth2.Config.Client() using an updated version of my go-aha client (https://github.com/grokify/go-aha). I'll update this and the other auto-generated SDKs I maintain.

I use something like the following now:

cfg := aha.NewConfiguration()
cfg.HTTPClient = client // generated by oauth2.Config.Client()
apiClient := aha.NewAPIClient(cfg)
featuresApi := apiClient.FeaturesApi

As a bonus, I noticed that a couple of things are much nicer in 2.3.0:

  • "type":"string", "format":"date" now results in a string instead of a time.Time.
  • query parameters are now a map[string]interface{} instead of a sequence of function parameters.
Was this page helpful?
0 / 5 - 0 ratings