c# - ASP.NET Web Api Swagger string parameters error - no description
问题描述
I am using Swagger UI to test my ASP.NET Web Api app. I added a class to allow operation parameters
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (operation.Parameters == null)
operation.Parameters = new List<OpenApiParameter>();
operation.Parameters.Add(new OpenApiParameter
{
Name = "ApiKey",
In = ParameterLocation.Header,
Required = true,
Schema = new OpenApiSchema
{
Type = "String"
}
});
operation.Parameters.Add(new OpenApiParameter
{
Name = "Authentication",
In = ParameterLocation.Header,
Required = false,
Schema = new OpenApiSchema
{
Type = "String"
}
});
}
In my Startup.cs, I added this line to the ConfigurationServices method
c.OperationFilter<CustomHeaderSwaggerAttribute>();
When I try and test one of the controller methods, my ApiKey string parameter always show an error no matter what I put in the textbox.
解决方案
我不确定该Schema
属性,但过去对我有用(设置type
为string
):
operation.Parameters.Add(new Parameter
{
name = "ApiKey",
@in = ParameterLocation.Header,
required = true,
type = "string"
});
有关更多详细信息,请参阅此帖子
推荐阅读
- javascript - 检查 Discord 消息中的特定单词
- javascript - 如何在javascript中从控制台获取多个输入?
- css - 如何以角度动态加载特定于组件的css样式
- postgresql - 如何停止 Postgrex 进程及其 TypeServer 进程?
- python - 从 Web 读取 UTF-8 并存储在 json 中
- python - 如何制作这个列表的元组 - Python
- visual-studio-code - VScode 强制我的扩展安装在 WSL 上
- android - Android:意外的活动生命周期
- c# - 如何根据多个属性通知用户进行自定义验证
- javascript - 将 Cinema 4D 动画导入到 three.js(通过 WEBGL 渲染器)