Changed swagger doc initialization
This commit is contained in:
42
Program.cs
42
Program.cs
@@ -35,25 +35,39 @@ internal static class Program
|
||||
appSettings.PrivateSettings = privateSettings;
|
||||
_configuration.GetSection("AppSettings").Bind(appSettings);
|
||||
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.SwaggerDoc("v1", new OpenApiInfo
|
||||
OpenApiInfo openApiInfo = new()
|
||||
{
|
||||
Version = appSettings?.Settings?.Version,
|
||||
Title = appSettings?.Settings?.Name,
|
||||
Description = appSettings?.Settings?.Description,
|
||||
TermsOfService = new Uri("https://example.com/terms"),
|
||||
Contact = new OpenApiContact
|
||||
Description = appSettings?.Settings?.Description
|
||||
};
|
||||
|
||||
if (!String.IsNullOrEmpty(appSettings?.OpenApiSettings?.TermsOfServiceUrl))
|
||||
{
|
||||
Name = "Example Contact",
|
||||
Url = new Uri("https://example.com/contact")
|
||||
},
|
||||
License = new OpenApiLicense
|
||||
{
|
||||
Name = "Example License",
|
||||
Url = new Uri("https://example.com/license")
|
||||
openApiInfo.TermsOfService = new Uri(appSettings.OpenApiSettings.TermsOfServiceUrl);
|
||||
}
|
||||
});
|
||||
|
||||
if (!String.IsNullOrEmpty(appSettings?.OpenApiSettings?.OpenApiContact?.Name) && !String.IsNullOrEmpty(appSettings?.OpenApiSettings?.OpenApiContact?.Url))
|
||||
{
|
||||
openApiInfo.Contact = new OpenApiContact
|
||||
{
|
||||
Name = appSettings.OpenApiSettings.OpenApiContact.Name,
|
||||
Url = new Uri(appSettings.OpenApiSettings.OpenApiContact.Url)
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(appSettings?.OpenApiSettings?.OpenApiLicense?.Name) && !String.IsNullOrEmpty(appSettings?.OpenApiSettings?.OpenApiLicense?.Url))
|
||||
{
|
||||
openApiInfo.License = new OpenApiLicense
|
||||
{
|
||||
Name = appSettings.OpenApiSettings.OpenApiLicense.Name,
|
||||
Url = new Uri(appSettings.OpenApiSettings.OpenApiLicense.Url)
|
||||
};
|
||||
}
|
||||
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.SwaggerDoc("v1", openApiInfo);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user