I have been running swagger in my .net core 3.0 web api project for quite some time with out issues.
I just installed Microsoft.AspNet.OData from the nuGet store. I believe i must have made a mistake in the config file.
OData is working, but my swashbuckle middleware is not.
Code below: NOTE: I know there is other middleware that is sloppy, but it was all working before adding the lines about oData.
I've tried messing with the order of syntaxes with out any luck. I have an idea of what's breaking it, but having trouble describing it.
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" });
});
}
}
}