1
votes

I have just started using this tool to define an API and scaffold out the Web API code in .NET. https://visualstudiogallery.msdn.microsoft.com/cadcb820-762c-4514-9817-884b7558aaa9 I have added a RAML contract which creates a bunch of Controllers and Contracts in the solution. I have also run the function to enable the metadata output. When I go to the /raml page I can see the API spec which is great. However, I get two versions of everything, and I'm not sure what to change to prevent it. For example, in my .raml file, I have a resource called "operators". Using the tools this creates a Controller called "OperatorsController". The baseUri in the .raml definition file is http://localhost:51366/api/ and the MapHttpRoute of the WebApiConfig.Register function is set with a routeTemplate of api/{controller}/{id}. On the /raml page there is an entry for /bookings AND an entry for /api/Bookings. The first one seems to come from the .raml spec and the second from the BookingsController that was created. enter image description here

Any idea how to prevent the duplicates.It''s the first time I've played around with api creation, so I might be missing something obvious here...

1
I don't see any obvious configuration parameter that could control this here: github.com/mulesoft-labs/… So you could try reporting the issue here: github.com/mulesoft-labs/raml-dotnet-tools/issues and see what the maintainers have to say.David Dossot

1 Answers

1
votes

The metadata (dynamically generated raml) captures all your routes. Your WebApi is configured in such a way that you have two different routes for each action/controller. That is reflected in the api console (the picture in your question).

The controllers you created by using the "Add RAML Contract..." command use attribute routing (RoutePrefix and Route attributes in the generated Controller and Actions).

And you also have the default route "api/{controller}/{id}".

Take a look at WebApiConfig.cs and you will find this:

config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

So for example the OpertatorsController / Get gets invoked by this two different routes:

/operators (using the route configured via attributes)

/api/operators (using the "DefaultApi" route

If you remove the "DefaultApi" route you will only have one route for each action and thus the duplication will go away.

Note: the baseUri is not used at all for the metadata