Right now I am using:
AutoRest.exe -Input %jsonUrl% -Namespace %projectName%ClientAutoGen -OutputDirectory %projectName%Client
To generate my ASP.NET Core Rest Client.
The annoyance is that AutoRest creates a single file/class for all of the controllers in that API. I've used pre-ASP.NET Core auto-generators that would split out each controller into their own file/class, is there any way to force this behavior in AutoRest?
I've also asked this question here:
http://stackoverflow.com/q/39903534/550975
AutoRest takes a swagger spec as an input. The magic that happens in your webapi to produce the swagger spec is out of context.
However, we have followed a format of Noun_Verb in the operationID; where the _Noun_ represents the logical artifact/component on which the operation is performed and the _Verb_ represents the action performed on that logical artifact/component.
To give an example:
"operationId": "StorageAccounts_create", will translate to an operation group named StorageAccounts being created in the client. This operation group will have the create method in it. For example: client.StorageAccounts.Create().
If the value of the operationId is not split by 1 underscore then the entire value is considered as the method name and it will be a method on the client
"operationId": "CreateStorageAccount", translates to client.CreateStorageAccount().
Note: currently we do not support multiple underscores
@amarzavery swagger-codegen and swagger-ui both group based on tags. why was this not done in autorest?
~I think its poor design to be forced to get the whole interface for a service when with other generators you can simply get the group you need.~ tried the underscore operationId and it does give you multiple files
I am sorry if I was not clear. Every operation group will have it's own class.
Let me give you a concrete example.
This should give a better idea about the patterns we follow in our swagger specs and the kind of code AutoRest generates in a strongly typed and a dynamically typed language.
If you're using Swashbuckle then you can use this operation filter:
public class OperationFilter : IOperationFilter
{
public void Apply(Operation operation, OperationFilterContext context)
{
if (context.ApiDescription.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
{
operation.OperationId =
$"{controllerActionDescriptor.ControllerName}_{controllerActionDescriptor.ActionName.Replace("Async", string.Empty)}";
}
}
}
Most helpful comment
If you're using Swashbuckle then you can use this operation filter: