Skip to content

Fix IParamConverter not being applied to IDictionary parameter values#92

Merged
twogood merged 3 commits intomainfrom
copilot/fix-91
Aug 6, 2025
Merged

Fix IParamConverter not being applied to IDictionary parameter values#92
twogood merged 3 commits intomainfrom
copilot/fix-91

Conversation

Copy link
Contributor

Copilot AI commented Aug 6, 2025

The RequestHandler.GetParams() method was not using the IParamConverter system for values within IDictionary parameters, causing inconsistent behavior compared to individual parameters. This was particularly problematic for DateTime values, which should be converted to ISO8601/RFC3339 format.

Problem

When using dictionary parameters with QueryParam, FormParam, or HeaderParam attributes, the values were converted using direct .ToString() calls instead of the configured parameter converters:

// Before fix - DateTime gets locale-specific format
var queryParams = new Dictionary<string, object>
{
    ["startDate"] = new DateTime(2023, 12, 25, 14, 30, 45, DateTimeKind.Utc)
};
// Results in: startDate=12/25/2023 2:30:45 PM (locale-dependent)

// Individual DateTime parameters worked correctly using DateTimeIso8601ParamConverter
public Task GetData([QueryParam] DateTime startDate) // Uses ISO8601 format

Solution

  1. Extended IParamConverterManager with a new GetConverter(Type type) method to support type-based converter lookup
  2. Updated ParamConverterManager to implement the new method using existing converter logic
  3. Modified RequestHandler.GetParams() to use a new ConvertValueToString() helper that leverages the param converter system for dictionary values
  4. Added comprehensive tests covering various dictionary types with DateTime values

Changes Made

  • Added GetConverter(Type type) to IParamConverterManager interface
  • Implemented the method in ParamConverterManager with minimal TypeOnlyParameterInfo helper class
  • Created ConvertValueToString() helper method in RequestHandler
  • Updated dictionary value handling in QueryParam, FormParam, and HeaderParam processing
  • Added 5 new tests covering IDictionary, Dictionary<string,object>, Dictionary<string,DateTime>, and Hashtable scenarios

Result

Dictionary parameters now consistently use the same conversion logic as individual parameters:

var queryParams = new Dictionary<string, object>
{
    ["startDate"] = new DateTime(2023, 12, 25, 14, 30, 45, DateTimeKind.Utc)
};
// Now results in: startDate=2023-12-25T14:30:45.0000000Z (ISO8601 format)

All existing tests continue to pass, ensuring backward compatibility while fixing the inconsistency.

Fixes #91.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change IParamConverter.CanConvert() to take a Type instead of creating a fake ParameterInfo instance.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please Change IParamConverter.CanConvert() to take a Type instead of creating a fake ParameterInfo instance in ParamConverterManager

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed IParamConverter.CanConvert() to take Type instead of ParameterInfo and removed the TypeOnlyParameterInfo helper class. All implementations now use Type directly, making the code cleaner and eliminating the fake ParameterInfo instances. Commit: 1bff500

Copilot AI changed the title [WIP] Bug in RequestHandler.GetParams(): IParamConverter is not applied to values in IDictionary parameters Fix IParamConverter not being applied to IDictionary parameter values Aug 6, 2025
Copilot AI requested a review from twogood August 6, 2025 10:02
@twogood twogood marked this pull request as ready for review August 6, 2025 10:18
@twogood twogood merged commit d57f5a6 into main Aug 6, 2025
8 checks passed
@twogood twogood deleted the copilot/fix-91 branch August 6, 2025 10:18
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.

Bug in RequestHandler.GetParams(): IParamConverter is not applied to values in IDictionary parameters

2 participants