Files
server/src/Api/Utilities/ServiceCollectionExtensions.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.9 KiB
C#
Raw Normal View History

using Bit.Core.Settings;
2020-01-10 09:36:12 -05:00
using Microsoft.OpenApi.Models;
2019-02-28 14:20:14 -05:00
namespace Bit.Api.Utilities
2019-02-28 14:20:14 -05:00
{
public static class ServiceCollectionExtensions
2019-02-28 14:20:14 -05:00
{
public static void AddSwagger(this IServiceCollection services, GlobalSettings globalSettings)
2019-02-28 14:20:14 -05:00
{
services.AddSwaggerGen(config =>
2019-02-28 14:20:14 -05:00
{
config.SwaggerDoc("public", new OpenApiInfo
2022-08-29 14:53:16 -04:00
{
Title = "Bitwarden Public API",
Version = "latest",
Contact = new OpenApiContact
{
Name = "Bitwarden Support",
Url = new Uri("https://bitwarden.com"),
Email = "support@bitwarden.com"
},
Description = "The Bitwarden public APIs.",
License = new OpenApiLicense
{
Name = "GNU Affero General Public License v3.0",
Url = new Uri("https://github.com/bitwarden/server/blob/master/LICENSE.txt")
}
});
config.SwaggerDoc("internal", new OpenApiInfo { Title = "Bitwarden Internal API", Version = "latest" });
2019-02-28 14:20:14 -05:00
config.AddSecurityDefinition("OAuth2 Client Credentials", new OpenApiSecurityScheme
2019-02-28 14:20:14 -05:00
{
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
2019-02-28 14:20:14 -05:00
{
ClientCredentials = new OpenApiOAuthFlow
2020-01-10 09:36:12 -05:00
{
TokenUrl = new Uri($"{globalSettings.BaseServiceUri.Identity}/connect/token"),
Scopes = new Dictionary<string, string>
{
{ "api.organization", "Organization APIs" },
},
}
},
});
2019-02-28 14:20:14 -05:00
config.AddSecurityRequirement(new OpenApiSecurityRequirement
2019-02-28 14:20:14 -05:00
{
2020-01-10 09:36:12 -05:00
{
new OpenApiSecurityScheme
2020-01-10 09:36:12 -05:00
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "OAuth2 Client Credentials"
},
2020-01-10 09:36:12 -05:00
},
new[] { "api.organization" }
}
});
2019-02-28 20:50:40 -05:00
config.DescribeAllParametersInCamelCase();
// config.UseReferencedDefinitionsForEnums();
2019-03-01 09:34:07 -05:00
var apiFilePath = Path.Combine(AppContext.BaseDirectory, "Api.xml");
config.IncludeXmlComments(apiFilePath, true);
var coreFilePath = Path.Combine(AppContext.BaseDirectory, "Core.xml");
config.IncludeXmlComments(coreFilePath);
});
}
2019-02-28 14:20:14 -05:00
}
}