普通提交

master
bicijinlian 4 years ago
parent 6c75a06bb0
commit 1ecbc1a3cd

@ -64,17 +64,22 @@ namespace SwaggerStudy.Controllers
/// <example>
/// 示例
/// ```
/// sfdfsdafsadfsaf
/// {
/// "Id":1,
/// "Name":"王高峰",
/// "Age":32
/// }
/// ```
/// </example>
/// <remarks>我是Remark注释</remarks>
/// <param name="studentId" example="1">学生Id(变量在路由中时example才有用)</param>
/// <see cref="http://www.baidu.com"/>
/// <returns>
/// 查询到的学生
/// </returns>
[AllowAnonymous]
[HttpGet("{studentId:int}")]
public IActionResult Get([FromRoute]int studentId)
[HttpGet("{studentId:int:min(1)}")]
public IActionResult Get([FromRoute][FromQuery]int studentId)
{
var apiResult = new ResultBase()
{

@ -1107,9 +1107,9 @@ _注意如果您使用的是[Swashbuckle Annotations library](#swashbuckleasp
## Swashbuckle.AspNetCore.SwaggerUI ##
### Change Relative Path to the UI ###
### 更改 UI 的相对路径 ###
By default, the Swagger UI will be exposed at "/swagger". If necessary, you can alter this when enabling the SwaggerUI middleware:
默认情况下,Swagger UI 将暴露在"/swagger"处。如有必要,可以在启用`SwaggerUI`中间件时更改此设置:
```csharp
app.UseSwaggerUI(c =>
@ -1119,9 +1119,10 @@ app.UseSwaggerUI(c =>
}
```
### Change Document Title ###
### 更改文档标题 ###
默认情况下,`Swagger UI`将具有通用文档标题。当您打开多个Swagger页面时,可能很难区分它们。您可以在启用`SwaggerUI`中间件时更改此设置:
By default, the Swagger UI will have a generic document title. When you have multiple Swagger pages open, it can be difficult to tell them apart. You can alter this when enabling the SwaggerUI middleware:
```csharp
app.UseSwaggerUI(c =>
@ -1131,9 +1132,10 @@ app.UseSwaggerUI(c =>
}
```
### List Multiple Swagger Documents ###
### 列出多个 Swagger 文档 ###
When enabling the middleware, you're required to specify one or more Swagger endpoints (fully qualified or relative to the UI page) to power the UI. If you provide multiple endpoints, they'll be listed in the top right corner of the page, allowing users to toggle between the different documents. For example, the following configuration could be used to document different versions of an API.
在启用中间件时,您需要指定一个或多个 Swagger 端点(绝对或相对于UI页面)来支持 UI。如果您提供多个端点它们将被列在页面的右上角允许用户在不同的文档之间切换。
例如,下面的配置可用于记录 API 的不同版本:
```csharp
app.UseSwaggerUI(c =>
@ -1143,9 +1145,10 @@ app.UseSwaggerUI(c =>
}
```
### Apply swagger-ui Parameters ###
### 应用 swagger-ui 参数 ###
The swagger-ui ships with it's own set of configuration parameters, all described here https://github.com/swagger-api/swagger-ui/blob/v3.8.1/docs/usage/configuration.md#display. In Swashbuckle, most of these are surfaced through the SwaggerUI middleware options:
`Swagger-ui` 附带了它自己的一套配置参数,这些参数都在[此处](https://github.com/swagger-api/swagger-ui/blob/v3.8.1/docs/usage/configuration.md#display)描述。
在 Swashbuckle中大多数的参数配置都是通过 `Swagger-UI` 中间件的特定选项暴露出来的:
```csharp
app.UseSwaggerUI(c =>

@ -22,7 +22,7 @@ namespace SwaggerStudy
.ConfigureWebHostDefaults(webBuilder =>
{
//测试 Swagger 设置
//webBuilder.UseStartup<StartupTest>();
webBuilder.UseStartup<StartupTest>();
//不使用 Swagger
//webBuilder.UseStartup<Startup>();
@ -37,7 +37,7 @@ namespace SwaggerStudy
//webBuilder.UseStartup<Startup031>();
//使用Newtonsoft替代默认System.Text.Json序列化库
webBuilder.UseStartup<Startup032>();
//webBuilder.UseStartup<Startup032>();
});
}
}

@ -156,6 +156,11 @@ namespace SwaggerStudy
});
app.UseSwaggerUI(setup =>
{
setup.EnableDeepLinking();
setup.DisplayRequestDuration();
setup.ShowCommonExtensions();
setup.ShowExtensions();
//swagger 访问页面前缀默认swagger
//SwaggerUi首页地址baseUrl+前辍+index.html 默认:/swagger/index.html
setup.RoutePrefix = "Swagger";

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
@ -9,6 +10,8 @@ namespace SwaggerStudy
{
public class StudentVModel
{
[Required(ErrorMessage ="必填")]
[MinLength(1,ErrorMessage ="最值为1")]
public int Id { get; set; }
public string Name { get; set; }

Loading…
Cancel
Save