sdk-codegen
sdk-codegen copied to clipboard
Go SDK string returning issue
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.
@kppk any ideas on this one?
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
This should be fixed by this. https://github.com/looker-open-source/sdk-codegen/pull/1021 Closing.