AP.NET/Program.cs

66 lines
2.5 KiB
C#
Raw Normal View History

using Microsoft.OpenApi.Models;
using KristofferStrube.ActivityStreams.JsonConverters;
using System.Reflection;
using System.Text.Json.Serialization;
using KristofferStrube.ActivityStreams;
using KristofferStrube.ActivityStreams.JsonLD;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
//options.JsonSerializerOptions.Converters.Add(new CollectionOrLinkConverter());
//options.JsonSerializerOptions.Converters.Add(new CollectionPageOrLinkConverter());
//options.JsonSerializerOptions.Converters.Add(new DateTimeBooleanObjectOrLinkConverter());
//options.JsonSerializerOptions.Converters.Add(new EndpointsOrLinkConverter());
//options.JsonSerializerOptions.Converters.Add(new ImageOrLinkConverter());
//options.JsonSerializerOptions.Converters.Add(new LinkConverter());
//options.JsonSerializerOptions.Converters.Add(new ObjectConverter());
//options.JsonSerializerOptions.Converters.Add(new ObjectOrLinkConverter());
//options.JsonSerializerOptions.Converters.Add(new TermDefinitionConverter());
//options.JsonSerializerOptions.Converters.Add(new XMLTimeSpanConverter());
//options.JsonSerializerOptions.Converters.Add(new OneOrMultipleConverter<string>());
//options.JsonSerializerOptions.Converters.Add(new OneOrMultipleConverter<IObjectOrLink>());
//options.JsonSerializerOptions.Converters.Add(new OneOrMultipleConverter<ITermDefinition>());
//options.JsonSerializerOptions.Converters.Add(new OneOrMultipleConverter<IDictionary<string, string>>());
});
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v0.0.1",
Title = "ActivityPub API",
Description = "An ASP.NET Core Web API for ActivityPub C2S and S2S Protocols"
});
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
options.RoutePrefix = string.Empty;
}); ;
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();