jeudi 23 juin 2016

Removing unwanted route from Web Api HelpPage

I'm in the process of upgrading my Web API to use the 2.2 client libraries using Visual Studio 2013. I've got all my controllers coded with the proper verbs that I want, but I'm having an issue with the auto-generated Help area.

One of my controllers has a single POST method, a couple GET methods and some PUT methods. The issue I'm having is that the auto-generated Help is documenting a route that shouldn't be there.

Here's the definition for the my Post method.

    [HttpPost]
    [ActionName("send")]
    public int Send([FromBody]Document document)

And here are my route maps that I set in the Register method of WebApiConfig:

        config.Routes.MapHttpRoute("Document1",
                                    "document/{action}",
                                    new { controller = "document", jobid = RouteParameter.Optional, action = "POST" });

        config.Routes.MapHttpRoute("Document2",
                                    "document/{jobid}/{action}",
                                    new { controller = "broadcastfax", action = "GET" });

The help area is listing two POST routes for this method.

The thing is there isn't a Send definition that even has jobid as a parameter. Only the GET and PUT methods have a jobid parameter. I thought it was the jobid = RouteParameter.Optional, but if I remove that it adds a bunch of other routes where jobid is passed in the querystring and I don't want that. This is what the documentation is generating. Everything is good except for that single "POST document/{jobid}/send"

API Description

POST document/send  
PUT document/statuslist     
POST document/{jobid}/send  
GET document/{jobid}/status     
PUT document/{jobid}/statuslist     
PUT document/{jobid}/pause  
PUT document/{jobid}/resume     
PUT document/{jobid}/stop   
GET document/{jobid}/report     

Let me know if there is any other information that's needed.

Thank you, Adrian




Aucun commentaire:

Enregistrer un commentaire