|
1 | | -using GitHub; |
| 1 | +using GitHub; |
2 | 2 | var builder = WebApplication.CreateBuilder(args); |
3 | 3 |
|
4 | 4 | // Add services to the container. |
5 | | -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |
6 | 5 | builder.Services.AddEndpointsApiExplorer(); |
7 | | -builder.Services.AddSwaggerGen(); |
| 6 | +builder.Services.AddOpenApi(); |
8 | 7 |
|
9 | 8 | // ----------- Add this part to register the generated client ----------- |
10 | 9 | // Add Kiota handlers to the dependency injection container |
11 | 10 | builder.Services.AddKiotaHandlers(); |
12 | 11 |
|
13 | 12 | // Register the factory for the GitHub client |
14 | | -builder.Services.AddHttpClient<GitHubClientFactory>((sp, client) => { |
| 13 | +builder.Services.AddHttpClient<GitHubClientFactory>((sp, client) => |
| 14 | +{ |
15 | 15 | // Set the base address and accept header |
16 | 16 | // or other settings on the http client |
17 | 17 | client.BaseAddress = new Uri("https://api.github.com"); |
|
27 | 27 | // Configure the HTTP request pipeline. |
28 | 28 | if (app.Environment.IsDevelopment()) |
29 | 29 | { |
30 | | - app.UseSwagger(); |
31 | | - app.UseSwaggerUI(); |
| 30 | + app.MapOpenApi(); |
| 31 | + app.UseSwaggerUI(o => o.SwaggerEndpoint("/openapi/v1.json", "My API")); |
32 | 32 | } |
33 | 33 |
|
34 | 34 | app.UseHttpsRedirection(); |
|
40 | 40 |
|
41 | 41 | app.MapGet("/weatherforecast", () => |
42 | 42 | { |
43 | | - var forecast = Enumerable.Range(1, 5).Select(index => |
| 43 | + var forecast = Enumerable.Range(1, 5).Select(index => |
44 | 44 | new WeatherForecast |
45 | 45 | ( |
46 | 46 | DateOnly.FromDateTime(DateTime.Now.AddDays(index)), |
|
50 | 50 | .ToArray(); |
51 | 51 | return forecast; |
52 | 52 | }) |
53 | | -.WithName("GetWeatherForecast") |
54 | | -.WithOpenApi(); |
| 53 | +.WithName("GetWeatherForecast"); |
55 | 54 |
|
56 | 55 | // ----------- Add this part to create a new endpoint that uses the generated client ----------- |
57 | 56 |
|
|
60 | 59 | var releases = await client.Repos["dotnet"]["runtime"].Releases["latest"].GetAsync(cancellationToken: cancellationToken); |
61 | 60 | return releases; |
62 | 61 | }) |
63 | | -.WithName("GetDotnetReleases") |
64 | | -.WithOpenApi(); |
| 62 | +.WithName("GetDotnetReleases"); |
65 | 63 |
|
66 | 64 | // ----------- Add this part to create a new endpoint that uses the generated client end ----------- |
67 | 65 |
|
|
0 commit comments