I have followed this:
Web Api How to add a Header parameter for all API in Swagger
and this:
How to send custom headers with requests in Swagger UI?
However, none of these IParameter, Parameter or NonBodyParameters work on ASP .NET CORE 3.1.
I would like to add a header on my swagger which takes a tenant-ID that is preferably taken from the logged user.
I have also went through this as well:
https://github.com/domaindrivendev/Swashbuckle.AspNetCore
Can anyone point me to the right direction?
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.JsonPatch.Operations;
using Microsoft.OpenApi.Models;
namespace Intent2.Auth.Utils
{
public class AddRequiredHeaderParameter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (operation.Parameters == null)
operation.Parameters = new List<IParameter>();
operation.Parameters.Add(new NonBodyParameter
{
Name = "X-User-Token",
In = "header",
Type = "string",
Required = false
});
}
}
}
services.AddSwaggerGen(options =>
{
options.OperationFilter<AddRequiredHeaderParameter>();
}