sdk-codegen icon indicating copy to clipboard operation
sdk-codegen copied to clipboard

Go SDK string returning issue

Open RFarrow9 opened this issue 4 years ago • 2 comments

I've been using the Go SDK, and found that in cases where the return result is a string and not a json, it isn't returned at all. For example in the following snippet (from sdk/v3/methods):

// ### Git Deploy Key // // Returns the ssh public key previously created for a project's git repository. // // GET /projects/{project_id}/git/deploy_key -> string func (l *LookerSDK) GitDeployKey( projectId string, options *rtl.ApiSettings) (string, error) { projectId = url.PathEscape(projectId) var result string err := l.session.Do(&result, "GET", "/3.1", fmt.Sprintf("/projects/%v/git/deploy_key", projectId), nil, nil, options) return result, err }

The result is declared as a string, and in the Do function (in rtl/Auth) it is assumed that the result is jsonnable:

(line 140):: err = json.NewDecoder(res.Body).Decode(&result)

This err is also unraised, and so the failure can be silent, and a empty string is bubbled up in the response.

I suggest replacing the above code with something like:

resBody, err := ioutil.ReadAll(res.Body)

if err != nil { return err }

if json.Valid([]byte(resBody)) { json.Unmarshal(resBody, &result) } else { n := result.(*string) string_response := string(resBody) *n = string_response }

This works for me now with this subbed in, but very very new to Go so code might be a bit rough around the edges.

RFarrow9 avatar Mar 23 '21 13:03 RFarrow9

@kppk any ideas on this one?

joeldodge79 avatar Mar 25 '21 04:03 joeldodge79

The same problem happens when using /queries/%d/run/sql - it tries to decode JSON but inside there is just a string.

/content_thumbnail/look/X/png - instead of returning []byte it returns empty string

lustefaniak avatar Jan 26 '22 21:01 lustefaniak

This should be fixed by this. https://github.com/looker-open-source/sdk-codegen/pull/1021 Closing.

jeremytchang avatar Mar 28 '23 19:03 jeremytchang