Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Vinod 22 posts 83 karma points
    Jun 18, 2015 @ 07:29
    Vinod
    0

    Umbraco and SwaggerUI/SwashBuckle

    Hi,

    I am trying to use SwashBuckle in my Umbraco MVC Project. MVC Version - 4.0 and Umbraco Version - 7.2.6. I am facing some issues like

    1) The response in /swagger/ui/index.html is taking too much time to load and its listing all apis in umbraco such as "Media", "Content Tree" etc.. instead of listing my api controller actions alone. Have any one experienced this issue?

    2) "Not supported by Swagger 2.0: Multiple operations with path 'api/ContentTree/CreateTreeNode/{id}' and method 'POST'. See the config setting - "ResolveConflictingActions" for a potential workaround. This is the message I am getting.

    Can some one provide a solution for the same. Is there any version dependencies with Umbraco.

    Thanks, Vinod

  • Vinod 22 posts 83 karma points
    Jun 18, 2015 @ 12:48
    Vinod
    101

    Hi,

    Found the solution for the same.

    Step 1: Create WebAPI project and install Umbraco.

    Step 2: Follow the procedure mentioned in http://www.strathweb.com/2014/04/opt-opt-asp-net-web-api-help-page/ and create the classes( create IncludeInApiExplorer, IncludeInApiExplorerAttribute, ApiController)

    Step 3: Install SwashBuckle

    Step 4: And add the "httpConfiguration.Services.Replace(typeof(IApiExplorer), new OptInApiExplorer(config));" in the Swagger.config file

    Step 5: Navigate to localhost:port/swagger/ui/index

    Thanks Vinod

  • lucuma 261 posts 563 karma points
    Oct 29, 2015 @ 17:09
    lucuma
    0

    Thank you this helped me a lot. Out of curiosity do you know how to remove the option {id} that is appearing in all the methods for my api controller?

    ie

    POST /umbraco/Api/Stuff/MyRequests/{id}

    Everyone of the actions has that id in the swagger docs which I assume is defined in some default route. The action MyRequests doesn't accept any parameters so I'd like to see about removing it.

  • lucuma 261 posts 563 karma points
    Oct 30, 2015 @ 15:08
    lucuma
    0

    I ended up just decorating each method with the route attribute to remove it.

     [Route("MyRequests")]
     public ActionResult MyRequests()
    
  • Tiago 2 posts 22 karma points
    Apr 17, 2017 @ 15:45
    Tiago
    0

    Hi,

    In my case, that didn't solve this issue. The {id} still appears at the end of each method in my UmbracoApiController. For you, the solution was only set the [Route("")] attribute with the same name as the method?

    Can you help me? Thanks in advance

  • Chris Randle 85 posts 199 karma points c-trib
    Apr 17, 2017 @ 17:29
    Chris Randle
    0

    If you're just trying to get rid of the ID parameter, well couldn't you just ignore it? It's not exactly mandatory. It's easier to ignore than to remove I think.

  • Chris Randle 85 posts 199 karma points c-trib
    Feb 21, 2017 @ 16:28
    Chris Randle
    0

    So in Umbraco 7.5.3, I installed Swashbuckle. There is no Swagger.config file but there is a SwaggerConfig.cs but the signature is different.

    I implemented the OptInApiExplorer code as per the example, and because there is no Register signature that is taking HttpConfiguration, I tried the following but it doesn't work.

                HttpConfiguration config = new HttpConfiguration();
            config.Services.Replace(typeof(IApiExplorer), new OptInApiExplorer(config));
    

    I tried this in the SwaggerConfig.cs before and after the initialisation code bit:

    var thisAssembly = typeof(SwaggerConfig).Assembly;
    
            GlobalConfiguration.Configuration 
                .EnableSwagger(c => ...).EnableSwaggerUI(c => ...);
    

    but nothing works. Any ideas?

  • Chris Randle 85 posts 199 karma points c-trib
    Feb 21, 2017 @ 16:30
    Chris Randle
    0

    Fixed it by entering

    GlobalConfiguration.Configuration.Services.Replace(typeof(IApiExplorer), new OptInApiExplorer(GlobalConfiguration.Configuration));
    

    after the initialisation block.

  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Mar 16, 2018 @ 08:21
    Biagio Paruolo
    0

    How to remove the {id} wrong parameter?

    Here is another info: https://stackoverflow.com/questions/40308111/c-sharp-attribute-appsettings

  • vijaya shivgand 23 posts 122 karma points
    Apr 26, 2018 @ 20:15
    vijaya shivgand
    0

    I wrote following and it worked for me

    httpConfiguration .EnableSwagger((c) => { c.SingleApiVersion("v1", "A title for your API")); c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); });

  • Jakob Kristensen 36 posts 169 karma points
    May 31, 2018 @ 07:31
    Jakob Kristensen
    0

    Anyone found a solution to this, its confusing the hell out of our frontenders with the extra ID but overall it helps a ton having this functionality :) Plus its making errors when we try to autogenerate a client from this, is there anyway to overwrite the route config from umbraco and just use ones own? :)

  • Gleb Anisimov 1 post 71 karma points
    Jun 25, 2018 @ 09:45
    Gleb Anisimov
    0

    In case somebody is still wandering "how to remove Id".
    1) Add Route ( namespace : System.Web.Http, NOT System.Web.Mvc )

    [Route("ProductSave")]
    public bool ProductSave([FromBody]ProductEditModel saveModel)
    

    2) Check that you have MapHttpAttributeRoutes() in App_Start

    GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
    

    Works in my case.

Please Sign in or register to post replies

Write your reply to:

Draft