我正在寻找一种方法来更改模型中属性的显示名称,以便在 swagger 中将相同的内容反映在响应正文中。
我尝试为该字段使用 DisplayName
属性,但它似乎不起作用。
[DisplayName("Fucntion ID")]
public string FunctionId { get; set; }
[DisplayName("Function Description")]
public string FunctionDEscription { get; set; }
有没有其他方法可以实现这一目标?提前致谢。
答案 0 :(得分:1)
如果您使用 asp.net core 3.x 和 asp.net 5,则可以使用 [JsonPropertyName("Fucntion ID")]
中的 System.Text.Json
。
如果您使用 asp.net core 2.x,则可以使用 [JsonProperty("Fucntion ID")]
中的 Json.NET
。
参考:
https://www.newtonsoft.com/json/help/html/JsonPropertyName.htm
答案 1 :(得分:0)
我得到了答案-
使用 [JsonPropertyName("Fucntion ID")]
而不是 [DisplayName("Fucntion ID")]