var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers()
.AddNewtonsoftJson();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll",
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.WriteIndented = true;
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
{
Title = "JSON Selector API",
Version = "v1",
Description = "Transform hierarchical JSON data into tabular CSV format using selector syntax",
Contact = new Microsoft.OpenApi.Models.OpenApiContact
{
Name = "JSON Selector Service"
}
});
var xmlFile = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
if (File.Exists(xmlPath))
{
options.IncludeXmlComments(xmlPath);
}
});
var app = builder.Build();
app.UseCors("AllowAll");
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "JSON Selector API V1");
options.RoutePrefix = "swagger"; });
app.UseRouting();
app.MapControllers();
app.MapGet("/", () => new
{
service = "JSON Selector Service",
version = "1.0",
description = "Transform hierarchical JSON into tabular data",
documentation = new
{
swagger_ui = "/swagger",
api_definition = "/swagger/v1/swagger.json"
},
endpoints = new[]
{
new { path = "/api/query/upload", method = "POST", description = "Simple query with file upload" },
new { path = "/api/query/direct", method = "POST", description = "Query with JSON in request body" },
new { path = "/api/messagequery/upload", method = "POST", description = "Message type-aware query" },
new { path = "/api/messagequery/example/fix", method = "POST", description = "FIX message example query" }
},
selectorExamples = new[]
{
"body.Symbol - Navigate to nested field",
"Parties[PartyRole=11].PartyID - Filter array and get field",
"AllocGrp:sum(AllocQty) - Aggregate array values",
"Parties[0].PartyID - Get first element",
"AllocGrp[*].AllocAccount - Get all values"
}
});
var port = Environment.GetEnvironmentVariable("PORT") ?? "5050";
Console.WriteLine($"JSON Selector Service starting on http://localhost:{port}");
app.Run($"http://localhost:{port}");