Restrict accepted Media Types in ASP.NET Core Controller action

前端 未结 1 1900
野性不改
野性不改 2021-01-18 03:37

I have an ASP.NET Core Service that produces both JSON and XML responses. However, I like to restrict the accepted Media Type for only one action, so Swagger can only list a

相关标签:
1条回答
  • 2021-01-18 04:23

    You can use the annotations Consumes and Produces. These are also picked up by Swashbuckle. Like so:

    [HttpGet]
    [Consumes("application/xml")]
    [Produces("application/xml")]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }
    
    0 讨论(0)
提交回复
热议问题