简体   繁体   English

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

[英]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.

相关问题 使用 Swashbuckle / Swagger 的 C# 版本化 WebApi 文档 - C# versioned WebApi documentation using Swashbuckle / Swagger 是否可以使用基于目录的版本(webapi / C#)使用swagger / Swashbuckle进行版本控制? - Is it possible to do versioning with swagger/Swashbuckle using directory based version (webapi /C#)? C#:Swagger/Swashbuckle - 使用“AND”连接安全方案 - C#: Swagger/Swashbuckle - Connect security schemes with "AND" Swashbuckle + ASP.Net Core WebApi:Swagger 文档不包含用于版本选择的 Request-Header 或 QueryParameter? - Swashbuckle + ASP.Net Core WebApi: Swagger Document does not include Request-Header or QueryParameter for version selection? 如何在 .NET Core 2.2 WebApi 和 Azure AD 2.0 中配置 Swagger? - How to Configure Swagger in .NET Core 2.2 WebApi and Azure AD 2.0? k__BackingField在C#中删除(通过Swashbuckle / Swagger看到) - k__BackingField remove in C# (seen via Swashbuckle / Swagger) C#WebAPI 2反序列化产生空值,但不产生异常 - C# WebAPI 2 Deserialization Produces Nulls but No Exception C# Swashbuckle:过时的模型属性显示没有改变招摇 - C# Swashbuckle: Obsolete model property shows without change in swagger 包含<returns> Swagger Swashbuckle C# 中的 XML 文档块 - Including <returns> XML documentation block in Swagger Swashbuckle C# Swashbuckle/Swagger .NET Core 字典<int, MyModel> - Swashbuckle/Swagger .NET Core Dictionary<int, MyModel>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM