Moh*_*oly 6 asp.net-web-api swagger swashbuckle asp.net-core
我正在使用 asp.netcore 3.1 和 openapi 3.0.1
我已使用以下代码向我的 api 添加了授权:
services.AddSwaggerGen(setupAction =>
{
setupAction.SwaggerDoc("APIs_Documentation", new OpenApiInfo
{
Title = "Project APIs",
Version = "1"
});
setupAction.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme()
{
Type = SecuritySchemeType.Http,
Scheme = "bearer",
Description = "Enter token here",
Name = "Authorization",
@In = ParameterLocation.Header,
});
setupAction.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "oauth2",
}
},new List<string>()}
});
});
Run Code Online (Sandbox Code Playgroud)
有没有办法为下图中弹出授权对话框的值字段设置默认值?
小智 0
如果您正在寻找添加默认标头的方法,您可以从 C# 执行此操作,如下所示:
app.UseSwagger()
.UseSwaggerUI(c =>
{
c.Interceptors = new InterceptorFunctions
{
RequestInterceptorFunction = "function (req) { req.headers['MyCustomHeader'] = 'CustomValue'; return req; }"
};
}
Run Code Online (Sandbox Code Playgroud)
);
或者想将其添加到 Swagger UI:相关问题
| 归档时间: |
|
| 查看次数: |
3362 次 |
| 最近记录: |