Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Multiple Header Values in Swagger

I know how to add one header value in Swagger, here's the code:

[HttpGet]
[Route("api/{bookID}")]
public async Task<IActionResult> GetBooksByID([FromHeader(Name = "Correlation-ID")]string bookID)
{
   //...
}

But what if I would like to add additional header values, such as "TenantID", "UserID", etc.

How would the syntax look like?

like image 910
superninja Avatar asked Feb 03 '26 16:02

superninja


1 Answers

Just add more parameters, and include the FromHeader attribute on each parameter you want to match:

[HttpGet]
[Route("api/{bookID}")]
public async Task<IActionResult> GetBooksByID(
    string bookID,
    [FromHeader(Name = "Correlation-ID")] string correlationID,
    [FromHeader(Name = "Tenant-ID")] string tenantID,
    [FromHeader(Name = "User-ID")] string userID)
{
   //...
}
like image 89
ugh StackExchange Avatar answered Feb 06 '26 05:02

ugh StackExchange