domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.25k stars 1.31k forks source link

What I can Do when I can't give actions an explicit HttpMethod when #979

Closed introspection3 closed 3 years ago

introspection3 commented 5 years ago

What I can Do when I can't give actions an explicit HttpMethod when Actions require an explicit HttpMethod binding for Swagger

domaindrivendev commented 5 years ago

I really have no idea what you’re asking here - can you elaborate, a code example would help?

introspection3 commented 5 years ago

Connection id "0HLJ74RLO0OLB", Request id "0HLJ74RLO0OLB:00000002": An unhandled exception was thrown by the application. System.NotSupportedException: Ambiguous HTTP method for action - Permission.Service.Controllers.RoleController.GetRoleConfigValue (Permission.Service). Actions require an explicit HttpMethod binding for Swagger 2.0 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable1 apiDescriptions, ISchemaRegistry schemaRegistry) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.<>c__DisplayClass6_0.<CreatePathItems>b__2(IGrouping2 group) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItems(IEnumerable1 apiDescriptions, ISchemaRegistry schemaRegistry) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath, String[] schemes) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

introspection3 commented 5 years ago

@domaindrivendev System.NotSupportedException: Ambiguous HTTP method for action - Permission.Service.Controllers.RoleController.GetRoleConfigValue (Permission.Service). Actions require an explicit HttpMethod binding for Swagger 2.0

introspection3 commented 5 years ago

only one GetRoleConfigValue method

bbqchickenrobot commented 5 years ago

Why can't I find anything on GetRoleConfigValue method? Anyone resolve this?

domaindrivendev commented 5 years ago

Is there a reason why you’re not decorating the action with the ”HttpGet” attribute? I’m assuming from method name that you want consumers to access via Http GET.

By omitting this, you’re actually exposing it via any Http verb. Is this really what you want?

bbqchickenrobot commented 5 years ago

Well, I don't have (source) control to the action method. It's in a 3rd party CMS authorization/login controller from a Nuget package....

introspection3 commented 5 years ago

@bbqchickenrobot we need a function just like asp.net webpi ,which can auto set HttpGet Delete....

bbqchickenrobot commented 5 years ago

Not sure what you mean.... there is an Action method on a (CMS) controller from a nuget package. I am using this nuget package (cms) along with my own web api. SwashBuckle finds all the methods including the Account.Login() method in the nuget package and then throws this error. Since the controller and its action method reside in a 3rd party nuget package (dll) I cannot decorate the action method with the appropriate HttpVerb attribute.

I think what you are saying is - then it just won't work....

introspection3 commented 5 years ago

the swagger in asp.net mvc (webpi) can work well,and it doesn't need us must add an HttpVerb attribute

introspection3 commented 5 years ago

the swagger in asp.net mvc (webpi) can work well,and it doesn't need us must add an HttpVerb attribute,so we can't migrate our old code to swagger core

bbqchickenrobot commented 5 years ago

ah! Got it... I figured out a band-aid hack.... I'll post the link here

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/899

introspection3 commented 5 years ago

thanks,but when I manual set HttpVerb to all actions, I met another question: our route template is /api/contoller/action/{id}, the swagger core also can't work

introspection3 commented 5 years ago

thanks,but when I manual set HttpVerb to all actions, I met another question: our route template is /api/contoller/action/{id}, the swagger core also can't work