小编ims*_*san的帖子

自定义自动生成的 Swagger 定义

我有 swagger 设置,以便它在项目启动时使用 NSwag 基于我的 WebApi 中的控制器生成开放的 Api 规范和 Swagger Ui。我想增强 swagger Ui 以包括

  • 每个端点的摘要/描述
  • 需要参数输入的端点的示例参数输入
  • POST 调用的请求正文示例
  • 一个示例访问令牌,只能在 swagger 文档中使用,以轻松进行身份验证并能够尝试一切(有点像此示例https://petstore.swagger.io/

我是 NSwag 的新手,不确定如何将这些增强功能添加到我的代码中,例如在哪里添加它们,我需要使用什么(控制器上的注释?XML 注释?另一种方式?)我尝试过编辑“ Swagger Editor',但不知道这是如何实现的,因为它会在每次应用程序启动时重新生成。

我已阅读 NSwag 文档,但这似乎都是关于添加我已经配置的 ASP.NET Core 中间件。

编辑: 我现在在页面顶部有一个描述,并且已经能够在 XML 注释中添加带有备注标记的示例 -有没有比使用 XML 注释更优雅的方法来执行此操作?

swagger-ui openapi asp.net-core-webapi nswag asp.net-core-3.1

5
推荐指数
1
解决办法
3264
查看次数

C# 中具有流畅验证的正则表达式 - 如何不允许密码中出现空格和某些特殊字符?

这是迄今为止我的 C# 应用程序中对密码的流畅验证

\n
RuleFor(request => request.Password)\n    .NotEmpty()\n    .MinimumLength(8)\n    .Matches("[A-Z]+").WithMessage("'{PropertyName}' must contain one or more capital letters.")\n    .Matches("[a-z]+").WithMessage("'{PropertyName}' must contain one or more lowercase letters.")\n    .Matches(@"(\\d)+").WithMessage("'{PropertyName}' must contain one or more digits.")\n    .Matches(@"[""!@$%^&*(){}:;<>,.?/+\\-_=|'[\\]~\\\\]").WithMessage("'{ PropertyName}' must contain one or more special characters.")\n    .Matches("(?!.*[\xc2\xa3# \xe2\x80\x9c\xe2\x80\x9d])").WithMessage("'{PropertyName}' must not contain the following characters \xc2\xa3 # \xe2\x80\x9c\xe2\x80\x9d or spaces.")\n    .Must(pass => !blacklistedWords.Any(word => pass.IndexOf(word, StringComparison.OrdinalIgnoreCase) >= 0))\n        .WithMessage("'{PropertyName}' contains a word that is not allowed.");\n
Run Code Online (Sandbox Code Playgroud)\n

以下部分目前不起作用

\n
.Matches("(?!.*[\xc2\xa3# \xe2\x80\x9c\xe2\x80\x9d])").WithMessage("'{PropertyName}' must not contain the following …
Run Code Online (Sandbox Code Playgroud)

c# regex validation fluentvalidation

3
推荐指数
1
解决办法
8668
查看次数