1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

swagger specs for public api

This commit is contained in:
Kyle Spearrin
2019-02-28 14:20:14 -05:00
parent b6696df055
commit 1c71af47bb
4 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc.ApplicationModels;
namespace Bit.Api.Utilities
{
public class ApiExplorerGroupConvention : IControllerModelConvention
{
public void Apply(ControllerModel controller)
{
var controllerNamespace = controller.ControllerType.Namespace;
controller.ApiExplorer.GroupName = controllerNamespace.Contains(".Public.") ? "public" : "internal";
}
}
}

View File

@ -0,0 +1,35 @@
using System.Collections.Generic;
using Bit.Core;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;
namespace Bit.Api.Utilities
{
public static class ServiceCollectionExtensions
{
public static void AddSwagger(this IServiceCollection services, GlobalSettings globalSettings)
{
services.AddSwaggerGen(config =>
{
config.SwaggerDoc("public", new Info { Title = "Bitwarden Public API", Version = "latest" });
// config.SwaggerDoc("internal", new Info { Title = "Bitwarden Internal API", Version = "latest" });
config.AddSecurityDefinition("OAuth2 Client Credentials", new OAuth2Scheme
{
Type = "oauth2",
Flow = "application",
TokenUrl = $"{globalSettings.BaseServiceUri.Identity}/connect/token",
Scopes = new Dictionary<string, string>
{
{ "api.organization", "Organization APIs" },
},
});
config.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
{ "OAuth2 Client Credentials", new[] { "api.organization" } }
});
});
}
}
}