[英]How to replace ValidationProblemDetails with SCIM-compatible model validation error details in ASP.NET Core 3.1 Web API?
ASP.NET Core 3.1 is taking POSTed JSON (for creating a user via SCIM v2 in my fledgling Web API) and model-binding it to my C# request-data class CreateUserRequest
like a champ. 如果 JSON 中有错误,它会产生很好的基于 ProblemDetails 的错误。
例如,如果用户的姓氏(又名姓氏)丢失(这不应该是因为我[Require]
该属性),那么响应 JSON 是:-
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "|dbd3da85-4991c45298582047.",
"errors": {
"Name.LastName": [
"The LastName field is required.",
"The field LastName must be a string with a minimum length of 1 and a maximum length of 100."
]
}
}
这是ValidationProblemDetails
的结果,它适用于大多数用途,但不幸的是,它不适用于 SCIM,它需要不同的 JSON 格式,在此处描述。
例如,SCIM 错误看起来像这样:-
{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:Error"],
"scimType":"mutability"
"detail":"Attribute 'id' is readOnly",
"status": "400"
}
如何在 ASP.NET Core 3.1 Web API 中用其他东西(在这种情况下与 SCIM 兼容)替换ProblemDetails
和ValidationProblemDetails
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.