关闭。这个问题需要debugging details .它目前不接受答案。
想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。
2年前关闭。
Improve this question
我试图在 asp.net 核心中同时实现( swagger 和 odata ),但它不起作用。
我无法整合为 odata 提供的路线。
我有以下配置,但收到一般错误。
这是错误
最佳答案
将 OData 添加到我们的 .Net Core 项目时,我们遇到了同样的问题。 this post 上的代码片段中显示的解决方法修复了 Swagger UI 加载时的 API 错误。
据我所知,AspNetCore 的 Swashbuckle 不支持 OData。因此,在上面的链接中添加解决方法代码后,我们的 Swagger UI 可以工作,但没有显示任何 OData 端点。
来自链接的代码片段:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddOData();
// Workaround: https://github.com/OData/WebApi/issues/1177
services.AddMvcCore(options =>
{
foreach (var outputFormatter in options.OutputFormatters.OfType<ODataOutputFormatter>().Where(_ => _.SupportedMediaTypes.Count == 0))
{
outputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/prs.odatatestxx-odata"));
}
foreach (var inputFormatter in options.InputFormatters.OfType<ODataInputFormatter>().Where(_ => _.SupportedMediaTypes.Count == 0))
{
inputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/prs.odatatestxx-odata"));
}
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var builder = new ODataConventionModelBuilder(app.ApplicationServices);
builder.EntitySet<Product>("Products");
app.UseMvc(routebuilder =>
{
routebuilder.MapODataServiceRoute("ODataRoute", "odata", builder.GetEdmModel());
// Workaround: https://github.com/OData/WebApi/issues/1175
routes.EnableDependencyInjection();
});
}
}
关于asp.net-core - 在 ASP.Net Core 中将 swashbuckle swagger 与 odata 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50940593/