Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass headers using ServiceStack's Swagger UI

I am trying to add headers in our SS service using the APIMember attribute with ParameterType = "header".

Everything seems to be working except the header which is not getting added to the RequestContext. Hoping it supports headers. If it does, how and is there a way to not allow that header property in the Get query or path?

What am I doing wrong?

namespace Test
{
    [Api(Description = "MyTest")]
    [Route("/Test", Verbs="GET")]
    public class MyRequest
    {
        [ApiMember(
            Name = "SolutionName", 
            ParameterType = "query", 
            Description = "Test", 
            DataType = "string", 
            IsRequired = true)]
        public string SolutionName { get; set; }

        [ApiMember(
            Name = "Token", 
            ParameterType = "header", 
            DataType = "string", 
            IsRequired = true)]
        public string Token { get; set; }

    }

}

Help appreciated!

Thanks, Nac

like image 471
Tech Xie Avatar asked Oct 04 '22 07:10

Tech Xie


1 Answers

So, looking here it appears that header parameters are not supported by default and you need to set supportHeaderParams = true. The NuGet install of ServiceStack.Api.Swagger has supportHeaderParams = false. You can change this variable in the index.html file that is located in the /swagger-ui folder.

like image 91
paaschpa Avatar answered Oct 18 '22 19:10

paaschpa