Open
Description
Description
If the API returns a 200, but the JSON payload is malformed, then the code Go code generated hides the decoding errors. It's more useful to surface these errors to the developer to handle.
Generated template currently with 2.4.15:
if localVarHttpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
}
Proposed change:
if localVarHttpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
return localVarReturnValue, localVarHttpResponse, err
}
Swagger-codegen version
2.4.15.
Technically, it's not a regression since 2.3.x returned generic interface{}
s. That version required you to do your own decoding.
Swagger declaration file content or url
not needed, it's with all Go generated code
Command line used for generation
swagger-cli generate
Steps to reproduce
You can generate any code.
Related issues/PRs
I opened #10429
Suggest a fix/enhancement
Metadata
Metadata
Assignees
Labels
No labels