Swagger 2.0 not supported: multiple path operations

I integrated Swagger into the WebApi 2 application. It works fine when the application has one controller. When I added the second controller in the application. I got the following error:

An error has occurred. "," ExceptionMessage ":" Swagger 2.0 not supported: multiple operations with the path 'api / Credential' and the method 'GET'. See Configuration parameter - \ "ResolveConflictingActions \" for a possible workaround "," ExceptionType ":" System.NotSupportedException "," StackTrace ":" in Swashbuckle.Swagger.SwaggerGeneratorOptions.DefaultConflictingActionsResolver ( 1 apiDescriptions)\r\n at Swashbuckle.Swagger.SwaggerGenerator.CreatePathItem(IEnumerable1 apiRistry in Swashbuckle.Swagger.SwaggerGenerator. <> C__DisplayClass7.b__4 ( 2 group)\r\n at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerableIGrouping 2 group)\r\n at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable. Source in the system. 2 group)\r\n at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func 2 keySelector, Func2 elementSelector, IEqualityComparer 1 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. 1 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);

. .

?

+21
8

AppStart/SwaggerConfig.cs

, Linq

using System.Linq;

c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());

:

GlobalConfiguration.Configuration 
                .EnableSwagger(c =>
                    { ...

: Http methods:

[HttpGet]
[Route("something")]
public List<model> something(){....}

[HttpGet]
[Route("something2")]
public List<model2> something2(){....}

[HttpPost]
[Route("mypost1")]
public List<model> mypost1(){....}

[HttpPost]
[Route("mypost2")]
public List<model2> mypost2(){....}
+30

:

  1. -

  2. URL- , - api/controller/byusername api/controller/bycredentials

+8

.

[Route("api/[controller]")]

[Route("api/[controller]/[action]")]

+1

, .

, " ".

:

[HttpGet]
[SwaggerOperation("GetByUsername")]
[Route("[path]/User")]
public IHttpActionResult GetUser(string username)
{

}

: https://docs.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

0

. [Route("GetByType")] [Route("GetById")]

0

, : .

MVC ( ) , , :

using System.Web.Http;
using System.Web.Mvc;

- , , ( ). RoutePrefix/Route/HttpGet .

namespace MyNameSpace
{
    [System.Web.Http.RoutePrefix("api/Reports")]
    public class ReportsController
    {
        {...constructor...}

        [System.Web.Http.Route("Scans")]
        [System.Web.Http.HttpGet,ResponseType(typeof(List<ReportClass>))]
        public ascyn Task<HttpResponseMessage> GetScans() {...}
0

[Route("ApiAnotherFunction")] [HttpGet].

-1

How about reading documents ? He says that Swashbuckle does not support such method signatures. However, you can create a filter operation to install or use the identifier SwaggerOperationAttributeas specified in the the Q & A .

-6
source

Source: https://habr.com/ru/post/1655236/


All Articles