1

看起来像 swashbuckle (5.2.2) 生成无效的字段名。我有一个(部分)看起来像这样的模型,所有属性都有一个后缀为“Field”的支持字段

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true,
    Namespace = "http://SomeCompany.Web.Service")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://SomeCompany.Web.Service", IsNullable = false)
]
public partial class GetOrderLines
{

    private string orderNumberField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
    public string OrderNumber
    {
        get
        {
            return this.orderNumberField;
        }
        set
        {
            this.orderNumberField = value;
        }
    }
}

控制器方法签名如下所示:

public GetOrderLinesResponse Get([FromUri]GetOrderLines request)
{

}

生成的文档如下所示:

在此处输入图像描述

它使用私有字段的名称而不是使用属性的名称。这是预期的行为吗?有什么办法可以解决这个问题并获得实际财产吗?

4

1 回答 1

1

我有一个类似的问题,并通过一个相关问题的答案解决了 - https://stackoverflow.com/a/35725054/1462905

简短的回答是 Json.NET 对标记的类做了一些不同的事情Serializable

config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver()
{
    IgnoreSerializableAttribute = true
};
于 2016-04-07T02:57:07.637 回答