Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend url parameters default formatting #1781

Merged

Conversation

MikeAmputer
Copy link
Contributor

@MikeAmputer MikeAmputer commented Aug 10, 2024

Closes #1775

This PR extends the DefaultUrlParameterFormatter with additional formatting options based on parameter type or a combination of request and parameter types. This allows values with no QueryAttribute format to be custom-formatted without the necessity of fully reimplementing DefaultUrlParameterFormatter.

Example usage:

class CustomUrlParameterFormatter : DefaultUrlParameterFormatter
{
	public CustomUrlParameterFormatter()
	{
		AddFormat<DateTime>("yyyy-MM-ddTHH:mm:ss");
		AddFormat<MyRequest, DateTime>("yyyy-MM-ddTHH:mm:ss.fffZ");
	}
}

or

var urlParameterFormatter = new DefaultUrlParameterFormatter();
urlParameterFormatter.AddFormat<DateTime>("yyyy-MM-ddTHH:mm:ss");
urlParameterFormatter.AddFormat<MyRequest, DateTime>("yyyy-MM-ddTHH:mm:ss.fffZ");

Formatting priority:

  1. QueryAttribute format
  2. AddFormat<TContainer, TParameter> (might be suppressed by a QueryAttribute format)
  3. AddFormat<TParameter> (might be suppressed by a QueryAttribute format or a container specific format)

@MikeAmputer
Copy link
Contributor Author

Should I add some tests using RequestBuilderImplementation with URI query assertion, or is it sufficient to test just the formatting?

@ChrisPulman
Copy link
Member

I would generally go with the more tests the better approach; this helps to ensure that the change in operation you are adding is both fully tested and that any future changes do not break these changes.

@MikeAmputer
Copy link
Contributor Author

Alright then, URI query assertion tests were added.

Copy link

codecov bot commented Aug 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.66%. Comparing base (6ebeda5) to head (fd9c4dd).
Report is 75 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1781      +/-   ##
==========================================
- Coverage   87.73%   83.66%   -4.08%     
==========================================
  Files          33       36       +3     
  Lines        2348     2442      +94     
  Branches      294      345      +51     
==========================================
- Hits         2060     2043      -17     
- Misses        208      316     +108     
- Partials       80       83       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ChrisPulman ChrisPulman reopened this Aug 17, 2024
@ChrisPulman ChrisPulman merged commit 7cfdede into reactiveui:main Aug 17, 2024
3 of 4 checks passed
Copy link

github-actions bot commented Sep 1, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance default URL parameter formatting for custom formats
2 participants