Naming autorun generated method names using Swagger

I played with AutoRest and Swagger . My web API controller has a method GetAllAsync. When I create a client for the service, the client has an interface IResourcesOperations, where Resourcesis the name of the controller.

The interface has a method called GetAllAsyncWithHttpMessagesAsync. Then there is a static class called ResourcesOperationsExtensions, which defines a method called GetAllAsyncand one is called GetAllAsyncAsync. The first one actually starts the second thread from the thread pool ( Task.Factory.StartNew). Does anyone know the reason for this?

I found that I can decorate my action method with an attribute

    [SwaggerOperation("GetResources")]

This will create a client class method GetResourcesWithHttpMessagesAsyncand remove all methods for this web API action from the interface class and extension class.

Now my question is: why are these three methods generated by default?

And is there a way to generate a client using a method named GetResources(i.e. get rid of the WithHttpMessagesAsync suffix) or even GetAllAsync?

+4
source share
2 answers

AutoRest (at least later versions) generates classes with a suffix Extensions. These classes contain extension methods on the proxy interface that allow you to call methods with abbreviated method names, such as the ones you use.

Just add

@using TheNameSpace.OfYour.Client.Extensions

, .

+1

AutoRest <operation-name>Async () , async/await <operation-name>.

, , , Async .

Swashbuckle , Async, Swagger, GetAll. AutoRest , Swagger GetAllAsync.

0

All Articles