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

minimal api ,有没有类似传统控制器那种可以进行一个统一简单模型验证 #738

Open
ByZhouhang opened this issue Oct 16, 2024 · 1 comment
Assignees

Comments

@ByZhouhang
Copy link

Description

传统控制器可以类似这样写:
.ConfigureApiBehaviorOptions(o =>
{

  o.InvalidModelStateResponseFactory = (context) =>
  {
      var error = context.ModelState.Keys
                            .SelectMany(k => context.ModelState[k].Errors)
                            .Select(e => e.ErrorMessage)
                            .ToArray();

      return new JsonResult(ResponseOutput.NotOk("The inputs supplied to the API are invalid. " + JsonConvert.SerializeObject(error)));
  };

});

在minimal api 有比较好的方式统一处理 来自url 路由 body 里面参数类型明显不符合要求的参数的方式么?

.NET version

No response

MASA Framework version

No response

@Qinyouzeng
Copy link
Contributor

可以看看 FluentValidation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants