【发布时间】:2017-01-28 20:07:27
【问题描述】:
我在 WebApi 2 应用程序中集成了 swagger。当应用程序具有单个控制器时,它可以正常工作。 当我在应用程序中添加第二个控制器时。我收到以下错误:
发生错误。","ExceptionMessage":"Swagger 2.0 不支持:路径为 'api/Credential' 和方法为 'GET' 的多个操作。请参阅配置设置 - \"ResolveConflictingActions\" 了解潜在的解决方法","ExceptionType":"System.NotSupportedException","StackTrace":" 在 Swashbuckle.Swagger.SwaggerGeneratorOptions.DefaultConflictingActionsResolver(IEnumerable
1 apiDescriptions)\r\n at Swashbuckle.Swagger.SwaggerGenerator.CreatePathItem(IEnumerable1 apiDescriptions, SchemaRegistry schemaRegistry) \r\n 在 Swashbuckle.Swagger.SwaggerGenerator.c__DisplayClass7.b__4(IGrouping2 group)\r\n at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer)\r\n at Swashbuckle.Swagger.SwaggerGenerator.GetSwagger(String rootUrl, String apiVersion)\r\n at Swashbuckle.Application.SwaggerDocsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Cors.CorsMessageHandler.<SendAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.HttpServer.d__0.MoveNext()"} http://localhost:50950/swagger/docs/v1
在第二个控制器中,我添加了以下两种方法。
string Get(string username, string password);
string Get(string credential);
如果我评论其中一种方法。然后就可以正常使用了。
知道怎么解决吗?
【问题讨论】:
-
您可能想customize Swashbuckle。然后由您来调整过滤方法以达到您的需要。
标签: c# asp.net-web-api swagger asp.net-web-api-routing swashbuckle