繁体   English   中英

Swashbuckle Swagger C#WebApi Core 2.0-“产品”为空

[英]Swashbuckle Swagger C# WebApi Core 2.0 - “Produces” is empty

我无法找到错误。 我已经使用.net Core 2和Swagger设置了一些Web API。 添加XML支持(.AddXmlDataContractSerializerFormatters();)之后,swagger在UI中不显示“ Response Content Type”选项。

我还将“ [Produces(” application / json“,” application / xml“)]”“设置为装饰器。 但是生成的json始终会打印:

"consumes":[  

],
"produces":[  

],

所以我不确定在这里我在做什么错。

    [HttpGet("Strom/{plz}")]
    [Produces("application/json", "application/xml")]
    public IActionResult GetStrom(string plz)
    {
        int iplz = 0;

        if (plz.Length != 5 || !int.TryParse(plz, out iplz))
        {
            return BadRequest("Die Postleitzahl ist ungültig.");
        }
        return Ok(GetOrte(plz, 1));
    }

由于我使用的是IActionResult,因此我需要确定地说一下,它将得到什么类型的内容...

[ProducesResponseType(typeof(IEnumerable<Model.Ort.Ort>),200)]

确实做到了。 因此,请确保正确装饰您的api ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM