master
bicijinlian 4 years ago
parent 1ecbc1a3cd
commit b97733e9fe

@ -1169,13 +1169,14 @@ app.UseSwaggerUI(c =>
});
```
_NOTE: The `InjectOnCompleteJavaScript` and `InjectOnFailureJavaScript` options have been removed because the latest version of swagger-ui doesn't expose the neccessary hooks. Instead, it provides a [flexible customization system](https://github.com/swagger-api/swagger-ui/blob/master/docs/customization/overview.md) based on concepts and patterns from React and Redux. To leverage this, you'll need to provide a custom version of index.html as described [below](#customize-indexhtml)._
_注意`InjectOnCompleteJavaScript`和`InjectOnFailureJavaScript`选项已被删除因为最新版本的swagger ui未公开必要的钩子。相反它提供了一个基于React和Redux的概念和模式的[灵活的定制系统](https://github.com/swagger-api/swagger-ui/blob/master/docs/customization/overview.md)。
要利用这一点,您需要提供[下述](#customize-indexhtml)Index.html文件_
The [custom index sample app](test/WebSites/CustomUIIndex/Swagger/index.html) demonstrates this approach, using the swagger-ui plugin system provide a custom topbar, and to hide the info component.
[自定义index.html 示例应用程序](test/WebSites/CustomUIIndex/Swagger/index.html)演示了这种方法,使用 `SwaggerUI `插件系统提供了一个自定义的 `topbar`,并隐藏了 `info 组件`
### Inject Custom CSS ###
### 注入自定义 CSS ###
To tweak the look and feel, you can inject additional CSS stylesheets by adding them to your `wwwroot` folder and specifying the relative paths in the middleware options:
要调整样式可以通过将其他CSS样式表添加到 `wwwroot` 文件夹并在中间件选项中指定相对路径来插入这些样式表:
```csharp
app.UseSwaggerUI(c =>
@ -1185,9 +1186,9 @@ app.UseSwaggerUI(c =>
}
```
### Customize index.html ###
### 定制 index.html ###
To customize the UI beyond the basic options listed above, you can provide your own version of the swagger-ui index.html page:
要自定义上面列出的基本选项以外的UI可以提供自定义的 `Swagger UI`r Index.html 页:
```csharp
app.UseSwaggerUI(c =>
@ -1199,11 +1200,11 @@ app.UseSwaggerUI(c =>
_To get started, you should base your custom index.html on the [default version](src/Swashbuckle.AspNetCore.SwaggerUI/index.html)_
### Enable OAuth2.0 Flows ###
### 启用 OAuth2.0 流程 ###
The swagger-ui has built-in support to participate in OAuth2.0 authorization flows. It interacts with authorization and/or token endpoints, as specified in the Swagger JSON, to obtain access tokens for subsequent API calls. See [Adding Security Definitions and Requirements](#add-security-definitions-and-requirements) for an example of adding OAuth2.0 metadata to the generated Swagger.
`swagger-ui`具有参与OAuth2.0授权流的内置支持。它与Swagger JSON中指定的授权(令牌)端点交互以获取用于后续API调用的访问令牌。有关向生成的 Swagger 添加 OAuth2.0 元数据的示例,请参见[添加安全性定义和要求](#add-security-definitions-and-requirements)。
If you're Swagger endpoint includes the appropriate security metadata, the UI interaction should be automatically enabled. However, you can further customize OAuth support in the UI with the following settings below. See https://github.com/swagger-api/swagger-ui/blob/v3.10.0/docs/usage/oauth2.md for more info:
如果您希望Swagger端点包含适当的安全元数据则应该自动启用UI交互。但是您可以使用以下设置在UI中进一步自定义OAuth支持。有关详细信息请[参见](https://github.com/swagger-api/swagger-ui/blob/v3.10.0/docs/usage/oauth2.md)
```csharp
app.UseSwaggerUI(c =>
@ -1222,16 +1223,16 @@ app.UseSwaggerUI(c =>
## Swashbuckle.AspNetCore.Annotations ##
### Install and Enable Annotations ###
### 安装和启用 Annotations ###
1. Install the following Nuget package into your ASP.NET Core application.
1. 将以下 Nuget 包安装到 ASP.NET Core 应用程序
```
Package Manager : Install-Package Swashbuckle.AspNetCore.Annotations
CLI : dotnet add package Swashbuckle.AspNetCore.Annotations
```
2. In the `ConfigureServices` method of `Startup.cs`, enable annotations within in the Swagger config block:
2. 在`Startup.cs`中的`ConfigureServices`方法里Swagger配置块中启用`注解`
```csharp
services.AddSwaggerGen(c =>
@ -1242,9 +1243,9 @@ app.UseSwaggerUI(c =>
});
```
### Enrich Operation Metadata ###
### 丰富操作元数据 ###
Once annotations have been enabled, you can enrich the generated Operation metadata by decorating actions with a `SwaggerOperationAttribute`.
启用`注解`后,可以通过使用`SwaggerOperationAttribute`修饰操作来丰富生成的操作元数据。
```csharp
[HttpPost]
@ -1258,9 +1259,9 @@ Once annotations have been enabled, you can enrich the generated Operation metad
public IActionResult Create([FromBody]Product product)
```
### Enrich Response Metadata ###
### 丰富响应元数据 ###
ASP.NET Core provides the `ProducesResponseTypeAttribute` for listing the different responses that can be returned by an action. These attributes can be combined with XML comments, as described [above](#include-descriptions-from-xml-comments), to include human friendly descriptions with each response in the generated Swagger. If you'd prefer to do all of this with a single attribute, and avoid the use of XML comments, you can use `SwaggerResponseAttribute`s instead:
ASP.NETCore 提供了`ProducesResponseTypeAttribute`用于列出操作可以返回的不同响应。这些属性可以与XML注释相结合[如上所述](#include-descriptions-from-xml-comments)以便在生成的招摇中包含每个响应的人性化描述。如果您希望使用单个属性完成所有这些操作并避免使用XML注释则可以改用`SwaggerResponseAttribute`
```csharp
[HttpPost]

Loading…
Cancel
Save