Skip to content

Commit 438158a

Browse files
author
Remco Lam
committed
fixed example
1 parent 13f9bea commit 438158a

File tree

1 file changed

+27
-33
lines changed
  • test/WebSites/MinimalAppWithConstructorDelay

1 file changed

+27
-33
lines changed
Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
1-
var builder = WebApplication.CreateBuilder(args);
1+
using Microsoft.OpenApi.Models;
2+
using Swashbuckle.AspNetCore.SwaggerGen;
23

3-
// Add services to the container.
4-
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
4+
var builder = WebApplication.CreateBuilder(args);
55
builder.Services.AddEndpointsApiExplorer();
6-
builder.Services.AddSwaggerGen();
7-
8-
var app = builder.Build();
96

10-
// Configure the HTTP request pipeline.
11-
if (app.Environment.IsDevelopment())
7+
var documentFilter = new DocumentFilter();
8+
var operationFilter = new OperationFilter();
9+
for (int i = 0; i < 1; i++)
1210
{
13-
app.UseSwagger();
14-
app.UseSwaggerUI();
11+
var x = i;
12+
builder.Services.AddSwaggerGen(c =>
13+
{
14+
c.SwaggerDoc($"title-{x}", new OpenApiInfo { Title = $"SMARTR ({i})", Version = "1.0" });
15+
c.AddDocumentFilterInstance(documentFilter);
16+
c.AddOperationFilterInstance(operationFilter);
17+
});
1518
}
1619

20+
var app = builder.Build();
21+
app.UseSwagger();
22+
app.UseSwaggerUI();
1723
app.UseHttpsRedirection();
18-
19-
var summaries = new[]
20-
{
21-
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
22-
};
23-
24-
app.MapGet("/weatherforecast", () =>
25-
{
26-
var forecast = Enumerable.Range(1, 5).Select(index =>
27-
new WeatherForecast
28-
(
29-
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
30-
Random.Shared.Next(-20, 55),
31-
summaries[Random.Shared.Next(summaries.Length)]
32-
))
33-
.ToArray();
34-
return forecast;
35-
})
36-
.WithName("GetWeatherForecast")
37-
.WithOpenApi();
38-
24+
app.MapGet("/weatherforecast", () => 0).WithName("GetWeatherForecast").WithOpenApi();
3925
app.Run();
4026

41-
internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
27+
public class DocumentFilter : IDocumentFilter
28+
{
29+
static int count;
30+
public DocumentFilter() { Thread.Sleep(20); Console.WriteLine("DocumentFilter " + count++); }
31+
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { }
32+
}
33+
public class OperationFilter : IOperationFilter
4234
{
43-
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
35+
static int count;
36+
public OperationFilter() { Thread.Sleep(20); Console.WriteLine("OperationFilter " + count++); }
37+
public void Apply(OpenApiOperation operation, OperationFilterContext context) { }
4438
}

0 commit comments

Comments
 (0)