[英]Swashbuckle Swagger C# WebApi Core 2.0 - “Produces” is empty
I'm having trouble finding the mistake. 我无法找到错误。 I've set up a little Web API with .net Core 2 and Swagger.
我已经使用.net Core 2和Swagger设置了一些Web API。 After I added XML support (.AddXmlDataContractSerializerFormatters();), swagger doesn't show "Response Content Type" option in the UI.
添加XML支持(.AddXmlDataContractSerializerFormatters();)之后,swagger在UI中不显示“ Response Content Type”选项。
I also set "[Produces("application/json", "application/xml")]" as decorator. 我还将“ [Produces(” application / json“,” application / xml“)]”“设置为装饰器。 And yet the generated json always prints:
但是生成的json始终会打印:
"consumes":[
],
"produces":[
],
So I'm not sure what i'm doing wrong here. 所以我不确定在这里我在做什么错。
[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));
}
Since I'm using IActionResult, I need to make sure to say, what type of content it's getting... 由于我使用的是IActionResult,因此我需要确定地说一下,它将得到什么类型的内容...
[ProducesResponseType(typeof(IEnumerable<Model.Ort.Ort>),200)]
That actually made it. 确实做到了。 So make sure to decorate your api correctly...
因此,请确保正确装饰您的api ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.