Skip to content

Commit

Permalink
Use built-in OpenAPI support in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
captainsafia committed Apr 25, 2024
1 parent 4efd1f2 commit f35b58c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
MicrosoftNETCoreAppRuntimeVersion=$(MicrosoftNETCoreAppRuntimeVersion);
SystemNetHttpJsonVersion=$(SystemNetHttpJsonVersion);
MicrosoftGraphVersion=$(MicrosoftGraphVersion);
SwashbuckleAspNetCoreVersion=$(SwashbuckleAspNetCoreVersion);
</GeneratedContentProperties>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="${MicrosoftAspNetCoreAuthenticationJwtBearerVersion}" Condition="'$(OrganizationalAuth)' == 'True' OR '$(IndividualB2CAuth)' == 'True'" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="${MicrosoftAspNetCoreAuthenticationNegotiateVersion}" Condition="'$(WindowsAuth)' == 'True'" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="${MicrosoftAspNetCoreAuthenticationOpenIdConnectVersion}" Condition="'$(OrganizationalAuth)' == 'True' OR '$(IndividualB2CAuth)' == 'True'" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="${MicrosoftAspNetCoreOpenApiVersion}" Condition="'$(EnableOpenAPI)' == 'True' AND '$(UsingMinimalAPIs)' == 'True'" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="${MicrosoftAspNetCoreOpenApiVersion}" Condition="'$(EnableOpenAPI)' == 'True' />
<PackageReference Include="Microsoft.Identity.Web" Version="${MicrosoftIdentityWebVersion}" Condition="'$(OrganizationalAuth)' == 'True' OR '$(IndividualB2CAuth)' == 'True'"/>
<PackageReference Include="Microsoft.Identity.Web.GraphServiceClient" Version="${MicrosoftIdentityWebGraphServiceClientVersion}" Condition=" '$(GenerateGraph)' == 'True' " />
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="${MicrosoftIdentityWebDownstreamApiVersion}" Condition="'$(OrganizationalAuth)' == 'True' OR '$(IndividualB2CAuth)' == 'True'"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="${SwashbuckleAspNetCoreVersion}" Condition="'$(EnableOpenAPI)' == 'True'" />
</ItemGroup>

<!--#endif -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ public static void Main(string[] args)
builder.Services.AddControllers();
#endif
#if (EnableOpenAPI)
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Learn more about configuring OpenAPI at https://aka.ms/aspnetcore/openapi
builder.Services.AddOpenApi();
#endif
#if (WindowsAuth)

Expand All @@ -81,8 +80,7 @@ public static void Main(string[] args)
#if (EnableOpenAPI)
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.MapOpenApi();
}
#endif
#if (HasHttpsProfile)
Expand Down Expand Up @@ -165,12 +163,10 @@ public static void Main(string[] args)
#if (EnableOpenAPI && !NoAuth)
})
.WithName("GetWeatherForecast")
.WithOpenApi()
.RequireAuthorization();
#elif (EnableOpenAPI && NoAuth)
})
.WithName("GetWeatherForecast")
.WithOpenApi();
.WithName("GetWeatherForecast");
#elif (!EnableOpenAPI && !NoAuth)
})
.RequireAuthorization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@
builder.Services.AddAuthorization();

#if (EnableOpenAPI)
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Learn more about configuring OpenAPI at https://aka.ms/aspnetcore/openapi
builder.Services.AddOpenApi();
#endif

var app = builder.Build();
Expand All @@ -53,8 +52,7 @@
#if (EnableOpenAPI)
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.MapOpenApi();
}
#endif
#if (HasHttpsProfile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

// Add services to the container.
#if (EnableOpenAPI)
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Learn more about configuring OpenAPI at https://aka.ms/aspnetcore/openapi
builder.Services.AddOpenApi();
#endif
#if (WindowsAuth)
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
Expand All @@ -27,8 +26,7 @@
#if (EnableOpenAPI)
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.MapOpenApi();
}
#endif
#if (HasHttpsProfile)
Expand All @@ -54,8 +52,7 @@
return forecast;
#if (EnableOpenAPI)
})
.WithName("GetWeatherForecast")
.WithOpenApi();
.WithName("GetWeatherForecast");
#else
});
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@

builder.Services.AddControllers();
#if (EnableOpenAPI)
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Learn more about configuring OpenAPI at https://aka.ms/aspnetcore/openapi
builder.Services.AddOpenApi();
#endif
#if (WindowsAuth)

Expand All @@ -68,8 +67,7 @@
#if (EnableOpenAPI)
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.MapOpenApi();
}
#endif
#if (HasHttpsProfile)
Expand Down

0 comments on commit f35b58c

Please sign in to comment.