带应用服务的Swagger UI,无法执行,因为缺少URL的参数(ZUMO)

xxhby3vn  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(164)

当我试图执行get over my swagger UI时,我发出了这个错误:

{
  "title": "Missing ZUMO-API-VERSION",
  "status": 400,
  "detail": "The value of ZUMO-API-VERSION is not specified 
              in headers or query parameters"
}

这是我意识到的一个问题,因为表的端点总是:
https://XXX.azurewebsites.net/tables/TABLENAME?ZUMO-API-VERSION=3.0.0
URL结束于:?ZUMO-API-VERSION=3.0.0
如果我在没有?ZUMO-API-VERSION=3.0.0的情况下尝试这个,我也会在浏览器中得到缺少zumoapi版本的错误;显然斯威格不是派他们出去的
如何将此参数添加到UI对中间件的每个请求中?
这是配置:

builder.Services.AddSwaggerGen(c => {
    c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo()
    {
        Title = "Skillbased Middleware API Info",
        Version = "v1"
    });
});

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Company API Testing v1");
});


  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:50999",
      "sslPort": 44331
    }
  },
  "profiles": {
    "SkillbasedMiddleware": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:7278;http://localhost:5147",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

工作API调用:

SqlConnection connection = new SqlConnection(connstring);
            connection.Open();
            string query = "SELECT * FROM [User] u LEFT JOIN [PICTURE] p ON u.Id = p.BelongsToUserId WHERE u.Id = '"+userId+"'";
            SqlCommand command = new SqlCommand(query, connection);
            List<UserJoinPicture> results = new List<UserJoinPicture>();
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var userItem = new UserJoinPicture
                    {
                        Id = reader.GetString(reader.GetOrdinal("Id")),
                        Email = reader.GetString(reader.GetOrdinal("Email")),
                        Telephone = reader.GetString(reader.GetOrdinal("Telephone")),
                        Password = reader.GetString(reader.GetOrdinal("Password")),
                        UniqueDeviceId = reader.GetString(reader.GetOrdinal("UniqueDeviceId")),
                        IsCompany = reader.GetBoolean(reader.GetOrdinal("IsCompany")),
                        IsLive = reader.GetBoolean(reader.GetOrdinal("IsLive")),
                        Thumbnail = (byte[])reader.GetValue(reader.GetOrdinal("Thumbnail"))
                    };

                    results.Add(userItem);
                }
            }
            connection.Close();
            return results;

编辑:
我尝试通过添加所需的参数来更改将端点设置到表的控制器:

[Route("tables/companybenefits?ZUMO-API-VERSION=3.0.0")]

    public class CompanyBenefitsController : TableController<CompanyBenefitsItem>
    {
        public CompanyBenefitsController(MigrationDbContext context) : base(new EntityTableRepository<CompanyBenefitsItem>(context))
        {
            
        }
    }
}

但是在部署中间件时,我得到了:

RoutePatternException: The literal section 'companybenefits?ZUMO-API-VERSION=3.0.0' is invalid. Literal sections cannot contain the '?' character.

有什么提示吗?

qij5mzcb

qij5mzcb1#

问题是趾高气扬;我就是这么解决的

public class SwaggerHeader : IOperationFilter
    {
        public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            if (operation.Parameters == null)
                operation.Parameters = new List<OpenApiParameter>();

            operation.Parameters.Add(new OpenApiParameter
            {
                Name = "ZUMO-API-VERSION",
                In = ParameterLocation.Query,
                Required = true // set to false if this is optional
            });
        }
    }

现在,我选择了不需要ID和put的调用,为ZUMO =“3.0.0”,所有的工作。

相关问题