Я довольно долго запускал swagger в моем проекте web api .net core 3.0.
Я только что установил Microsoft.AspNet.OData из магазина nuGet. Я полагаю, что я допустил ошибку в файле конфигурации.
OData работает, но мое промежуточное программное обеспечение не работает.
Код ниже:
ПРИМЕЧАНИЕ: я знаю, что есть другое промежуточное программное обеспечение, которое небрежно, но все это работало до добавления строк о oData.
Я попытался возиться с порядком синтаксиса без какой-либо удачи. Я имею представление о том, что его нарушает, но не могу описать это.
namespace MyProjectPortalVueJs
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddAzureAd(options =>
{
Configuration.Bind("AzureAd", options);
AzureAdOptions.Settings = options;
})
.AddCookie();
// Add framework services.
services.AddMvc()
//UNSURE WHAT THE COMPATIBILITY WAS DOING. CHANGED ON 4-16-2019
//.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
.AddSessionStateTempDataProvider();
services.AddSession();
// Simple example with dependency injection for a data provider.
services.AddSingleton<Providers.IWeatherProvider, Providers.WeatherProviderFake>();
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
});
services.AddOData();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
// Webpack initialization with hot-reload.
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true,
});
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseSession(); // Needs to be before app.UseAuthentication() and app.UseMvc() otherwise you will get an exception "Session has not been configured for this application or request."
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.EnableDependencyInjection();
routes.Expand().Select().Count().OrderBy().Filter();
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
}
}
}