我有 swagger 设置,以便它在项目启动时使用 NSwag 基于我的 WebApi 中的控制器生成开放的 Api 规范和 Swagger Ui。我想增强 swagger Ui 以包括
我是 NSwag 的新手,不确定如何将这些增强功能添加到我的代码中,例如在哪里添加它们,我需要使用什么(控制器上的注释?XML 注释?另一种方式?)我尝试过编辑“ Swagger Editor',但不知道这是如何实现的,因为它会在每次应用程序启动时重新生成。
我已阅读 NSwag 文档,但这似乎都是关于添加我已经配置的 ASP.NET Core 中间件。
编辑: 我现在在页面顶部有一个描述,并且已经能够在 XML 注释中添加带有备注标记的示例 -有没有比使用 XML 注释更优雅的方法来执行此操作?
swagger-ui openapi asp.net-core-webapi nswag asp.net-core-3.1
这是迄今为止我的 C# 应用程序中对密码的流畅验证
\nRuleFor(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.");\nRun 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)