Reputation: 3697
I have a WebAPI with an action like "MyActionName"
The route is set to something like Books\Read
.
I have XML Comments on and Swashbuckle config'd to generate the SwaggerUI help page.
The actions are listed correctly in Swagger UI, showing Books\Read
as the name of the operation (for example).
However, codegen based on the Swagger.json results in actions named like "MyActionName", the original name in the C# code.
How can I set the operation name to something else, more like the route (e.g.: BooksRead
)?
Upvotes: 2
Views: 1852
Reputation: 1704
You can create an Operation Filter like the one below:
public class CustomOperationFilter: IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation != null)
{
operation.operationId = "OperationName"; // Give whatever name that is required
}
}
}
Also, in the swagger config file attach the operation filter:
c.OperationFilter<CustomOperationFilter>();
Upvotes: 3