Skip to content

fix(parameter-based): respect [EnumMember] attribute when serialising enum query parameters#945

Open
ProNotion wants to merge 2 commits into
abuzuhri:mainfrom
ProNotion:fix/parameter-based-enum-member-serialisation-clean
Open

fix(parameter-based): respect [EnumMember] attribute when serialising enum query parameters#945
ProNotion wants to merge 2 commits into
abuzuhri:mainfrom
ProNotion:fix/parameter-based-enum-member-serialisation-clean

Conversation

@ProNotion
Copy link
Copy Markdown
Collaborator

Summary

  • ParameterBased.getParameters() was calling .ToString() on enum values, producing the C# identifier name (e.g. FINANCIALEVENTGROUPID) instead of the wire format declared via [EnumMember(Value = "...")] (e.g. FINANCIAL_EVENT_GROUP_ID). Amazon APIs silently reject the malformed values, making every enum-typed query parameter effectively broken when the C# member name differs from the API wire value.
  • Fixed by using StringEnumConverter (Newtonsoft.Json) in both the scalar enum branch and the IEnumerable<TEnum> branch, consistent with the fallback path that was already doing this correctly for other types.
  • relatedIdentifierName on ParameterListFinancialTransactions20240619 is now typed as RelatedIdentifierNameEnum? instead of string?, taking advantage of the fixed serialisation.

Root cause

// Before - ignores [EnumMember(Value = "FINANCIAL_EVENT_GROUP_ID")]
else if (p.PropertyType.IsEnum || IsNullableEnum(p.PropertyType))
{
    output = value.ToString();  // produces "FINANCIALEVENTGROUPID"
}

// After - respects [EnumMember] attribute
else if (p.PropertyType.IsEnum || IsNullableEnum(p.PropertyType))
{
    var enumSettings = new JsonSerializerSettings
    {
        Converters = new List<JsonConverter> { new StringEnumConverter() }
    };
    output = JsonConvert.SerializeObject(value, enumSettings).Trim('"');
}

Test plan

  • Build passes with 0 errors (dotnet build)
  • Verify that ParameterListFinancialTransactions20240619 with relatedIdentifierName = RelatedIdentifierNameEnum.FINANCIALEVENTGROUPID produces relatedIdentifierName=FINANCIAL_EVENT_GROUP_ID in the query string
  • Check other enum-typed parameters in other ParameterBased subclasses produce their expected wire values

ProNotion added 2 commits June 4, 2026 05:56
… 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.
…eEnum

ParameterListFinancialTransactions20240619.relatedIdentifierName is now typed as
RelatedIdentifierNameEnum? rather than string?, so the sample code must use the
enum member instead of a raw string literal.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 4, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant