How do I annotate my ASP.NET WebAPI actions so that the swagger metadata includes the content-types that my resources support?
Specifically, I want the documentation
What you need to do is this; Swagger spec: you need to add your response-type to the list of response-types for that operation:
"produces": [
"application/json",
"text/json"
],
This can be done with an OperationFilter.
Pseudo Code incoming!!!
public class CustomResponseType : IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.operationId == "myCustomName")
{
operation.produces.Add("application/vnd.blah+json");
}
}
}
the OperationId can be set through the [SwaggerOperation("myCustomName")] annotation.
Then apply the operationsFilter in the swaggerConfig.cs:
c.OperationFilter();
Note:
instead of operation.operationId == "myCustomName"
you could do it for a particular route or anything else basically. ApiDescription gives a LOT of info about context.