Bug Report: JSON Unmarshal Error in WalletsAPI TopUp Endpoint
- Dominant language
- Go
- Stars
- 2
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
### Description
The SDK fails to parse error responses from the `WalletsIdTopUpPost` endpoint due to a type mismatch in the error details field.
### Error Message
```
json: cannot unmarshal array into Go struct field ErrorsErrorDetail.error.details of type map[string]interface {}
```
### Expected Behavior
The SDK should successfully parse error responses from the API, allowing users to access detailed error information.
### Actual Behavior
The SDK crashes when attempting to unmarshal error responses because the `ErrorsErrorDetail.Details` field is defined as `map[string]interface{}`, but the API returns an array.
### Steps to Reproduce
```go
topUpReq := flexpricesdk.NewDtoTopUpWalletRequest(idempotencyKey, transactionReason)
topUpReq.SetAmount(100.0)
result, httpResp, err := apiClient.WalletsAPI.WalletsIdTopUpPost(ctx, walletID).
Request(*topUpReq).
Execute()
// Error occurs during error response parsing
```
### Root Cause
The SDK's error model defines:
```go
type ErrorsErrorDetail struct {
Details map[string]interface{} `json:"details"`
}
```
However, the API returns:
```json
{
"error": {
"details": [...] // Array, not object/map
}
}
```
### Proposed Solution
Update the `ErrorsErrorDetail` struct to handle both arrays and objects:
**Option 1: Use interface{}**
```go
type ErrorsErrorDetail struct {
Details interface{} `json:"details"`
}
```
**Option 2: Use array (if details is always an array)**
```go
type ErrorsErrorDetail struct {
Details []interface{} `json:"details"`
}
```
**Option 3: Use custom unmarshaling**
```go
type ErrorsErrorDetail struct {
Details json.RawMessage `json:"details"`
}
```
### Workaround
Currently, users must manually read the HTTP response body to access error details:
```go
result, httpResp, err := apiClient.WalletsAPI.WalletsIdTopUpPost(ctx, walletID).
Request(*topUpReq).
Execute()
if err != nil && httpResp != nil {
bodyBytes, _ := io.ReadAll(httpResp.Body)
fmt.Printf("Error details: %s\n", string(bodyBytes))
}
```
### Impact
- **Severity**: High
- **Affected Endpoints**: At minimum `WalletsIdTopUpPost`, potentially other endpoints with error responses
- **User Impact**: Unable to properly handle API errors, leading to poor error messages and debugging difficulties
### Additional Context
This appears to be an issue with the OpenAPI specification or SDK generation process. The generated models don't match the actual API response format for error payloads.
### Checklist
- [ ] Verify OpenAPI spec matches actual API responses
- [ ] Update error model definitions
- [ ] Regenerate SDK
- [ ] Add tests for error response parsing
- [ ] Update documentation if needed
Contributor guide
Assessment
This issue has not been assessed yet.