-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
bugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.cost: SWill take up to 2 days to completeWill take up to 2 days to completeenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-mvc-formattingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labelsseverity-nice-to-haveThis label is used by an internal toolThis label is used by an internal tool
Milestone
Description
Describe the bug
The issue 7439 was not completely addressed, the bot blocked the issue from commenting, but I think this main problem should be addressed:
As is, Net Core responds almost everything as camel case, except for model validations, which I think is odd:
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "|706e0133-46db8fce16cb675d.",
"errors": {
"Email": [
"The Email field is not a valid e-mail address."
],
"Password": [
"The field Password must be a string or array type with a minimum length of '8'."
]
}
}
As you see, all the properties are camel case but the field names, a workaround is to use CustomProblemDetailsFactory
from the comment in the same issue.
To Reproduce
Create a project and a controller with a model with validations.
Make sure the controller is annotated with [ApiController]
, so validation is handled automatically.
Example:
[Authorize]
[ApiController]
[Route("Api/Address/[controller]")]
public class ColonyController : Controller
{
[HttpPost]
[Route("[action]")]
public Task<int> Create([FromBody]ColonyToAddDto colonyToAddDto)
{
return Task.FromResult(0);
}
}
With the model
public class ColonyToAddDto
{
[Required]
[StringLength(300, MinimumLength = 3)]
public string Name { get; set; }
[Range(1, 99999)]
public int PostalCode { get; set; }
[Range(1, double.PositiveInfinity)]
public int MunicipalityId { get; set; }
}
Further technical details
- ASP.NET Core version 3.1
codeaid, aayjaychan, bcronje, JonAnders, tr00st and 4 morebcronje, gklittlejohn and TanvirArjel
Metadata
Metadata
Assignees
Labels
bugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.cost: SWill take up to 2 days to completeWill take up to 2 days to completeenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-mvc-formattingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labelsseverity-nice-to-haveThis label is used by an internal toolThis label is used by an internal tool