简体   繁体   English

ASP.NET Web Api Z336FF1E9AA6177EA7A71984FA8C241B9字符串参数错误描述

[英]ASP.NET Web Api Swagger string parameters error - no description

I am using Swagger UI to test my ASP.NET Web Api app.我正在使用 Swagger UI 来测试我的 ASP.NET Web Z72664DC0959F3B0C04891F8C734 应用程序。 I added a class to allow operation parameters我添加了一个 class 以允许运行参数

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在我的 Startup.cs 中,我将此行添加到 ConfigurationServices 方法

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.当我尝试测试 controller 方法之一时,无论我在文本框中输入什么,我的 ApiKey 字符串参数总是显示错误。

在此处输入图像描述

I am not sure about the Schema property but the following worked for me in past (setting the type to string ):我不确定Schema属性,但过去对我有用(将type设置为string ):

operation.Parameters.Add(new Parameter
        {
            name = "ApiKey",
            @in = ParameterLocation.Header,
            required = true,
            type = "string"                
        });

For more details, refer to this post有关更多详细信息,请参阅此帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Asp.Net Web Api - Passing String[] values from swagger to Asp.Net Web API - Asp.Net Web Api - Passing String[] values from swagger to Asp.Net Web API 如何在 Swagger for .Net Core Web Api 中覆盖描述“无参数”? - How to override description 'No parameters' in Swagger for .Net Core Web Api? ASP.NET Web API中的可选查询字符串参数 - Optional query string parameters in ASP.NET Web API Asp.NET Web Api 2路由参数 - Asp.NET Web Api 2 Routing parameters ASP.NET Core Web API - Fetch error undefined /swagger/MyApp API v1/swagger.json - ASP.NET Core Web API - Fetch error undefined /swagger/MyApp API v1/swagger.json 500错误响应 swagger ASP.NET web API 查询 SQL 服务器 - 500 error response swagger ASP.NET web API query SQL Server 使用 ASP.NET Core 6 Swagger UI 时出错 Web API 自定义路由 - Getting error for Swagger UI with an ASP.NET Core 6 Web API with custom routing 将MiniProfiler连接到ASP.NET Core Web API Swagger - Wire up MiniProfiler to ASP.NET Core Web API Swagger 使用 ASP.NET Core Web API 重命名 Swashbuckle 6 (Swagger) 中的模型 - Rename model in Swashbuckle 6 (Swagger) with ASP.NET Core Web API Swagger UI 响应示例 Asp.Net Core Web Api - Swagger UI Response Example Asp.Net Core Web Api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM