|
1 |
| -var builder = WebApplication.CreateBuilder(args); |
| 1 | +using Microsoft.OpenApi.Models; |
| 2 | +using Swashbuckle.AspNetCore.SwaggerGen; |
2 | 3 |
|
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); |
5 | 5 | builder.Services.AddEndpointsApiExplorer();
|
6 |
| -builder.Services.AddSwaggerGen(); |
7 |
| - |
8 |
| -var app = builder.Build(); |
9 | 6 |
|
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++) |
12 | 10 | {
|
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 | + }); |
15 | 18 | }
|
16 | 19 |
|
| 20 | +var app = builder.Build(); |
| 21 | +app.UseSwagger(); |
| 22 | +app.UseSwaggerUI(); |
17 | 23 | 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(); |
39 | 25 | app.Run();
|
40 | 26 |
|
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 |
42 | 34 | {
|
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) { } |
44 | 38 | }
|
0 commit comments