简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM