connect to csharp
This commit is contained in:
parent
0261b94820
commit
b88ff96b32
16 changed files with 336 additions and 63 deletions
51
StitchImg/Program.cs
Executable file
51
StitchImg/Program.cs
Executable file
|
|
@ -0,0 +1,51 @@
|
|||
using Microsoft.OpenApi.Models;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddControllers()
|
||||
.AddNewtonsoftJson(options =>
|
||||
{
|
||||
options.SerializerSettings.ContractResolver = new DefaultContractResolver
|
||||
{
|
||||
NamingStrategy = new SnakeCaseNamingStrategy()
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SchemaFilter<SnakeCaseSchemaFilter>();
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.MapControllers();
|
||||
app.Run();
|
||||
|
||||
public class SnakeCaseSchemaFilter : ISchemaFilter
|
||||
{
|
||||
private readonly SnakeCaseNamingStrategy _namingStrategy = new();
|
||||
|
||||
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
|
||||
{
|
||||
if (schema.Properties == null) return;
|
||||
|
||||
var newProps = new Dictionary<string, OpenApiSchema>();
|
||||
foreach (var prop in schema.Properties)
|
||||
{
|
||||
var snakeName = _namingStrategy.GetPropertyName(prop.Key, false);
|
||||
newProps[snakeName] = prop.Value;
|
||||
}
|
||||
|
||||
schema.Properties = newProps;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue