I got the solution here 
: 
https://stackoverflow.com/questions/41493130/web-api-how-to-add-a-header-parameter-for-all-api-in-swagger




down voteaccepted

Yes you can do it via inheriting from IOperationFilter

You can find the answer on github here: AddRequiredHeaderParameter 
<https://github.com/domaindrivendev/Swashbuckle/issues/501>

   public class AddRequiredHeaderParameter : IOperationFilter{
    public void Apply(Operation operation, SchemaRegistry schemaRegistry, 
ApiDescription apiDescription)
    {
        if (operation.parameters == null)
            operation.parameters = new List<Parameter>();

        operation.parameters.Add(new Parameter
        {
            name = "X-User-Token",
            @in = "header",
            type = "string",
            required = false
        });
    }}

Then you go to your SwaggerConfig.cs file and add the following in the 
EnableSwagger section:

   c.OperationFilter(() => new AddRequiredHeaderParameter());


Thanks to stackoverflow :)












On Thursday, 28 September 2017 00:22:53 UTC+5:30, Ron wrote:
>
> I assume you use Swashbuckle which is a community project – we’re unable 
> to provide support to it. Please file a ticket with the project directly.
>
>  
>
>  
>
>  
>
> *From: *<[email protected] <javascript:>> on behalf of RAJAN 
> KUMAR <[email protected] <javascript:>>
> *Reply-To: *"[email protected] <javascript:>" <
> [email protected] <javascript:>>
> *Date: *Monday, September 25, 2017 at 06:29
> *To: *Swagger <[email protected] <javascript:>>
> *Subject: *Re: How to apply header in api documentation
>
>  
>
> Please someone reply. I have to implement this.
>
> On Saturday, 23 September 2017 09:15:39 UTC+5:30, RAJAN KUMAR wrote: 
>
> I have used swagger in .net mvc 5 webapi for api documetation. It is 
> working fine for all the verbs like: get, post,put, delete. But I want to 
> pass header(authentication) key in all the apis for security purpose. 
> Please help me how I implement thi 
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Swagger" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to