Reputation: 515
Authorization field is showing for HTTP POST
request but it's not showing for GET
request to add a token for authentication of Web API.
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "Mach.CharterPad.API");
c.OperationFilter<SwaggerAuthorizationFilter>();
c.RootUrl(req => $"{req.RequestUri.GetLeftPart(UriPartial.Authority)}{req.GetConfiguration().VirtualPathRoot.TrimEnd('/')}{appvirtualpath}/api");
}).EnableSwaggerUi();
public class SwaggerAuthorizationFilter : IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.parameters != null)
{
operation.parameters.Add(new Parameter
{
name = "Authorization",
@in = "header",
description = "access token",
required = false,
type = "string"
});
}
}
}
Upvotes: 0
Views: 1133
Reputation: 515
I have updated API parameters and it's working fine.
[Route("")]
public IHttpActionResult Get([FromUri] Paging paging)
{
var result = TripManager.Get(paging.Index, paging.Size);
return Ok(result != null ? new ApiResponse(true, "Results found", result) : new ApiResponse(false, "No record found", result));
}
Upvotes: 1