Skip to content

Commit fb4b446

Browse files
committed
fix(parameter-based): respect [EnumMember] attribute when serialising enum query parameters
ParameterBased.getParameters() was calling .ToString() on enum values, producing the C# identifier name (e.g. FINANCIALEVENTGROUPID) rather than the wire format declared in [EnumMember(Value = "...")] (e.g. FINANCIAL_EVENT_GROUP_ID). This caused every enum-typed query parameter to be silently rejected by Amazon APIs. Fix: use StringEnumConverter (Newtonsoft.Json) for both the scalar enum and the IEnumerable<TEnum> branches so [EnumMember] attribute values are honoured. Also: type relatedIdentifierName on ParameterListFinancialTransactions20240619 as RelatedIdentifierNameEnum? instead of string? now that the serialisation is correct.
1 parent 3eb8bac commit fb4b446

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

Source/FikaAmazonAPI/Parameter/Finance/ParameterListFinancialTransactions20240619.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class ParameterListFinancialTransactions20240619 : ParameterBased
1919
/// </summary>
2020
public string? transactionStatus { get; set; }
2121
/// <summary>
22-
/// Possible values:`FINANCIAL_EVENT_GROUP_ID`: the financial event group ID associated with the transaction.
23-
///*Note: FINANCIAL_EVENT_GROUP_ID is the only `relatedIdentifier` with filtering capabilities at the moment. While other `relatedIdentifier` values will be included in the response when available, they cannot be used for filtering purposes.
22+
/// The identifier name to filter by. Only FINANCIAL_EVENT_GROUP_ID has filtering capability at the moment;
23+
/// other values appear in response payloads but cannot be used as query filters.
2424
/// </summary>
25-
public string? relatedIdentifierName { get; set; }
25+
public RelatedIdentifierNameEnum? relatedIdentifierName { get; set; }
2626
public string? relatedIdentifierValue { get; set; }
2727
public string nextToken { get; set; }
2828
public int? MaxNumberOfPages { get; set; }

Source/FikaAmazonAPI/Parameter/ParameterBased.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,22 @@ public virtual List<KeyValuePair<string, string>> getParameters()
5757
}
5858
else if (p.PropertyType.IsEnum || IsNullableEnum(p.PropertyType))
5959
{
60-
output = value.ToString();
60+
var enumSettings = new JsonSerializerSettings
61+
{
62+
Converters = new List<JsonConverter> { new StringEnumConverter() }
63+
};
64+
output = JsonConvert.SerializeObject(value, enumSettings).Trim('"');
6165
}
6266
else if (IsEnumerableOfEnum(p.PropertyType) || IsEnumerable(p.PropertyType))
6367
{
64-
var data = ((ICollection)value).Cast<object>().Select(a => a.ToString());
68+
var enumSettings = new JsonSerializerSettings
69+
{
70+
Converters = new List<JsonConverter> { new StringEnumConverter() }
71+
};
72+
var data = ((ICollection)value).Cast<object>()
73+
.Select(a => a.GetType().IsEnum
74+
? JsonConvert.SerializeObject(a, enumSettings).Trim('"')
75+
: a.ToString());
6576
if (data.Count() > 0)
6677
{
6778
var result = data.ToArray();

0 commit comments

Comments
 (0)