Reputation: 31
I'm having trouble finding the mistake. I've set up a little Web API with .net Core 2 and Swagger. After I added XML support (.AddXmlDataContractSerializerFormatters();), swagger doesn't show "Response Content Type" option in the UI.
I also set "[Produces("application/json", "application/xml")]" as decorator. And yet the generated json always prints:
"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));
}
Upvotes: 1
Views: 1297
Reputation: 31
Since I'm using IActionResult, I need to make sure to say, what type of content it's getting...
[ProducesResponseType(typeof(IEnumerable<Model.Ort.Ort>),200)]
That actually made it. So make sure to decorate your api correctly...
Upvotes: 2