Configuring host, scheme and base path with SwashBuckle

Configuring host, scheme and base path with SwashBuckle

Swagger 2.0 supports specifying both host, scheme and base path directly in the swagger document. By default SwashBuckle does not set any values for these properties in the swagger document.

The following snippet will dynamically add the properties taken from the request to the swagger document:

app.UseSwagger(c =>
{
    c.PreSerializeFilters.Add((swaggerDoc, httpReq) => {
        swaggerDoc.Host = httpReq.Host.Value;
        swaggerDoc.Schemes = new List<string>() { httpReq.Scheme };
        swaggerDoc.BasePath = httpReq.PathBase;
    });
});

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s