|
1 | 1 | using iGotify_Notification_Assist.Services; |
| 2 | +using Microsoft.AspNetCore.Http.Json; |
| 3 | +using Microsoft.AspNetCore.Identity; |
2 | 4 | using Microsoft.OpenApi.Models; |
| 5 | +using Scalar.AspNetCore; |
| 6 | +using Environments = iGotify_Notification_Assist.Services.Environments; |
3 | 7 |
|
4 | 8 | var builder = WebApplication.CreateBuilder(args); |
5 | 9 |
|
6 | 10 | // Add services to the container. |
7 | 11 | builder.Services.AddCors(); |
8 | 12 |
|
9 | | -builder.Services.AddControllers(opt => { opt.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true; }) |
| 13 | +builder.Services.AddControllers(opt => |
| 14 | + { |
| 15 | + opt.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true; |
| 16 | + }) |
10 | 17 | .AddJsonOptions(opt => |
11 | 18 | { |
12 | 19 | opt.JsonSerializerOptions.PropertyNamingPolicy = null; |
13 | 20 | opt.JsonSerializerOptions.PropertyNameCaseInsensitive = true; |
14 | 21 | }); |
15 | | - |
16 | | -builder.Services.AddSingleton(builder.Configuration); |
17 | | -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |
18 | | -builder.Services.AddEndpointsApiExplorer(); |
19 | | -builder.Services.AddSwaggerGen(c => |
| 22 | +builder.Services.Configure<JsonOptions>(options => |
20 | 23 | { |
21 | | - c.SwaggerDoc("v1", new OpenApiInfo { Title = "iGotify Notification Assist API", Version = "v1" }); |
| 24 | + options.SerializerOptions.PropertyNameCaseInsensitive = true; // Enable case-insensitivity |
| 25 | + options.SerializerOptions.PropertyNamingPolicy = null; // Preserve exact casing |
22 | 26 | }); |
23 | 27 |
|
| 28 | +builder.Services.AddSingleton(builder.Configuration); |
| 29 | +builder.Services.AddOpenApi(); |
24 | 30 | builder.Services.AddTransient<IStartupFilter, StartUpBuilder>(); |
25 | 31 |
|
26 | 32 | var app = builder.Build(); |
|
37 | 43 |
|
38 | 44 | app.UseRouting(); |
39 | 45 |
|
40 | | -// Enable middleware to serve generated Swagger as a JSON endpoint. |
41 | | -app.UseSwagger(c => { c.RouteTemplate = "/swagger/{documentName}/swagger.json"; }); |
42 | | - |
43 | | -// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), |
44 | | -// specifying the Swagger JSON endpoint. |
45 | | -app.UseSwaggerUI(c => |
| 46 | +if (Environments.enableScalarUi) |
46 | 47 | { |
47 | | - c.SwaggerEndpoint("/api/swagger/v1/swagger.json", "iGotify Notification Assist API"); |
48 | | - c.RoutePrefix = string.Empty; |
49 | | - c.DefaultModelsExpandDepth(-1); |
50 | | -}); |
| 48 | + app.MapOpenApi(); |
| 49 | + app.MapScalarApiReference(options => |
| 50 | + { |
| 51 | + options.WithTitle("iGotify Notification Assist API") |
| 52 | + .WithModels(false) |
| 53 | + .WithLayout(ScalarLayout.Classic) |
| 54 | + .WithTheme(ScalarTheme.Moon) |
| 55 | + .WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient); |
| 56 | + }); |
| 57 | +} |
51 | 58 |
|
52 | 59 | //app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); |
53 | 60 |
|
|
0 commit comments