mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
camelcase swagger/public apis
This commit is contained in:
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" } }
|
||||
});
|
||||
|
||||
config.DescribeAllParametersInCamelCase();
|
||||
// config.UseReferencedDefinitionsForEnums();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user