-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Respect JsonSerializerOptions casing for property names in validation errors #62036
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
base: main
Are you sure you want to change the base?
Conversation
…ation errors Co-authored-by: captainsafia <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start! Left some comments inline.
src/Http/Http.Abstractions/test/Validation/ValidateContextTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: captainsafia <[email protected]>
I've addressed all the inline comments. Made the SerializerOptions property internal, removed the test file, and updated ValidationEndpointFilterFactory to use the internal property via reflection. All changes in commit 216406a. |
… from service provider Co-authored-by: captainsafia <[email protected]>
@captainsafia Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
@copilot Let's try to address the review comments I left for you earlier. You were on the right track with making the |
… complex keys Co-authored-by: captainsafia <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're almost there! One more comment. Also, be undo all the changes you made to the package.json
files and remove the package.json.bak
files.
…tions Co-authored-by: captainsafia <[email protected]>
@copilot Revert any changes made to package.json and package-lock.json files to their state in main. |
…for JsonPropertyName attributes Co-authored-by: captainsafia <[email protected]>
@copilot Oops! I totally forgot the other aspect to this. We need to format the member names as well. That means instead of:
we want to get:
|
Co-authored-by: captainsafia <[email protected]>
Co-authored-by: captainsafia <[email protected]>
... I've implemented the formatting for member names in validation error messages in e94aff2. Now both the property names used as keys and the property names inside the error messages follow the configured JSON naming policy. The implementation looks for error messages with the pattern "The X field is..." and formats the property name while preserving other parts of the message. |
Co-authored-by: captainsafia <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure all the tests are fixed.
src/Http/Http.Abstractions/test/Validation/ValidatableTypeInfoTests.cs
Outdated
Show resolved
Hide resolved
src/Http/Http.Abstractions/test/Validation/ValidatableTypeInfoTests.cs
Outdated
Show resolved
Hide resolved
src/Http/Http.Abstractions/test/Validation/ValidatableTypeInfoTests.cs
Outdated
Show resolved
Hide resolved
src/Http/Http.Abstractions/test/Validation/ValidatableTypeInfoTests.cs
Outdated
Show resolved
Hide resolved
src/Http/Http.Abstractions/test/Validation/ValidatableTypeInfoTests.cs
Outdated
Show resolved
Hide resolved
src/Http/Http.Abstractions/test/Validation/ValidatableTypeInfoTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: captainsafia <[email protected]>
... As per our discussion, I removed the error message formatting code from ValidateContext.cs in e9f9a2e. This way, property names in keys (used as JSON property names) follow the configured naming policy, while the error messages preserve the original member names.
Updated all the tests to expect the original member names in validation error messages while still respecting the JSON naming policy for keys in commit e9f9a2e. |
@copilot it looks like some tests in ValidatableTypeInfoTests and ValidationsGeneratorTests are failing. Can you fix them? |
@copilot Can you fix this build error by adding the correct attribute to the constructor?
|
…idatablePropertyInfo constructor Co-authored-by: captainsafia <[email protected]>
... Fixed the build error by adding Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:If you need me to access, download, or install something from one of these locations, you can either:
|
Summary
When configuring JSON serialization options with a custom property naming policy (like camelCase), validation error responses were not consistently following the same naming policy for property names. This created a disconnect between what clients send/expect and what the validation errors contained.
The implemented changes ensure validation errors respect the configured JSON naming policy, making them consistent with the rest of the API's JSON formatting.
Changes
SerializerOptions
property toValidateContext
to access JSON naming policiesValidationEndpointFilterFactory
to pass the JSON options from DI to the validation contextPropertyNamingPolicy
for error key namesitems[0].productName
→items[0].productName
)Before
After
The implementation preserves the full compatibility with existing usage while ensuring that property names in validation errors now follow the configured naming policy.
Fixes #61764.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
cdn.fwupd.org
/usr/bin/fwupdmgr refresh
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 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.