Revert "BP-761: Validation exception when sort by or sort direction are empty in the request." #58
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Should we revert #57?
Issue
Non-nullable reference fields are marked as Required by default.
Issue was suppressed on projects by setting the SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true
This suppress was not added to Blueprint template.
Request:
/Users?PageNumber=1&PageSize=20&SortBy=emailAddress&SortDirection=
Error:
Exception occurs when query params in HTTP request contains empty/missing value sortBy/sortDirection.
Option 1: Make SortBy and SortDirection nullable fields.
Introduced by: #57
Potential breaking changes?
After packages are updated in a project, if SortBy or SortDirection are used directly in code e.g.
var isPriceWithVatSort = request.SortBy.Equals("unitPriceWithVat")
-> this would lead to compile time warningCS8602 Dereference of a possibly null reference
Option 2: SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true
Testing behavior of model validation and model binding, example:
False
(default): Non-nullable reference fields are marked as Required by default.For request
/Users?Name=&PageNumber=1&PageSize=20
public string Name { get; set; } = String.Empty;
=> Validation error 400: Name is requiredpublic string? Name { get; set; }
=> OK: Model binding will set Name = nullpublic string? Name { get; set; } = String.Empty;
=> OK: Model binding will set Name = null (!?)public string? Email { get; set; } = String.Empty;
=> OK: Model binding will set Email = "";True
: This required behavior is suppressedFor request
/Users?Name=&PageNumber=1&PageSize=20
public string Name { get; set; } = String.Empty;
=> OK: Model binding will set Name = null (!!? seems hazardous)public string? Name { get; set; }
=> OK: Model binding will set Name = nullpublic string? Name { get; set; } = String.Empty;
=> OK: Model binding will set Name = null (!?)public string? Email { get; set; } = String.Empty;
=> OK: Model binding will set Email = "";