我正在使用Swagger和C#创建一个最小的API。我真的不明白我是如何定义头参数的。类似于[SwaggerHeaderParameter(“apikey”,“description.”)]或类似的东西。我到处都找过了,但似乎找不到一个(在我看来)相对简单的解决方案。有人能帮助我吗?
示例代码:
using Swashbuckle.AspNetCore;
app.MapPut("/myapi",
[SwaggerResponse(200, "Success")]
[SwaggerResponse(400, "Bad request")]
async Task<IResult> (HttpRequest request, ILogger<Program> log, CancellationToken ct) =>
{
var result = await request.ReadFromJsonAsync<MyClass[]>(request.HttpContext.RequestAborted);
// [Required] Unique api key for this specific combination of supplierID and Stocknumber.
var apikey = request.Headers["apikey"].ToString();
return Results.Ok(successList);
})
.Accepts<MyClass[]>(false, "application/json")
.Produces<string[]>(StatusCodes.Status200OK, "text/plain")
.Produces<Error>(StatusCodes.Status400BadRequest)
字符串
1条答案
按热度按时间h9a6wy2h1#
你可以从header中尝试binding parameter:
字符串
的数据