Refer https://github.com/domaindrivendev/Swashbuckle
Swashbuckle adds swagger documentation to .NET Web API project.
This article explains how to document parameters that are passed in via HTTPHeader.
for this create a custom operation filter:
public class SwaggerHeaderparameters: IOperationFilter
{
public string Description { get; set; }
public string Key { get; set; }
public string Name { get; set; }
public string DefaultValue { get; set; }
public void Apply(SwaggerDocsConfig c)
{
c.ApiKey(Key).Name(Name).Description(Description).In("header");
c.OperationFilter(() => this);
}
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
operation.parameters = operation.parameters ?? new List<Parameter>();
operation.parameters.Add(new Parameter
{
name = Name,
description = Description,
@in = "header",
required = true,
type = "string",
@default = DefaultValue
});
}
}
How to use?
var brandHeader = new SwaggerHeaderparameters
{
Description = "brand",
Key = "brand",
Name = "brand"
};
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "API Documentation");
c.RootUrl(req => req.RequestUri.GetLeftPart(UriPartial.Authority)
+ req.GetRequestContext().VirtualPathRoot.TrimEnd('/'));
brandHeader.Apply(c);
}
).EnableSwaggerUi();
I’m not a nerd!! But I love to learn technology. Have a good collection of tech book soft copies, hardly read. Always bing to solve problem. Now decided to scribble - whatever I binged for my tech work!!!! Disclaimer: This is not my view ;) itz collated views
Wednesday, March 8, 2017
Autofac : resolve dependency per request based on parameter passed on HTTPHeader
Get the HTTP Context base
builder.RegisterHttpRequestMessage(GlobalConfiguration.Configuration);
builder.Register<HttpContextBase>(c =>
{
var context = (HttpContext.Current != null) ?
new HttpContextWrapper(HttpContext.Current) :
c.Resolve<System.Net.Http.HttpRequestMessage>().Properties["MS_HttpContext"] as HttpContextWrapper;
return context;
}).InstancePerRequest();
Resolve the dependency based on the request header value
builder.Register(c =>
{
var route = c.Resolve<HttpContextBase>().Request.Headers.Get("provider");
if (route == null)
{
throw new ArgumentNullException($"A route must be specified");
}
return c.ResolveNamed<IInterfaceName>(route);
}).InstancePerRequest();
Subscribe to:
Posts (Atom)
Featured post
How to connect to Mongo Atlas from Robo 3T
If you use a local instance of MongoDB, you might be a great fan of Robo3T. However, if you are using Mongo Atlas, the Atlas web interface p...
Popular Posts
-
Last week I was working on on-boarding a few SAP Odata APIs to API Management gateway. The APIM tool used by my organization supports JSON ...
-
Our team has used EWS API's Appointment service to book a meeting room. During our testing, its been noted that the room was not block...
-
When comes to API maturity model there are two major models: 1. Richardson Maturity Model 2. Amundsen Maturity Model. To attain RMM...