mirror of
https://github.com/bitwarden/server.git
synced 2025-02-16 01:51:21 +01:00
camelcase swagger/public apis
This commit is contained in:
parent
0a82f472ef
commit
c02f732056
@ -14,7 +14,6 @@ using Stripe;
|
|||||||
using Bit.Core.Utilities;
|
using Bit.Core.Utilities;
|
||||||
using IdentityModel;
|
using IdentityModel;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Swashbuckle.AspNetCore.Swagger;
|
|
||||||
|
|
||||||
namespace Bit.Api
|
namespace Bit.Api
|
||||||
{
|
{
|
||||||
@ -112,9 +111,16 @@ namespace Bit.Api
|
|||||||
services.AddMvc(config =>
|
services.AddMvc(config =>
|
||||||
{
|
{
|
||||||
config.Conventions.Add(new ApiExplorerGroupConvention());
|
config.Conventions.Add(new ApiExplorerGroupConvention());
|
||||||
|
config.Conventions.Add(new PublicApiControllersModelConvention());
|
||||||
config.Filters.Add(new ExceptionHandlerFilterAttribute());
|
config.Filters.Add(new ExceptionHandlerFilterAttribute());
|
||||||
config.Filters.Add(new ModelStateValidationFilterAttribute());
|
config.Filters.Add(new ModelStateValidationFilterAttribute());
|
||||||
}).AddJsonOptions(o => o.SerializerSettings.ContractResolver = new DefaultContractResolver());
|
}).AddJsonOptions(options =>
|
||||||
|
{
|
||||||
|
if(Configuration["swaggerGen"] != "true")
|
||||||
|
{
|
||||||
|
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
services.AddSwagger(globalSettings);
|
services.AddSwagger(globalSettings);
|
||||||
|
|
||||||
@ -186,8 +192,8 @@ namespace Bit.Api
|
|||||||
|
|
||||||
// Add MVC to the request pipeline.
|
// Add MVC to the request pipeline.
|
||||||
app.UseMvc();
|
app.UseMvc();
|
||||||
|
|
||||||
if(true || globalSettings.SelfHosted)
|
if(globalSettings.SelfHosted)
|
||||||
{
|
{
|
||||||
app.UseSwagger(config =>
|
app.UseSwagger(config =>
|
||||||
{
|
{
|
||||||
|
30
src/Api/Utilities/CamelCaseJsonResultFilterAttribute.cs
Normal file
30
src/Api/Utilities/CamelCaseJsonResultFilterAttribute.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Bit.Api.Utilities
|
||||||
|
{
|
||||||
|
public class CamelCaseJsonResultFilterAttribute : IAsyncResultFilter
|
||||||
|
{
|
||||||
|
private static JsonSerializerSettings _jsonSerializerSettings;
|
||||||
|
|
||||||
|
static CamelCaseJsonResultFilterAttribute()
|
||||||
|
{
|
||||||
|
_jsonSerializerSettings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
|
||||||
|
{
|
||||||
|
if(context.Result is JsonResult jsonResult)
|
||||||
|
{
|
||||||
|
context.Result = new JsonResult(jsonResult.Value, _jsonSerializerSettings);
|
||||||
|
}
|
||||||
|
await next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
src/Api/Utilities/PublicApiControllersModelConvention.cs
Normal file
16
src/Api/Utilities/PublicApiControllersModelConvention.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||||
|
|
||||||
|
namespace Bit.Api.Utilities
|
||||||
|
{
|
||||||
|
public class PublicApiControllersModelConvention : IControllerModelConvention
|
||||||
|
{
|
||||||
|
public void Apply(ControllerModel controller)
|
||||||
|
{
|
||||||
|
var controllerNamespace = controller.ControllerType.Namespace;
|
||||||
|
if(controllerNamespace.Contains(".Public."))
|
||||||
|
{
|
||||||
|
controller.Filters.Add(new CamelCaseJsonResultFilterAttribute());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -29,6 +29,9 @@ namespace Bit.Api.Utilities
|
|||||||
{
|
{
|
||||||
{ "OAuth2 Client Credentials", new[] { "api.organization" } }
|
{ "OAuth2 Client Credentials", new[] { "api.organization" } }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
config.DescribeAllParametersInCamelCase();
|
||||||
|
// config.UseReferencedDefinitionsForEnums();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user