in src/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/Document.cs [78:112]
public IDocument AddServer(IHttpRequestDataObject req, string routePrefix, IOpenApiConfigurationOptions options = null)
{
this._req = req;
var prefix = string.IsNullOrWhiteSpace(routePrefix) ? string.Empty : $"/{routePrefix}";
var baseUrl = $"{HttpRequestDataObjectExtensions.GetScheme(this._req, options)}://{this._req.Host}{prefix}";
var server = new OpenApiServer { Url = baseUrl };
if (GenericExtensions.IsNullOrDefault(options))
{
this.OpenApiDocument.Servers = new List<OpenApiServer>() { server };
return this;
}
// Filters out the existing base URLs that are the same as the current host URL.
var servers = options.Servers
.Where(p => p.Url.TrimEnd('/') != baseUrl.TrimEnd('/'))
.ToList();
if (!servers.Any())
{
servers.Insert(0, server);
}
if (options.IncludeRequestingHostName
&& !servers.Any(p => p.Url.TrimEnd('/') == baseUrl.TrimEnd('/')))
{
servers.Insert(0, server);
}
this.OpenApiDocument.Servers = servers;
return this;
}